code.oscarkilo.com/klex-git

Hash:
7abbf82a696046fbe2a48ed8c8ea4ef5b7d375dd
Author:
Igor Naverniouk <[email protected]>
Date:
Wed Sep 25 10:00:12 2024 -0700
Message:
messages API
diff --git a/api/messages.go b/api/messages.go
new file mode 100644
index 0000000..ffcb40d
--- /dev/null
+++ b/api/messages.go
@@ -0,0 +1,42 @@
+package api
+
+type ChatMessage struct {
+ Role string `json:"role"`
+ Content string `json:"content"`
+}
+
+type MessagesRequest struct {
+ Model string `json:"model"`
+ Messages []ChatMessage `json:"messages"`
+ MaxTokens int `json:"max_tokens"`
+ Temperature float64 `json:"temperature"`
+}
+
+type ContentBlock struct {
+ Type string `json:"type"`
+ Text string `json:"text"`
+}
+
+type Usage struct {
+ InputTokens int `json:"input_tokens"`
+ CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
+ CacheReadInputTokens *int `json:"cache_read_input_tokens"`
+ OutputTokens int `json:"output_tokens"`
+}
+
+type ErrorResponse struct {
+ Type string `json:"type"`
+ Message string `json:"message"`
+}
+
+type MessagesResponse struct {
+ Id string `json:"id"`
+ Type string `json:"type"`
+ Role string `json:"role"`
+ Content []ContentBlock `json:"content"`
+ Model string `json:"model"`
+ StopReason string `json:"stop_reason"`
+ StopSequence bool `json:"stop_sequence"`
+ Usage Usage `json:"usage"`
+ Error *ErrorResponse `json:"error"`
+}
/dev/null
b/api/messages.go
1
package api
2
3
type ChatMessage struct {
4
Role string `json:"role"`
5
Content string `json:"content"`
6
}
7
8
type MessagesRequest struct {
9
Model string `json:"model"`
10
Messages []ChatMessage `json:"messages"`
11
MaxTokens int `json:"max_tokens"`
12
Temperature float64 `json:"temperature"`
13
}
14
15
type ContentBlock struct {
16
Type string `json:"type"`
17
Text string `json:"text"`
18
}
19
20
type Usage struct {
21
InputTokens int `json:"input_tokens"`
22
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
23
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
24
OutputTokens int `json:"output_tokens"`
25
}
26
27
type ErrorResponse struct {
28
Type string `json:"type"`
29
Message string `json:"message"`
30
}
31
32
type MessagesResponse struct {
33
Id string `json:"id"`
34
Type string `json:"type"`
35
Role string `json:"role"`
36
Content []ContentBlock `json:"content"`
37
Model string `json:"model"`
38
StopReason string `json:"stop_reason"`
39
StopSequence bool `json:"stop_sequence"`
40
Usage Usage `json:"usage"`
41
Error *ErrorResponse `json:"error"`
42
}