Private
Public Access
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:
+6
-1
@@ -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 = ""
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user