Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/codegen/sdk/ai/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@

# TODO: move into utils/ai folder
class OpenAIHelper(AbstractAIHelper):
client: OpenAI = None

Check failure on line 109 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "None", variable has type "OpenAI") [assignment]

def __init__(
self,
openai_key: str,
api_base: str = "https://oai.hconeai.com/v1",
api_base: str = "https://api.openai.com/v1",
headers=None,
cache: bool | None = True,
) -> None:
Expand Down Expand Up @@ -184,7 +184,7 @@
return response

@staticmethod
def llm_response_to_json(response: openai_types.chat_completion.ChatCompletion) -> str:

Check failure on line 187 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "llm_response_to_json" incompatible with supertype "AbstractAIHelper" [override]
# the response needs an object of type ChatCompletionMessage
js = json.loads(response.model_dump_json())
if len(js["choices"]) == 0:
Expand All @@ -197,7 +197,7 @@
self,
anthropic_key: str,
# Dont add /v1 to the path. Anthropic already adds it, so it will be a double /v1/v1
api_base: str = "https://anthropic.hconeai.com/",
api_base: str = "https://api.anthropic.com",
headers=None,
openai_anthropic_translation: bool = True,
cache: bool | None = True,
Expand All @@ -224,7 +224,7 @@
if "parameters" in function["function"]:
new_function["input_schema"] = function["function"]["parameters"]
new_functions.append(new_function)
return new_functions

Check failure on line 227 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible return value type (got "list[dict[str, Any]]", expected "list[ToolParam]") [return-value]

def _convert_claude_response_to_openai(
self, response: anthropic_types.Message | anthropic_tool_types.ToolsBetaMessage, parse_function_calls: bool = False, parse_result_block: bool = False
Expand Down Expand Up @@ -326,7 +326,7 @@
claude_system_prompt = system_prompt + claude_system_prompt
else:
claude_system_prompt = system_prompt
response = self.client.beta.tools.messages.create(max_tokens=max_tokens, system=claude_system_prompt, messages=messages, model=model, **kwargs)

Check failure on line 329 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "max_tokens" to "create" of "Messages" has incompatible type "int | None"; expected "int" [arg-type]
if self.openai_anthropic_translation:
return self._convert_claude_response_to_openai(response)
else:
Expand All @@ -350,7 +350,7 @@
claude_functions = functions
claude_system_prompt = system_prompt
response = self.client.beta.tools.messages.create(
max_tokens=max_tokens or anthropic.NotGiven(),

Check failure on line 353 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "max_tokens" to "create" of "Messages" has incompatible type "int | NotGiven"; expected "int" [arg-type]
system=claude_system_prompt,
messages=messages,
model=model,
Expand All @@ -372,7 +372,7 @@
return response

@staticmethod
def llm_response_to_json(response: openai_types.chat_completion.ChatCompletion | anthropic_types.Message) -> str:

Check failure on line 375 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "llm_response_to_json" incompatible with supertype "AbstractAIHelper" [override]
if isinstance(response, openai_types.chat_completion.ChatCompletion):
return OpenAIHelper.llm_response_to_json(response)
else:
Expand All @@ -387,8 +387,8 @@
self,
openai_key: str,
anthropic_key: str | None = None,
openai_base: str = "https://oai.hconeai.com/v1",
anthropic_base: str = "https://anthropic.hconeai.com/",
openai_base: str = "https://api.openai.com/v1",
anthropic_base: str = "https://api.anthropic.com",
headers=None,
use_openai: bool = True,
use_claude: bool = True,
Expand Down Expand Up @@ -482,6 +482,6 @@
raise Exception(msg)

@staticmethod
def llm_response_to_json(response) -> str:

Check failure on line 485 in src/codegen/sdk/ai/helpers.py

View workflow job for this annotation

GitHub Actions / mypy

error: Signature of "llm_response_to_json" incompatible with supertype "AbstractAIHelper" [override]
# Prioritize Anthropic First (Has support for both, while OpenAI only supports OpenAI)
return AnthropicHelper.llm_response_to_json(response)
Loading