mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
Address PR review feedback
- Consolidate stacked type: ignore comments into single annotation on responses.create call (ntindle's feedback) - Add name validation in convert_tools_to_responses_format with clear ValueError - Use getattr for safe response.usage access in extract_responses_usage - Add test for missing name validation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -714,15 +714,15 @@ async def llm_call(
|
||||
if force_json_output:
|
||||
text_config = {"format": {"type": "json_object"}} # type: ignore
|
||||
|
||||
response = await oai_client.responses.create(
|
||||
response = await oai_client.responses.create( # type: ignore[arg-type]
|
||||
model=llm_model.value,
|
||||
input=prompt, # type: ignore[arg-type]
|
||||
tools=tools_param, # type: ignore[arg-type]
|
||||
input=prompt,
|
||||
tools=tools_param,
|
||||
max_output_tokens=max_tokens,
|
||||
parallel_tool_calls=get_parallel_tool_calls_param(
|
||||
llm_model, parallel_tool_calls
|
||||
),
|
||||
text=text_config, # type: ignore[arg-type]
|
||||
text=text_config,
|
||||
store=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -54,9 +54,14 @@ def convert_tools_to_responses_format(tools: list[dict] | None) -> list[dict]:
|
||||
for tool in tools:
|
||||
if tool.get("type") == "function":
|
||||
func = tool.get("function", {})
|
||||
name = func.get("name")
|
||||
if not name:
|
||||
raise ValueError(
|
||||
f"Function tool is missing required 'name' field: {tool}"
|
||||
)
|
||||
entry: dict[str, Any] = {
|
||||
"type": "function",
|
||||
"name": func.get("name"),
|
||||
"name": name,
|
||||
# Note: strict=True is default in Responses API
|
||||
}
|
||||
if func.get("description") is not None:
|
||||
@@ -109,7 +114,7 @@ def extract_responses_usage(response: Any) -> tuple[int, int]:
|
||||
Returns:
|
||||
Tuple of (input_tokens, output_tokens)
|
||||
"""
|
||||
if not response.usage:
|
||||
if not getattr(response, "usage", None):
|
||||
return 0, 0
|
||||
|
||||
return (
|
||||
|
||||
@@ -145,6 +145,14 @@ class TestConvertToolsToResponsesFormat:
|
||||
assert "description" not in result[0]
|
||||
assert "parameters" not in result[0]
|
||||
|
||||
def test_raises_on_missing_name(self):
|
||||
"""Should raise ValueError when function tool has no name."""
|
||||
import pytest
|
||||
|
||||
tools = [{"type": "function", "function": {}}]
|
||||
with pytest.raises(ValueError, match="missing required 'name' field"):
|
||||
convert_tools_to_responses_format(tools)
|
||||
|
||||
|
||||
class TestExtractResponsesToolCalls:
|
||||
"""Tests for the extract_responses_tool_calls function."""
|
||||
|
||||
Reference in New Issue
Block a user