Class ChatCompletionsProtocol
Implements the OpenAI-compatible /chat/completions wire format. Used by Grok, DeepSeek, Sonar, and other compatible providers.
public class ChatCompletionsProtocol : CompletionProtocol
- Inheritance
-
ChatCompletionsProtocol
- Inherited Members
Fields
Instance
public static readonly ChatCompletionsProtocol Instance
Field Value
Methods
BuildFunctionRequestBody(ProtocolRequestParams, IReadOnlyList<FunctionDefinition>, FunctionCallMode, Func<Message, object>?)
Builds the request body including function/tool definitions.
public override object BuildFunctionRequestBody(ProtocolRequestParams p, IReadOnlyList<FunctionDefinition> functions, FunctionCallMode mode, Func<Message, object>? messageConverter = null)
Parameters
pProtocolRequestParamsfunctionsIReadOnlyList<FunctionDefinition>modeFunctionCallModemessageConverterFunc<Message, object>
Returns
BuildRequestBody(ProtocolRequestParams, Func<Message, object>?)
Builds the request body for a standard completion request.
public override object BuildRequestBody(ProtocolRequestParams p, Func<Message, object>? messageConverter = null)
Parameters
pProtocolRequestParamsmessageConverterFunc<Message, object>
Returns
ConvertMessage(Message)
Converts a message to the standard chat/completions format. Handles both text-only and multimodal (OpenAI-compatible image_url format).
public override object ConvertMessage(Message message)
Parameters
messageMessage
Returns
CreateFunctionRequest(string, object)
Creates the HTTP request for a function-calling completion call.
public override HttpRequestMessage CreateFunctionRequest(string apiKey, object requestBody)
Parameters
Returns
CreateRequest(string, object)
Creates the HTTP request for a completion call.
public override HttpRequestMessage CreateRequest(string apiKey, object requestBody)
Parameters
Returns
ExtractFunctionCall(string)
Extracts a function call (if any) from the API response JSON.
public override (string content, FunctionCall? functionCall) ExtractFunctionCall(string responseJson)
Parameters
responseJsonstring
Returns
ExtractResponse(string)
Extracts the text response content from the API response JSON.
public override string ExtractResponse(string responseJson)
Parameters
responseJsonstring
Returns
ParseStreamChunk(string)
Extracts a text delta from a single SSE stream chunk.
public override string ParseStreamChunk(string chunkJson)
Parameters
chunkJsonstring