Skip to content

Commit 4f4e0ac

Browse files
authored
Merge pull request #117 from GitHubSecurityLab/p--initial-openai-api-support
initial support for OpenAI API endpoint
2 parents 6113b00 + ea21d19 commit 4f4e0ac

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/seclab_taskflow_agent/agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
default_model = 'gpt-4o'
2727
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
2828
default_model = 'openai/gpt-4o'
29+
case AI_API_ENDPOINT_ENUM.AI_API_OPENAI:
30+
default_model = 'gpt-4o'
2931
case _:
3032
raise ValueError(
3133
f"Unsupported Model Endpoint: {api_endpoint}\n"

src/seclab_taskflow_agent/capi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
class AI_API_ENDPOINT_ENUM(StrEnum):
1414
AI_API_MODELS_GITHUB = 'models.github.ai'
1515
AI_API_GITHUBCOPILOT = 'api.githubcopilot.com'
16+
AI_API_OPENAI = 'api.openai.com'
1617

1718
def to_url(self):
1819
"""
@@ -23,6 +24,8 @@ def to_url(self):
2324
return f"https://{self}"
2425
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
2526
return f"https://{self}/inference"
27+
case AI_API_ENDPOINT_ENUM.AI_API_OPENAI:
28+
return f"https://{self}/v1"
2629
case _:
2730
raise ValueError(f"Unsupported endpoint: {self}")
2831

@@ -61,6 +64,8 @@ def list_capi_models(token: str) -> dict[str, dict]:
6164
models_catalog = 'models'
6265
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
6366
models_catalog = 'catalog/models'
67+
case AI_API_ENDPOINT_ENUM.AI_API_OPENAI:
68+
models_catalog = 'models'
6469
case _:
6570
raise ValueError(f"Unsupported Model Endpoint: {api_endpoint}\n"
6671
f"Supported endpoints: {[e.to_url() for e in AI_API_ENDPOINT_ENUM]}")
@@ -77,6 +82,8 @@ def list_capi_models(token: str) -> dict[str, dict]:
7782
models_list = r.json().get('data', [])
7883
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
7984
models_list = r.json()
85+
case AI_API_ENDPOINT_ENUM.AI_API_OPENAI:
86+
models_list = r.json().get('data', [])
8087
for model in models_list:
8188
models[model.get('id')] = dict(model)
8289
except httpx.RequestError as e:
@@ -98,6 +105,13 @@ def supports_tool_calls(model: str, models: dict) -> bool:
98105
case AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB:
99106
return 'tool-calling' in models.get(model, {}).\
100107
get('capabilities', [])
108+
case AI_API_ENDPOINT_ENUM.AI_API_OPENAI:
109+
# OpenAI doesn't expose capabilities in the models list
110+
# Check if model name indicates function calling support
111+
model_lower = model.lower()
112+
return any([
113+
'gpt-' in model_lower,
114+
])
101115
case _:
102116
raise ValueError(
103117
f"Unsupported Model Endpoint: {api_endpoint}\n"

tests/test_api_endpoint_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def test_to_url_githubcopilot(self):
5353
endpoint = AI_API_ENDPOINT_ENUM.AI_API_GITHUBCOPILOT
5454
assert endpoint.to_url() == 'https://api.githubcopilot.com'
5555

56+
def test_to_url_openai(self):
57+
"""Test to_url method for OpenAI endpoint."""
58+
endpoint = AI_API_ENDPOINT_ENUM.AI_API_OPENAI
59+
assert endpoint.to_url() == 'https://api.openai.com/v1'
60+
5661
def test_unsupported_endpoint(self, monkeypatch):
5762
"""Test that unsupported API endpoint raises ValueError."""
5863
api_endpoint = 'https://unsupported.example.com'

0 commit comments

Comments
 (0)