fix(backend): resolve type errors from Anthropic/OpenAI SDK updates

- Change convert_openai_tool_fmt_to_anthropic return type from
  Iterable[ToolParam] | NotGiven to list[ToolParam] | None
- Use conditional kwargs for Anthropic tools parameter
- Fix get_parallel_tool_calls to return NotGiven instead of Omit
  (openai.omit doesn't exist, openai.NOT_GIVEN is correct)
This commit is contained in:
Otto
2026-02-09 01:13:35 +00:00
parent 545e9cf746
commit 71b4287973

View File

@@ -531,12 +531,12 @@ class LLMResponse(BaseModel):
def convert_openai_tool_fmt_to_anthropic(
openai_tools: list[dict] | None = None,
) -> Iterable[ToolParam] | anthropic.NotGiven:
) -> list[ToolParam] | None:
"""
Convert OpenAI tool format to Anthropic tool format.
"""
if not openai_tools or len(openai_tools) == 0:
return anthropic.NOT_GIVEN
return None
anthropic_tools = []
for tool in openai_tools:
@@ -596,10 +596,10 @@ def extract_openai_tool_calls(response) -> list[ToolContentBlock] | None:
def get_parallel_tool_calls_param(
llm_model: LlmModel, parallel_tool_calls: bool | None
) -> bool | openai.Omit:
) -> bool | openai.NotGiven:
"""Get the appropriate parallel_tool_calls parameter for OpenAI-compatible APIs."""
if llm_model.startswith("o") or parallel_tool_calls is None:
return openai.omit
return openai.NOT_GIVEN
return parallel_tool_calls
@@ -717,14 +717,16 @@ async def llm_call(
api_key=credentials.api_key.get_secret_value()
)
try:
resp = await client.messages.create(
model=llm_model.value,
system=sysprompt,
messages=messages,
max_tokens=max_tokens,
tools=an_tools,
timeout=600,
)
create_kwargs: dict[str, Any] = {
"model": llm_model.value,
"system": sysprompt,
"messages": messages,
"max_tokens": max_tokens,
"timeout": 600,
}
if an_tools:
create_kwargs["tools"] = an_tools
resp = await client.messages.create(**create_kwargs)
if not resp.content:
raise ValueError("No content returned from Anthropic.")