Skip to content

Commit 15c257f

Browse files
Improve API endpoint error handling
1 parent 10752b4 commit 15c257f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Example:
4747
AI_API_TOKEN=<your_github_token>
4848
# MCP configs
4949
GITHUB_PERSONAL_ACCESS_TOKEN=<your_github_token>
50-
CODEQL_DBS_BASE_PATH="/app/my_data/codeql_databases"
50+
CODEQL_DBS_BASE_PATH="/app/data/codeql_databases"
51+
AI_API_ENDPOINT="https://models.github.ai/inference"
5152
```
5253

5354
## Deploying from Source

src/seclab_taskflow_agent/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
2828
default_model = 'openai/gpt-4o'
2929
case _:
30-
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}")
30+
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}\n"
31+
f"Supported endpoints: {[e.to_url() for e in AI_API_ENDPOINT_ENUM]}")
3132

3233
DEFAULT_MODEL = os.getenv('COPILOT_DEFAULT_MODEL', default=default_model)
3334

src/seclab_taskflow_agent/capi.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,20 @@
1111

1212
# Enumeration of currently supported API endpoints.
1313
class 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 self.AI_API_GITHUBCOPILOT:
23+
return f"https://{self}"
24+
case self.AI_API_MODELS_GITHUB:
25+
return f"https://{self}/inference"
26+
case _:
27+
raise ValueError(f"Unsupported Model Endpoint: {self}")
1628

1729
COPILOT_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
2335
def 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

2638
def get_AI_token():
2739
"""
@@ -65,7 +77,8 @@ def list_capi_models(token: str) -> dict[str, dict]:
6577
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
6678
models_list = r.json()
6779
case _:
68-
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}")
80+
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}\n"
81+
f"Supported endpoints: {[e.to_url() for e in AI_API_ENDPOINT_ENUM]}")
6982
for model in models_list:
7083
models[model.get('id')] = dict(model)
7184
except httpx.RequestError as e:
@@ -88,7 +101,8 @@ def supports_tool_calls(model: str, models: dict) -> bool:
88101
return 'tool-calling' in models.get(model, {}).\
89102
get('capabilities', [])
90103
case _:
91-
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}")
104+
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}\n"
105+
f"Supported endpoints: {[e.to_url() for e in AI_API_ENDPOINT_ENUM]}")
92106

93107
def list_tool_call_models(token: str) -> dict[str, dict]:
94108
models = list_capi_models(token)

0 commit comments

Comments
 (0)