-
Notifications
You must be signed in to change notification settings - Fork 1
/
anthropic.go
117 lines (100 loc) · 3.33 KB
/
anthropic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package anthropic
// See: https://docs.anthropic.com/claude/reference/messages_post
const (
// See: https://docs.anthropic.com/claude/docs/models-overview#model-recommendations
MODEL_CLAUDE_2_1 = "claude-2.1"
MODEL_CLAUDE_3_SONNET = "claude-3-sonnet-20240229"
MODEL_CLAUDE_3_OPUS = "claude-3-opus-20240229"
MODEL_CLAUDE_3_HAIKU = "claude-3-haiku-20240307"
MODEL_CLAUDE_35_SONNET = "claude-3-5-sonnet-20240620"
)
// MessageContentText | MessageContentFile
type MessageContent interface {
GetType() string
}
type MessageContentText struct {
Type string `json:"type"`
Text string `json:"text"`
}
func (m *MessageContentText) GetType() string {
return m.Type
}
type MessageContentFileSource struct {
Type string `json:"type"`
MediaType string `json:"media_type"`
Data string `json:"data"`
}
type MessageContentFile struct {
Type string `json:"type"`
Source MessageContentFileSource `json:"source,omitempty"`
}
func (m *MessageContentFile) GetType() string {
return m.Type
}
type Message struct {
Role string `json:"role"`
Content []MessageContent `json:"content"`
// Content string `json:"content"`
}
type MessagesRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
System string `json:"system,omitempty"`
MaxTokens int `json:"max_tokens"`
Metadata struct {
UserID string `json:"user_id"`
} `json:"metadata,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
TopK int `json:"top_k,omitempty"`
}
type MessagesResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Content []MessageContentText `json:"content"`
Model string `json:"model"`
StopReaon string `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
} `json:"usage"`
}
type MessagesStreamResponseContentBlock struct {
Type string `json:"type"`
Text string `json:"text"`
}
type MessagesStreamResponseDelta struct {
Type string `json:"type"`
Text string `json:"text"`
StopReaon string `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
Usage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
} `json:"usage"`
}
type MessagesStream struct {
*MessagesStreamReader
}
type MessagesStreamResponse struct {
Type string `json:"type"`
Message MessagesResponse `json:"message,omitempty"`
Index int `json:"index,omitempty"`
ContentBlock MessagesStreamResponseContentBlock `json:"content_block,omitempty"`
Delta MessagesStreamResponseDelta `json:"delta,omitempty"`
Error struct {
Type string `json:"type"`
Message string `json:"message"`
} `json:"error,omitempty"`
}
type MessagesResponseError struct {
Type string `json:"type"`
Error struct {
Type string `json:"type"`
Message string `json:"message"`
} `json:"error"`
}