-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathmapping.py
70 lines (54 loc) · 2.42 KB
/
mapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional
from pydantic import BaseModel, HttpUrl
from pydantic_settings import BaseSettings
class CopilotProxyRoute(BaseModel):
"""Pydantic model for proxy route validation"""
path: str
target: HttpUrl
class CoPilotMappings(BaseSettings):
# Proxy routes configuration
# This code is to ensure that incoming proxy requests are routed to the correct target
PROXY_ROUTES: List[tuple[str, str]] = [
("/github/login", "https://github.com/login"),
("/api/github/user", "https://api.github.com"),
("/api/github/copilot", "https://api.github.com/copilot_internal"),
("/copilot/telemetry", "https://copilot-telemetry.githubusercontent.com"),
("/vscode/ab", "https://default.exp-tas.com"),
("/copilot/proxy", "https://copilot-proxy.githubusercontent.com"),
("/origin-tracker", "https://origin-tracker.githubusercontent.com"),
("/copilot/suggestions", "https://githubcopilot.com"),
("/copilot_internal/user", "https://api.github.com"),
("/copilot_internal/v2/token", "https://api.github.com"),
("/telemetry", "https://copilot-telemetry.githubusercontent.com"),
("/", "https://github.com"),
("/login/oauth/access_token", "https://github.com/login/oauth/access_token"),
("/api/copilot", "https://api.github.com/copilot_internal"),
("/api/copilot_internal", "https://api.github.com/copilot_internal"),
("/v1/completions", "https://copilot-proxy.githubusercontent.com/v1/completions"),
("/v1", "https://copilot-proxy.githubusercontent.com/v1"),
]
# Create settings instance
mappings = CoPilotMappings()
# Convert routes to validated ProxyRoute objects
VALIDATED_ROUTES: List[CopilotProxyRoute] = [
CopilotProxyRoute(path=path, target=target) for path, target in mappings.PROXY_ROUTES
]
class PipelineType(Enum):
FIM = "fim"
CHAT = "chat"
@dataclass
class PipelineRoute:
path: str
pipeline_type: PipelineType
target_url: Optional[str] = None
PIPELINE_ROUTES = [
PipelineRoute(
path="v1/chat/completions",
# target_url="https://api.openai.com/v1/chat/completions",
pipeline_type=PipelineType.CHAT,
),
PipelineRoute(path="v1/engines/copilot-codex/completions", pipeline_type=PipelineType.FIM),
PipelineRoute(path="chat/completions", pipeline_type=PipelineType.CHAT),
]