code.oscarkilo.com/klex-git

Hash:
7faba14e4a2603b971fddcdbb201a6212a637ffc
Author:
Igor Naverniouk <[email protected]>
Date:
Tue Oct 8 10:04:41 2024 -0700
Message:
JSONSchema shenanigans
diff --git a/api/messages.go b/api/messages.go
index 77df339..4075b7b 100644
--- a/api/messages.go
+++ b/api/messages.go
@@ -69,8 +69,10 @@ type Tool struct {
type JSONSchema struct {
Type string `json:"type"`
Properties map[string]JSONSchema `json:"properties,omitempty"`
- Items *JSONSchema `json:"items,omitempty"`
+ Items bool `json:"items,omitempty"`
+ PrefixItems []JSONSchema `json:"prefixItems,omitempty"`
+ UnevaluatedItems bool `json:"unevaluatedItems,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
UnevaluatedProperties bool `json:"unevaluatedProperties,omitempty"`
- Requeired []string `json:"required,omitempty"`
+ Required []string `json:"required,omitempty"`
}
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 []ContentBlock `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,omitempty"`
12
System string `json:"system,omitempty"`
13
Temperature float64 `json:"temperature"`
13
Temperature float64 `json:"temperature"`
14
Tools []Tool `json:"tools,omitempty"`
14
Tools []Tool `json:"tools,omitempty"`
15
}
15
}
16
16
17
type ContentBlock struct {
17
type ContentBlock struct {
18
// Type is "text", "image", "tool_use", or "tool_result".
18
// Type is "text", "image", "tool_use", or "tool_result".
19
Type string `json:"type"`
19
Type string `json:"type"`
20
Text string `json:"text"`
20
Text string `json:"text"`
21
Source *ContentSource `json:"source"`
21
Source *ContentSource `json:"source"`
22
}
22
}
23
23
24
type ContentSource struct {
24
type ContentSource struct {
25
// Type can only be "base64".
25
// Type can only be "base64".
26
Type string `json:"type"`
26
Type string `json:"type"`
27
27
28
// MediaType can be one of:
28
// MediaType can be one of:
29
// - "image/jpeg",
29
// - "image/jpeg",
30
// - "image/png",
30
// - "image/png",
31
// - "image/gif", or
31
// - "image/gif", or
32
// - "image/webp".
32
// - "image/webp".
33
MediaType string `json:"media_type,omitempty"`
33
MediaType string `json:"media_type,omitempty"`
34
34
35
Data string `json:"data,omitempty"`
35
Data string `json:"data,omitempty"`
36
}
36
}
37
37
38
type Usage struct {
38
type Usage struct {
39
InputTokens int `json:"input_tokens"`
39
InputTokens int `json:"input_tokens"`
40
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
40
CacheCreationInputTokens *int `json:"cache_creation_input_tokens"`
41
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
41
CacheReadInputTokens *int `json:"cache_read_input_tokens"`
42
OutputTokens int `json:"output_tokens"`
42
OutputTokens int `json:"output_tokens"`
43
}
43
}
44
44
45
type ErrorResponse struct {
45
type ErrorResponse struct {
46
Type string `json:"type"`
46
Type string `json:"type"`
47
Message string `json:"message"`
47
Message string `json:"message"`
48
}
48
}
49
49
50
type MessagesResponse struct {
50
type MessagesResponse struct {
51
Id string `json:"id"`
51
Id string `json:"id"`
52
Type string `json:"type"`
52
Type string `json:"type"`
53
Role string `json:"role"`
53
Role string `json:"role"`
54
Content []ContentBlock `json:"content"`
54
Content []ContentBlock `json:"content"`
55
Model string `json:"model"`
55
Model string `json:"model"`
56
StopReason string `json:"stop_reason"`
56
StopReason string `json:"stop_reason"`
57
StopSequence bool `json:"stop_sequence"`
57
StopSequence bool `json:"stop_sequence"`
58
Usage Usage `json:"usage"`
58
Usage Usage `json:"usage"`
59
Error *ErrorResponse `json:"error"`
59
Error *ErrorResponse `json:"error"`
60
}
60
}
61
61
62
type Tool struct {
62
type Tool struct {
63
Name string `json:"name"`
63
Name string `json:"name"`
64
Description string `json:"description"`
64
Description string `json:"description"`
65
InputSchema JSONSchema `json:"input_schema"`
65
InputSchema JSONSchema `json:"input_schema"`
66
}
66
}
67
67
68
// JSONSchema is the subset of json-shcema.org that we need.
68
// JSONSchema is the subset of json-shcema.org that we need.
69
type JSONSchema struct {
69
type JSONSchema struct {
70
Type string `json:"type"`
70
Type string `json:"type"`
71
Properties map[string]JSONSchema `json:"properties,omitempty"`
71
Properties map[string]JSONSchema `json:"properties,omitempty"`
72
Items *JSONSchema `json:"items,omitempty"`
72
Items bool `json:"items,omitempty"`
73
PrefixItems []JSONSchema `json:"prefixItems,omitempty"`
74
UnevaluatedItems bool `json:"unevaluatedItems,omitempty"`
73
AdditionalProperties bool `json:"additionalProperties,omitempty"`
75
AdditionalProperties bool `json:"additionalProperties,omitempty"`
74
UnevaluatedProperties bool `json:"unevaluatedProperties,omitempty"`
76
UnevaluatedProperties bool `json:"unevaluatedProperties,omitempty"`
75
Requeired []string `json:"required,omitempty"`
77
Required []string `json:"required,omitempty"`
76
}
78
}