Fix: Return NormalizedResponse from send_openai_compatible

This resolves the issue where calling 'send_openai_compatible' discarded the NormalizedResponse details, resulting in an AttributeError when accessing 'raw_response' inside the tool loop.
This commit is contained in:
ed
2026-06-13 17:50:43 -04:00
parent fbcc1db495
commit 3aa7bdca99
3 changed files with 13 additions and 7 deletions
+6 -1
View File
@@ -732,7 +732,12 @@ def run_with_tool_loop(
def _default_send(_round_idx: int) -> NormalizedResponse:
from src.openai_compatible import send_openai_compatible as _send_oc
assert capabilities is not None, "capabilities required when send_func is not provided"
return _send_oc(client, request_builder(_round_idx), capabilities=capabilities)
res = _send_oc(client, request_builder(_round_idx), capabilities=capabilities)
if not res.ok:
if res.errors and res.errors[0].original:
raise res.errors[0].original
raise RuntimeError(res.errors[0].message if res.errors else "Unknown OpenAI error")
return res.data
request_builder: Callable[[int], OpenAICompatibleRequest] = (request if callable(request) else (lambda _i: request))
dispatch_send: Callable[[int], NormalizedResponse] = send_func or _default_send
response_text: str = ""
+4 -3
View File
@@ -64,7 +64,7 @@ def send_openai_compatible(
request: OpenAICompatibleRequest,
*,
capabilities: Any,
) -> Result[str]:
) -> Result[NormalizedResponse]:
kwargs: dict[str, Any] = {
"model": request.model,
"messages": request.messages,
@@ -83,9 +83,10 @@ def send_openai_compatible(
response = _send_streaming(client, kwargs, request.stream_callback)
else:
response = _send_blocking(client, kwargs)
return Result(data=response.text)
return Result(data=response)
except OpenAIError as exc:
return Result(data="", errors=[_classify_openai_compatible_error(exc, source="openai_compatible")])
empty_resp = NormalizedResponse(text="", tool_calls=[], usage_input_tokens=0, usage_output_tokens=0, usage_cache_read_tokens=0, usage_cache_creation_tokens=0, raw_response=None)
return Result(data=empty_resp, errors=[_classify_openai_compatible_error(exc, source="openai_compatible")])
def _send_blocking(client: Any, kwargs: dict[str, Any]) -> NormalizedResponse:
resp = client.chat.completions.create(**kwargs)