Responses#
Helpers for extracting fields from OpenAI-style API responses (the
shape returned by completions() and
chat()).
- saia_python.text_of(response: dict) str[source]#
Extract the assistant message content from a chat / RAG response.
Reaches into
response["choices"][0]["message"]["content"]with full nil-safety: an emptychoiceslist, a missingmessagekey, or aNonecontentfield all collapse to""rather than raising. Both empty-response cases log a warning at this module’s logger so silent regressions surface in logs.Works for the response shape returned by:
saia_python.ChatService.completions()saia_python.ArcanaService.chat()client.openai.chat.completions.create(...).model_dump()
- Parameters:
response – An OpenAI-style ChatCompletion response dict.
- Returns:
The first choice’s assistant content string, or
""if the response carries no usable content.
Example:
resp = client.arcana.chat( model="...", messages=[...], arcana_id="...", ) answer = saia_python.text_of(resp)