|
8 | 8 | import sys |
9 | 9 | import time |
10 | 10 | from dataclasses import dataclass, fields |
11 | | -from datetime import datetime |
12 | 11 | from pathlib import Path |
13 | 12 | from typing import Optional, Union |
14 | 13 |
|
@@ -903,57 +902,6 @@ def is_deepseek_r1(self): |
903 | 902 | def is_ollama(self): |
904 | 903 | return self.name.startswith("ollama/") or self.name.startswith("ollama_chat/") |
905 | 904 |
|
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 | | - |
957 | 905 | def send_completion( |
958 | 906 | self, messages, functions, stream, temperature=None, tools=None, max_tokens=None |
959 | 907 | ): |
@@ -1029,8 +977,6 @@ def send_completion( |
1029 | 977 | "Copilot-Integration-Id": "vscode-chat", |
1030 | 978 | } |
1031 | 979 |
|
1032 | | - self.github_copilot_token_to_open_ai_key(kwargs["extra_headers"]) |
1033 | | - |
1034 | 980 | try: |
1035 | 981 | res = litellm.completion(**kwargs) |
1036 | 982 | except Exception as err: |
|
0 commit comments