Struct CopilotClient

Source
pub struct CopilotClient { /* private fields */ }
Expand description

Client for interacting with the GitHub Copilot API.

This client handles GitHub token retrieval, fetching available models, and sending API requests for chat completions and embeddings.

Implementations§

Source§

impl CopilotClient

Source

pub async fn from_env_with_models( editor_version: String, ) -> Result<Self, CopilotError>

Creates a new CopilotClient by retrieving the GitHub token from environment variables or configuration files, and then fetching the list of available models.

§Arguments
  • editor_version - The version of the editor (e.g., “1.0.0”).
§Errors

Returns a CopilotError if the token retrieval or model fetching fails.

Source

pub async fn new_with_models( github_token: String, editor_version: String, ) -> Result<Self, CopilotError>

Creates a new CopilotClient with the provided GitHub token and editor version, and fetches the list of available models.

§Arguments
  • github_token - The GitHub token for authentication.
  • editor_version - The version of the editor.
§Errors

Returns a CopilotError if the model fetching fails.

Source

pub async fn get_agents(&self) -> Result<Vec<Agent>, CopilotError>

Fetches the list of agents from the GitHub Copilot API.

§Errors

Returns a CopilotError if the HTTP request fails or the response cannot be parsed.

Source

pub async fn get_models(&self) -> Result<Vec<Model>, CopilotError>

Fetches the list of available models from the GitHub Copilot API.

§Errors

Returns a CopilotError if the HTTP request fails or the response cannot be parsed.

Source

pub async fn chat_completion( &self, messages: Vec<Message>, model_id: String, ) -> Result<ChatResponse, CopilotError>

Sends a chat completion request to the GitHub Copilot API.

§Arguments
  • messages - A vector of chat messages to send.
  • model_id - The identifier of the model to use.
§Errors

Returns a CopilotError::InvalidModel error if the specified model is not available, or another CopilotError if the HTTP request or response parsing fails.

Source

pub async fn get_embeddings( &self, inputs: Vec<String>, ) -> Result<Vec<Embedding>, CopilotError>

Sends an embeddings request to the GitHub Copilot API.

§Arguments
  • inputs - A vector of input strings to generate embeddings for.
§Errors

Returns a CopilotError if the HTTP request fails or the response cannot be parsed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,