Expand description
Conversion between framework types and GitHub Copilot’s OpenAI-compatible
/chat/completions wire format.
Once authenticated with an exchanged Copilot API token, GitHub Copilot’s
chat endpoint 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 and agent-framework-foundry-local
reuse 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.
This module has nothing to do with the GitHub OAuth-token-to-Copilot-token exchange (see the crate root for that) — it only converts chat request/response bodies, after authentication has already produced a usable Copilot bearer token.
Functions§
- build_
request - Build the
/chat/completionsrequest body. - parse_
delta - Parse one streamed
chat.completion.chunkvalue into an update, resolving tool-call ids from the index map (a streamed tool-call delta only carries itsidon the first chunk; later chunks reference it byindex).