Expand description
Shared OpenAI Chat Completions wire format.
Both the cloud openai provider (api.openai.com) and the local
provider (Ollama / LM Studio / llama.cpp on localhost) speak the exact
same /v1/chat/completions request and response shape. This module owns
the body builder, non-streaming response parser, and the streaming SSE
reader so the two providers can’t drift.
Functions§
- build_
body - Build a Chat Completions request body from a
CloudAiRequest. - build_
embeddings_ body - Build an OpenAI-compatible
/v1/embeddingsbody. The text to embed is the requestprompt. - build_
streaming_ body - Build the request body for a streaming Chat Completions call. Same shape
as
build_bodyplusstream: trueand astream_optionsblock that asks the server to send a finalusagechunk so the caller can report token counts even on streaming responses. - parse_
embeddings_ response - Parse an OpenAI-compatible embeddings response into the first vector.
- parse_
response - Parse a Chat Completions response body.
provideris the caller’s name, stamped into errors and the returnedCloudAiResponse.provider. - run_
tools_ loop - Run the OpenAI-compatible tool-use loop: expose
tools, and on each turn, if the model requests tool calls, run them throughdispatcher, append the results, and re-call - until the model answers without tool calls (returned as theCloudAiResponse) ormax_itersis exhausted.api_keyempty means no bearer header (local servers). Non-streaming: tool-call deltas don’t reassemble cleanly over SSE. - stream_
response - Stream an OpenAI-compatible Chat Completions response, emitting each
content delta through
sink. Returns the accumulated full response once the stream closes so the caller still gets aCloudAiResponseto surface in the node output. - strip_
reasoning - Strip inline reasoning so only the user-facing answer is surfaced: removes
<think>…</think>spans (some local models inline their chain-of-thought there). Separatereasoning_contentfields are never read intotext, so they’re already excluded. Idempotent; trims surrounding whitespace.