types.go

v0.6.1
Doc Versions Source
1
package proxy
2
3
import "encoding/json"
4
5
// ---------- Anthropic API types ----------
6
7
type anthropicRequest struct {
8
	Model         string             `json:"model"`
9
	MaxTokens     int                `json:"max_tokens"`
10
	Messages      []anthropicMessage `json:"messages"`
11
	System        json.RawMessage    `json:"system,omitempty"`
12
	Stream        bool               `json:"stream,omitempty"`
13
	Temperature   *float64           `json:"temperature,omitempty"`
14
	TopP          *float64           `json:"top_p,omitempty"`
15
	StopSequences []string           `json:"stop_sequences,omitempty"`
16
	Tools         []anthropicTool    `json:"tools,omitempty"`
17
	ToolChoice    json.RawMessage    `json:"tool_choice,omitempty"`
18
	Thinking      json.RawMessage    `json:"thinking,omitempty"`
19
}
20
21
type anthropicMessage struct {
22
	Role    string          `json:"role"`
23
	Content json.RawMessage `json:"content"` // string | []contentBlock
24
}
25
26
type contentBlock struct {
27
	Type      string          `json:"type"`
28
	Text      string          `json:"text,omitempty"`
29
	ID        string          `json:"id,omitempty"`
30
	Name      string          `json:"name,omitempty"`
31
	Input     json.RawMessage `json:"input,omitempty"`
32
	ToolUseID string          `json:"tool_use_id,omitempty"`
33
	Content   json.RawMessage `json:"content,omitempty"` // tool_result content
34
	IsError   bool            `json:"is_error,omitempty"`
35
}
36
37
type anthropicTool struct {
38
	Name        string          `json:"name"`
39
	Description string          `json:"description,omitempty"`
40
	InputSchema json.RawMessage `json:"input_schema"`
41
}
42
43
type anthropicToolChoice struct {
44
	Type string `json:"type"`
45
	Name string `json:"name,omitempty"`
46
}
47
48
type anthropicResponse struct {
49
	ID           string         `json:"id"`
50
	Type         string         `json:"type"`
51
	Role         string         `json:"role"`
52
	Content      []contentBlock `json:"content"`
53
	Model        string         `json:"model"`
54
	StopReason   *string        `json:"stop_reason"`
55
	StopSequence *string        `json:"stop_sequence"`
56
	Usage        anthropicUsage `json:"usage"`
57
}
58
59
type anthropicUsage struct {
60
	InputTokens  int `json:"input_tokens"`
61
	OutputTokens int `json:"output_tokens"`
62
}
63
64
// ---------- OpenAI API types ----------
65
66
type openaiRequest struct {
67
	Model         string          `json:"model"`
68
	Messages      []openaiMessage `json:"messages"`
69
	MaxTokens     *int            `json:"max_tokens,omitempty"`
70
	Temperature   *float64        `json:"temperature,omitempty"`
71
	TopP          *float64        `json:"top_p,omitempty"`
72
	Stream        bool            `json:"stream,omitempty"`
73
	StreamOptions *streamOptions  `json:"stream_options,omitempty"`
74
	Stop          []string        `json:"stop,omitempty"`
75
	Tools         []openaiTool    `json:"tools,omitempty"`
76
	ToolChoice    any             `json:"tool_choice,omitempty"`
77
}
78
79
type streamOptions struct {
80
	IncludeUsage bool `json:"include_usage"`
81
}
82
83
type openaiMessage struct {
84
	Role       string           `json:"role"`
85
	Content    any              `json:"content"`
86
	ToolCalls  []openaiToolCall `json:"tool_calls,omitempty"`
87
	ToolCallID string           `json:"tool_call_id,omitempty"`
88
}
89
90
type openaiTool struct {
91
	Type     string         `json:"type"`
92
	Function openaiFunction `json:"function"`
93
}
94
95
type openaiFunction struct {
96
	Name        string          `json:"name"`
97
	Description string          `json:"description,omitempty"`
98
	Parameters  json.RawMessage `json:"parameters,omitempty"`
99
}
100
101
type openaiToolCall struct {
102
	ID       string         `json:"id"`
103
	Type     string         `json:"type"`
104
	Function openaiCallFunc `json:"function"`
105
}
106
107
type openaiCallFunc struct {
108
	Name      string `json:"name"`
109
	Arguments string `json:"arguments"`
110
}
111
112
type openaiResponse struct {
113
	ID      string         `json:"id"`
114
	Object  string         `json:"object"`
115
	Created int64          `json:"created"`
116
	Model   string         `json:"model"`
117
	Choices []openaiChoice `json:"choices"`
118
	Usage   *openaiUsage   `json:"usage,omitempty"`
119
}
120
121
type openaiChoice struct {
122
	Index        int           `json:"index"`
123
	Message      openaiMessage `json:"message"`
124
	FinishReason *string       `json:"finish_reason"`
125
}
126
127
type openaiUsage struct {
128
	PromptTokens     int `json:"prompt_tokens"`
129
	CompletionTokens int `json:"completion_tokens"`
130
	TotalTokens      int `json:"total_tokens"`
131
}
132
133
// ---------- OpenAI streaming types ----------
134
135
type openaiStreamChunk struct {
136
	ID      string               `json:"id"`
137
	Object  string               `json:"object"`
138
	Created int64                `json:"created"`
139
	Model   string               `json:"model"`
140
	Choices []openaiStreamChoice `json:"choices"`
141
	Usage   *openaiUsage         `json:"usage,omitempty"`
142
}
143
144
type openaiStreamChoice struct {
145
	Index        int               `json:"index"`
146
	Delta        openaiStreamDelta `json:"delta"`
147
	FinishReason *string           `json:"finish_reason"`
148
}
149
150
type openaiStreamDelta struct {
151
	Role      string                 `json:"role,omitempty"`
152
	Content   *string                `json:"content,omitempty"`
153
	ToolCalls []openaiStreamToolCall `json:"tool_calls,omitempty"`
154
}
155
156
type openaiStreamToolCall struct {
157
	Index    int             `json:"index"`
158
	ID       string          `json:"id,omitempty"`
159
	Type     string          `json:"type,omitempty"`
160
	Function *openaiCallFunc `json:"function,omitempty"`
161
}
162

Source Files