xonecas.io
6312
Ga

go-opencode-ai-zen-sdk / files

go-opencode-ai-zen-sdk / types_responses.go

2.3 KB
1package zen
2
3import "encoding/json"
4
5type ResponsesRequest struct {
6	Model           string
7	Input           any
8	Instructions    string
9	Reasoning       *ResponsesReasoning
10	Tools           []ResponsesTool
11	ToolChoice      any
12	Temperature     *float64
13	MaxOutputTokens *int
14	Stream          bool
15	Extra           map[string]any
16}
17
18type ResponsesReasoning struct {
19	Effort  string `json:"effort,omitempty"`
20	Summary string `json:"summary,omitempty"`
21}
22
23// ResponsesTool defines a function tool in the Responses API flat format:
24// {"type":"function","name":...,"description":...,"parameters":...}
25// Note: this differs from Chat Completions which nests these under a "function" key.
26type ResponsesTool struct {
27	Type        string          `json:"type"`
28	Name        string          `json:"name"`
29	Description string          `json:"description,omitempty"`
30	Parameters  json.RawMessage `json:"parameters,omitempty"`
31}
32
33type ResponsesInputMessage struct {
34	Role    string                  `json:"role"`
35	Content []ResponsesInputContent `json:"content"`
36}
37
38type ResponsesInputContent struct {
39	Type string `json:"type"`
40	Text string `json:"text,omitempty"`
41}
42
43// ResponsesFunctionCall represents an assistant function-call output item in
44// the Responses API input array.
45type ResponsesFunctionCall struct {
46	Type      string `json:"type"`
47	CallID    string `json:"call_id"`
48	Name      string `json:"name"`
49	Arguments string `json:"arguments"`
50}
51
52// ResponsesFunctionCallOutput represents a tool result item in the Responses
53// API input array.
54type ResponsesFunctionCallOutput struct {
55	Type   string `json:"type"`
56	CallID string `json:"call_id"`
57	Output string `json:"output"`
58}
59
60func (r ResponsesRequest) MarshalJSON() ([]byte, error) {
61	base := map[string]any{
62		"model": r.Model,
63	}
64	if r.Input != nil {
65		base["input"] = r.Input
66	}
67	if r.Instructions != "" {
68		base["instructions"] = r.Instructions
69	}
70	if r.Reasoning != nil {
71		base["reasoning"] = r.Reasoning
72	}
73	if len(r.Tools) > 0 {
74		base["tools"] = r.Tools
75	}
76	if r.ToolChoice != nil {
77		base["tool_choice"] = r.ToolChoice
78	}
79	if r.Temperature != nil {
80		base["temperature"] = r.Temperature
81	}
82	if r.MaxOutputTokens != nil {
83		base["max_output_tokens"] = r.MaxOutputTokens
84	}
85	if r.Stream {
86		base["stream"] = r.Stream
87	}
88
89	return marshalWithExtra(base, r.Extra)
90}