6312
Ga
go-opencode-ai-zen-sdk / files
go-opencode-ai-zen-sdk / types_messages.go
1.8 KB
1package zen 2 3import "encoding/json" 4 5type MessagesRequest struct { 6 Model string 7 System string 8 Messages []AnthropicMessage 9 Tools []AnthropicTool 10 ToolChoice *AnthropicToolChoice 11 Thinking *AnthropicThinking 12 Temperature *float64 13 MaxTokens *int 14 Stream bool 15 Extra map[string]any 16} 17 18type AnthropicContentBlock struct { 19 Type string `json:"type"` 20 Text string `json:"text,omitempty"` 21 ID string `json:"id,omitempty"` 22 Name string `json:"name,omitempty"` 23 Input json.RawMessage `json:"input,omitempty"` 24 ToolUseID string `json:"tool_use_id,omitempty"` 25 Content string `json:"content,omitempty"` 26} 27 28type AnthropicMessage struct { 29 Role string `json:"role"` 30 Content any `json:"content"` // string or []AnthropicContentBlock 31} 32 33type AnthropicTool struct { 34 Name string `json:"name"` 35 Description string `json:"description,omitempty"` 36 InputSchema json.RawMessage `json:"input_schema,omitempty"` 37} 38 39type AnthropicToolChoice struct { 40 Type string `json:"type"` 41 Name string `json:"name,omitempty"` 42} 43 44type AnthropicThinking struct { 45 Type string `json:"type"` 46 BudgetTokens int `json:"budget_tokens,omitempty"` 47} 48 49func (r MessagesRequest) MarshalJSON() ([]byte, error) { 50 base := map[string]any{ 51 "model": r.Model, 52 "messages": r.Messages, 53 } 54 if r.System != "" { 55 base["system"] = r.System 56 } 57 if len(r.Tools) > 0 { 58 base["tools"] = r.Tools 59 } 60 if r.ToolChoice != nil { 61 base["tool_choice"] = r.ToolChoice 62 } 63 if r.Thinking != nil { 64 base["thinking"] = r.Thinking 65 } 66 if r.Temperature != nil { 67 base["temperature"] = r.Temperature 68 } 69 if r.MaxTokens != nil { 70 base["max_tokens"] = r.MaxTokens 71 } 72 if r.Stream { 73 base["stream"] = r.Stream 74 } 75 76 return marshalWithExtra(base, r.Extra) 77}