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
impl CopilotClient
Sourcepub async fn from_env_with_models(
editor_version: String,
) -> Result<Self, CopilotError>
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.
Sourcepub async fn new_with_models(
github_token: String,
editor_version: String,
) -> Result<Self, CopilotError>
pub async fn new_with_models( github_token: String, editor_version: String, ) -> Result<Self, CopilotError>
Sourcepub async fn get_agents(&self) -> Result<Vec<Agent>, CopilotError>
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.
Sourcepub async fn get_models(&self) -> Result<Vec<Model>, CopilotError>
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.
Sourcepub async fn chat_completion(
&self,
messages: Vec<Message>,
model_id: String,
) -> Result<ChatResponse, CopilotError>
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.