11package desktop
22
3+ // Tool represents an OpenAI function tool definition.
4+ type Tool struct {
5+ Type string `json:"type"`
6+ Function ToolFunction `json:"function"`
7+ }
8+
9+ // ToolFunction holds the schema for a tool.
10+ type ToolFunction struct {
11+ Name string `json:"name"`
12+ Description string `json:"description,omitempty"`
13+ Parameters any `json:"parameters,omitempty"`
14+ }
15+
16+ // ToolCall represents a tool call in a message or streaming delta.
17+ type ToolCall struct {
18+ ID string `json:"id,omitempty"`
19+ Type string `json:"type,omitempty"`
20+ Index int `json:"index"`
21+ Function ToolCallFunction `json:"function"`
22+ }
23+
24+ // ToolCallFunction holds the name and accumulated arguments for a tool call.
25+ type ToolCallFunction struct {
26+ Name string `json:"name,omitempty"`
27+ Arguments string `json:"arguments,omitempty"`
28+ }
29+
330type OpenAIChatMessage struct {
4- Role string `json:"role"`
5- Content interface {} `json:"content"` // Can be string or []ContentPart for multimodal
31+ Role string `json:"role"`
32+ Content any `json:"content,omitempty"` // Can be string or []ContentPart for multimodal
33+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
34+ ToolCallID string `json:"tool_call_id,omitempty"`
635}
736
837// ContentPart represents a part of multimodal content (text or image)
@@ -21,6 +50,7 @@ type OpenAIChatRequest struct {
2150 Model string `json:"model"`
2251 Messages []OpenAIChatMessage `json:"messages"`
2352 Stream bool `json:"stream"`
53+ Tools []Tool `json:"tools,omitempty"`
2454}
2555
2656type OpenAIChatResponse struct {
@@ -30,13 +60,15 @@ type OpenAIChatResponse struct {
3060 Model string `json:"model"`
3161 Choices []struct {
3262 Delta struct {
33- Content string `json:"content"`
34- Role string `json:"role,omitempty"`
35- ReasoningContent string `json:"reasoning_content,omitempty"`
63+ Content string `json:"content"`
64+ Role string `json:"role,omitempty"`
65+ ReasoningContent string `json:"reasoning_content,omitempty"`
66+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
3667 } `json:"delta"`
3768 Message struct {
38- Content string `json:"content"`
39- Role string `json:"role,omitempty"`
69+ Content string `json:"content"`
70+ Role string `json:"role,omitempty"`
71+ ToolCalls []ToolCall `json:"tool_calls,omitempty"`
4072 } `json:"message"`
4173 Index int `json:"index"`
4274 FinishReason string `json:"finish_reason"`
0 commit comments