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
Constructors
ChatCompletionsProtocol()
public ChatCompletionsProtocol()
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
ExtractFinishReason(string)
public string? ExtractFinishReason(string responseJson)
Parameters
responseJsonstring
Returns
ExtractFunctionCalls(string)
Extracts every function call from one API response JSON payload.
public override (string content, FunctionCallBatch functionCalls) ExtractFunctionCalls(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