Merge pull request #4156 from stackbuilders/always_pass_extra_headers_to_copilot_models
Some checks are pending
pre-commit / pre-commit (push) Waiting to run

This commit is contained in:
paul-gauthier 2025-06-02 07:06:10 -07:00 committed by GitHub
commit fa0aa9459b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,7 @@ import json5
import yaml
from PIL import Image
from aider import __version__
from aider.dump import dump # noqa: F401
from aider.llm import litellm
from aider.openrouter import OpenRouterModelManager
@ -876,7 +877,7 @@ class Model(ModelSettings):
def is_ollama(self):
return self.name.startswith("ollama/") or self.name.startswith("ollama_chat/")
def github_copilot_token_to_open_ai_key(self):
def github_copilot_token_to_open_ai_key(self, extra_headers):
# check to see if there's an openai api key
# If so, check to see if it's expire
openai_api_key = "OPENAI_API_KEY"
@ -889,10 +890,8 @@ class Model(ModelSettings):
headers = {
"Authorization": f"Bearer {os.environ['GITHUB_COPILOT_TOKEN']}",
"Editor-Version": self.extra_params["extra_headers"]["Editor-Version"],
"Copilot-Integration-Id": self.extra_params["extra_headers"][
"Copilot-Integration-Id"
],
"Editor-Version": extra_headers["Editor-Version"],
"Copilot-Integration-Id": extra_headers["Copilot-Integration-Id"],
"Content-Type": "application/json",
}
res = requests.get("https://api.github.com/copilot_internal/v2/token", headers=headers)
@ -941,7 +940,13 @@ class Model(ModelSettings):
# Are we using github copilot?
if "GITHUB_COPILOT_TOKEN" in os.environ:
self.github_copilot_token_to_open_ai_key()
if "extra_headers" not in kwargs:
kwargs["extra_headers"] = {
"Editor-Version": f"aider/{__version__}",
"Copilot-Integration-Id": "vscode-chat",
}
self.github_copilot_token_to_open_ai_key(kwargs["extra_headers"])
res = litellm.completion(**kwargs)
return hash_object, res