Skip to main content

Module convert

Module convert 

Source
Expand description

Conversion between framework types and Foundry Local’s OpenAI-compatible /v1/chat/completions wire format.

Foundry Local’s OpenAI-compatibility layer (https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-local/reference/reference-catalog-api#openai-compatibility) speaks the exact same JSON shapes as OpenAI’s Chat Completions API for everything this crate needs: messages, tools/tool_choice, the scalar sampling options, the non-streaming response envelope, usage, and the chat.completion.chunk SSE delta shape. So request-body assembly and response/usage parsing are reused verbatim from [agent_framework_openai::convert] rather than duplicated (mirrors how agent-framework-ollama reuses the same module, and for the same reason). Only the streaming-delta parser is reimplemented locally, kept small on purpose, so it can be unit-tested here over fixture JSON without going through a live reqwest::Response.

Known gaps versus upstream OpenAI, reflecting real Foundry Local server behavior: no refusal field, no completion_tokens_details / prompt_tokens_details breakdown (harmless — parse_usage simply finds nothing there), and no system_fingerprint. None of these affect the fields this crate reads.

Functions§

build_request
Build the /v1/chat/completions request body.
parse_delta
Parse one streamed chat.completion.chunk value into an update, resolving tool-call ids from the index map (a streamed tool-call delta only carries its id on the first chunk; later chunks reference it by index).