1111
1212# Enumeration of currently supported API endpoints.
1313class AI_API_ENDPOINT_ENUM (StrEnum ):
14- AI_API_MODELS_GITHUB = 'models.github.ai'
15- AI_API_GITHUBCOPILOT = 'api.githubcopilot.com'
14+ AI_API_MODELS_GITHUB = 'models.github.ai'
15+ AI_API_GITHUBCOPILOT = 'api.githubcopilot.com'
16+
17+ def to_url (self ):
18+ """
19+ Convert the endpoint to its full URL.
20+ """
21+ match self :
22+ case AI_API_ENDPOINT_ENUM .AI_API_GITHUBCOPILOT :
23+ return f"https://{ self } "
24+ case AI_API_ENDPOINT_ENUM .AI_API_MODELS_GITHUB :
25+ return f"https://{ self } /inference"
26+ case _:
27+ raise ValueError (f"Unsupported endpoint: { self } " )
1628
1729COPILOT_INTEGRATION_ID = 'vscode-chat'
1830
@@ -21,7 +33,7 @@ class AI_API_ENDPOINT_ENUM(StrEnum):
2133# since different APIs use their own id schema, use -l with your desired
2234# endpoint to retrieve the correct id names to use for your taskflow
2335def get_AI_endpoint ():
24- return os .getenv ('AI_API_ENDPOINT' , default = 'https://models.github.ai/inference' )
36+ return os .getenv ('AI_API_ENDPOINT' , default = 'https://models.github.ai/inference' )
2537
2638def get_AI_token ():
2739 """
@@ -50,7 +62,8 @@ def list_capi_models(token: str) -> dict[str, dict]:
5062 case AI_API_ENDPOINT_ENUM .AI_API_MODELS_GITHUB :
5163 models_catalog = 'catalog/models'
5264 case _:
53- raise ValueError (f"Unsupported Model Endpoint: { api_endpoint } " )
65+ raise ValueError (f"Unsupported Model Endpoint: { api_endpoint } \n "
66+ f"Supported endpoints: { [e .to_url () for e in AI_API_ENDPOINT_ENUM ]} " )
5467 r = httpx .get (httpx .URL (api_endpoint ).join (models_catalog ),
5568 headers = {
5669 'Accept' : 'application/json' ,
@@ -64,8 +77,6 @@ def list_capi_models(token: str) -> dict[str, dict]:
6477 models_list = r .json ().get ('data' , [])
6578 case AI_API_ENDPOINT_ENUM .AI_API_MODELS_GITHUB :
6679 models_list = r .json ()
67- case _:
68- raise ValueError (f"Unsupported Model Endpoint: { api_endpoint } " )
6980 for model in models_list :
7081 models [model .get ('id' )] = dict (model )
7182 except httpx .RequestError as e :
@@ -88,7 +99,10 @@ def supports_tool_calls(model: str, models: dict) -> bool:
8899 return 'tool-calling' in models .get (model , {}).\
89100 get ('capabilities' , [])
90101 case _:
91- raise ValueError (f"Unsupported Model Endpoint: { api_endpoint } " )
102+ raise ValueError (
103+ f"Unsupported Model Endpoint: { api_endpoint } \n "
104+ f"Supported endpoints: { [e .to_url () for e in AI_API_ENDPOINT_ENUM ]} "
105+ )
92106
93107def list_tool_call_models (token : str ) -> dict [str , dict ]:
94108 models = list_capi_models (token )
0 commit comments