Skip to content

Commit 436d593

Browse files
committed
Fix deepseek max tokens, fully delegate github copilot to litellm
1 parent 7053c79 commit 436d593

2 files changed

Lines changed: 3 additions & 57 deletions

File tree

aider/models.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
import time
1010
from dataclasses import dataclass, fields
11-
from datetime import datetime
1211
from pathlib import Path
1312
from typing import Optional, Union
1413

@@ -903,57 +902,6 @@ def is_deepseek_r1(self):
903902
def is_ollama(self):
904903
return self.name.startswith("ollama/") or self.name.startswith("ollama_chat/")
905904

906-
def github_copilot_token_to_open_ai_key(self, extra_headers):
907-
# check to see if there's an openai api key
908-
# If so, check to see if it's expire
909-
openai_api_key = "OPENAI_API_KEY"
910-
911-
if openai_api_key not in os.environ or (
912-
int(dict(x.split("=") for x in os.environ[openai_api_key].split(";"))["exp"])
913-
< int(datetime.now().timestamp())
914-
):
915-
import requests
916-
917-
class GitHubCopilotTokenError(Exception):
918-
"""Custom exception for GitHub Copilot token-related errors."""
919-
920-
pass
921-
922-
# Validate GitHub Copilot token exists
923-
if "GITHUB_COPILOT_TOKEN" not in os.environ:
924-
raise KeyError("GITHUB_COPILOT_TOKEN environment variable not found")
925-
926-
github_token = os.environ["GITHUB_COPILOT_TOKEN"]
927-
if not github_token.strip():
928-
raise KeyError("GITHUB_COPILOT_TOKEN environment variable is empty")
929-
930-
headers = {
931-
"Authorization": f"Bearer {os.environ['GITHUB_COPILOT_TOKEN']}",
932-
"Editor-Version": extra_headers["Editor-Version"],
933-
"Copilot-Integration-Id": extra_headers["Copilot-Integration-Id"],
934-
"Content-Type": "application/json",
935-
}
936-
937-
url = "https://api.github.com/copilot_internal/v2/token"
938-
res = requests.get(url, headers=headers)
939-
if res.status_code != 200:
940-
safe_headers = {k: v for k, v in headers.items() if k != "Authorization"}
941-
token_preview = github_token[:5] + "..." if len(github_token) >= 5 else github_token
942-
safe_headers["Authorization"] = f"Bearer {token_preview}"
943-
raise GitHubCopilotTokenError(
944-
f"GitHub Copilot API request failed (Status: {res.status_code})\n"
945-
f"URL: {url}\n"
946-
f"Headers: {json.dumps(safe_headers, indent=2)}\n"
947-
f"JSON: {res.text}"
948-
)
949-
950-
response_data = res.json()
951-
token = response_data.get("token")
952-
if not token:
953-
raise GitHubCopilotTokenError("Response missing 'token' field")
954-
955-
os.environ[openai_api_key] = token
956-
957905
def send_completion(
958906
self, messages, functions, stream, temperature=None, tools=None, max_tokens=None
959907
):
@@ -1029,8 +977,6 @@ def send_completion(
1029977
"Copilot-Integration-Id": "vscode-chat",
1030978
}
1031979

1032-
self.github_copilot_token_to_open_ai_key(kwargs["extra_headers"])
1033-
1034980
try:
1035981
res = litellm.completion(**kwargs)
1036982
except Exception as err:

aider/resources/model-metadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"deepseek/deepseek-reasoner": {
3-
"max_tokens": 64000,
3+
"max_tokens": 128000,
44
"max_input_tokens": 128000,
55
"max_output_tokens": 64000,
66
"input_cost_per_token": 0.00000028,
@@ -15,9 +15,9 @@
1515
"supports_prompt_caching": true
1616
},
1717
"deepseek/deepseek-chat": {
18-
"max_tokens": 8192,
18+
"max_tokens": 128000,
1919
"max_input_tokens": 128000,
20-
"max_output_tokens": 8192,
20+
"max_output_tokens": 8000,
2121
"input_cost_per_token": 0.00000028,
2222
"input_cost_per_token_cache_hit": 0.000000028,
2323
"cache_read_input_token_cost": 0.000000028,

0 commit comments

Comments
 (0)