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:
@@ -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