code.oscarkilo.com/klex-git

Hash:
e297e88d82f9fcfab49cc992a8742bf764fdacf5
Author:
Igor Naverniouk <[email protected]>
Date:
Thu Sep 26 13:30:41 2024 -0700
Message:
messages API
diff --git a/api/messages.go b/api/messages.go
index ffcb40d..3f51e46 100644
--- a/api/messages.go
+++ b/api/messages.go
@@ -1,20 +1,34 @@
package api

type ChatMessage struct {
- Role string `json:"role"`
- Content string `json:"content"`
+ Role string `json:"role"`
+ Content []ContentBlock `json:"content"`
}

type MessagesRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
MaxTokens int `json:"max_tokens"`
+ System string `json:"system"`
Temperature float64 `json:"temperature"`
}

type ContentBlock struct {
+ // Type is "text", "image", "tool_use", or "tool_result".
Type string `json:"type"`
Text string `json:"text"`
+ Source *ContentSource `json:"source"`
+}
+
+type ContentSource struct {
+ // Type can only be "base64".
+ Type string `json:"type"`
+
+ // MediaType can be "image/jpeg", "image/png", "image/gif",
+ // or "image/webp".
+ MediaType string `json:"media_type"`
+
+ Data string `json:"data"`
}

type Usage struct {
a/api/messages.go
b/api/messages.go
1
package api
1
package api
2
2
3
type ChatMessage struct {
3
type ChatMessage struct {
4
Role string `json:"role"`
4
Role string `json:"role"`
5
Content string `json:"content"`
5
Content []ContentBlock `json:"content"`
6
}
6
}
7
7
8
type MessagesRequest struct {
8
type MessagesRequest struct {
9
Model string `json:"model"`
9
Model string `json:"model"`
10
Messages []ChatMessage `json:"messages"`
10
Messages []ChatMessage `json:"messages"`
11
MaxTokens int `json:"max_tokens"`
11
MaxTokens int `json:"max_tokens"`
12
System string `json:"system"`
12
Temperature float64 `json:"temperature"`
13
Temperature float64 `json:"temperature"`
13
}
14
}
14
15
15
type ContentBlock struct {
16
type ContentBlock struct {
17
// Type is "text", "image", "tool_use", or "tool_result".
16
Type string `json:"type"`
18
Type string `json:"type"`
17
Text string `json:"text"`
19
Text string `json:"text"`
20
Source *ContentSource `json:"source"`
21
}
22
23
type ContentSource struct {
24
// Type can only be "base64".
25
Type string `json:"type"`
26
27
// MediaType can be "image/jpeg", "image/png", "image/gif",
28
// or "image/webp".
29
MediaType string `json:"media_type"`
30
31
Data string `json:"data"`
18
}
32
}
19
33
20
type Usage struct {
34
type Usage struct {
21
InputTokens int `json:"input_tokens"`
35
InputTokens int `json:"input_tokens"`
22
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
36
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
23
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
37
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
24
OutputTokens int `json:"output_tokens"`
38
OutputTokens int `json:"output_tokens"`
25
}
39
}
26
40
27
type ErrorResponse struct {
41
type ErrorResponse struct {
28
Type string `json:"type"`
42
Type string `json:"type"`
29
Message string `json:"message"`
43
Message string `json:"message"`
30
}
44
}
31
45
32
type MessagesResponse struct {
46
type MessagesResponse struct {
33
Id string `json:"id"`
47
Id string `json:"id"`
34
Type string `json:"type"`
48
Type string `json:"type"`
35
Role string `json:"role"`
49
Role string `json:"role"`
36
Content []ContentBlock `json:"content"`
50
Content []ContentBlock `json:"content"`
37
Model string `json:"model"`
51
Model string `json:"model"`
38
StopReason string `json:"stop_reason"`
52
StopReason string `json:"stop_reason"`
39
StopSequence bool `json:"stop_sequence"`
53
StopSequence bool `json:"stop_sequence"`
40
Usage Usage `json:"usage"`
54
Usage Usage `json:"usage"`
41
Error *ErrorResponse `json:"error"`
55
Error *ErrorResponse `json:"error"`
42
}
56
}