Add GitHub token environment variable support for Copilot (#31392)
Add support for environment variables as authentication alternatives to OAuth flow for Copilot. Closes #31172 We can include the token in HTTPS request headers to hopefully resolve the rate limiting issue in #9483. This change will be part of a separate PR. Release Notes: - Added support for manually providing an OAuth token for GitHub Copilot Chat by assigning the GH_COPILOT_TOKEN environment variable --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
parent
78fd2685d5
commit
1fe10117b7
4 changed files with 37 additions and 11 deletions
|
@ -16,6 +16,8 @@ use paths::home_dir;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use settings::watch_config_dir;
|
||||
|
||||
pub const COPILOT_OAUTH_ENV_VAR: &str = "GH_COPILOT_TOKEN";
|
||||
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
pub struct CopilotChatSettings {
|
||||
pub api_url: Arc<str>,
|
||||
|
@ -405,13 +407,19 @@ impl CopilotChat {
|
|||
})
|
||||
.detach_and_log_err(cx);
|
||||
|
||||
Self {
|
||||
oauth_token: None,
|
||||
let this = Self {
|
||||
oauth_token: std::env::var(COPILOT_OAUTH_ENV_VAR).ok(),
|
||||
api_token: None,
|
||||
models: None,
|
||||
settings,
|
||||
client,
|
||||
};
|
||||
if this.oauth_token.is_some() {
|
||||
cx.spawn(async move |this, mut cx| Self::update_models(&this, &mut cx).await)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
async fn update_models(this: &WeakEntity<Self>, cx: &mut AsyncApp) -> Result<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue