mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-05 20:25:01 +00:00
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
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
This commit is contained in:
commit
fa0aa9459b
1 changed files with 11 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue