Changeset 0.7.2 (#40)
This commit is contained in:
@@ -2,6 +2,7 @@ package providers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// ── Provider Interface ──────────────────────
|
||||
@@ -37,8 +38,39 @@ type ProviderConfig struct {
|
||||
|
||||
// Message represents a chat message in the conversation.
|
||||
type Message struct {
|
||||
Role string `json:"role"` // user, assistant, system
|
||||
Role string `json:"role"` // user, assistant, system, tool
|
||||
Content string `json:"content"`
|
||||
|
||||
// Tool calling fields (assistant → tool_calls, tool → tool_call_id)
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set when assistant requests tools
|
||||
ToolCallID string `json:"tool_call_id,omitempty"` // set for role="tool" result messages
|
||||
Name string `json:"name,omitempty"` // tool name for role="tool"
|
||||
}
|
||||
|
||||
// ToolCall represents a function call requested by the LLM.
|
||||
type ToolCall struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"` // "function"
|
||||
Function FunctionCall `json:"function"`
|
||||
}
|
||||
|
||||
// FunctionCall is the function name and JSON arguments.
|
||||
type FunctionCall struct {
|
||||
Name string `json:"name"`
|
||||
Arguments string `json:"arguments"`
|
||||
}
|
||||
|
||||
// ToolDef describes a tool available to the LLM.
|
||||
type ToolDef struct {
|
||||
Type string `json:"type"` // "function"
|
||||
Function FunctionDef `json:"function"`
|
||||
}
|
||||
|
||||
// FunctionDef is the schema for a tool function.
|
||||
type FunctionDef struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Parameters json.RawMessage `json:"parameters"`
|
||||
}
|
||||
|
||||
// CompletionRequest is the normalized request sent to any provider.
|
||||
@@ -49,15 +81,17 @@ type CompletionRequest struct {
|
||||
Temperature *float64 `json:"temperature,omitempty"`
|
||||
TopP *float64 `json:"top_p,omitempty"`
|
||||
Stream bool `json:"stream,omitempty"`
|
||||
Tools []ToolDef `json:"tools,omitempty"` // available tools for function calling
|
||||
}
|
||||
|
||||
// CompletionResponse is the normalized non-streaming response.
|
||||
type CompletionResponse struct {
|
||||
Content string `json:"content"`
|
||||
Model string `json:"model"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
InputTokens int `json:"input_tokens"`
|
||||
OutputTokens int `json:"output_tokens"`
|
||||
Content string `json:"content"`
|
||||
Model string `json:"model"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
InputTokens int `json:"input_tokens"`
|
||||
OutputTokens int `json:"output_tokens"`
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set when finish_reason is "tool_calls"
|
||||
}
|
||||
|
||||
// StreamEvent is a single chunk from a streaming response.
|
||||
@@ -69,8 +103,13 @@ type StreamEvent struct {
|
||||
Done bool `json:"done,omitempty"`
|
||||
|
||||
// FinishReason is set on the final event.
|
||||
// "stop" = normal, "tool_calls" = LLM wants to call tools.
|
||||
FinishReason string `json:"finish_reason,omitempty"`
|
||||
|
||||
// ToolCalls accumulates tool call data during streaming.
|
||||
// Fully populated on the final event when FinishReason is "tool_calls".
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
|
||||
|
||||
// Model echoes back the model used.
|
||||
Model string `json:"model,omitempty"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user