code.oscarkilo.com/klex-git

Hash:
1edf1c524915e944dd79a1da5aa3cf2ff0f94608
Author:
Igor Naverniouk <[email protected]>
Date:
Thu Oct 10 15:10:46 2024 -0700
Message:
simpler tool schema
diff --git a/api/messages.go b/api/messages.go
index 4075b7b..87dd3e9 100644
--- a/api/messages.go
+++ b/api/messages.go
@@ -60,19 +60,12 @@ type MessagesResponse struct {
}

type Tool struct {
- Name string `json:"name"`
- Description string `json:"description"`
- InputSchema JSONSchema `json:"input_schema"`
+ Type string `json:"type"`
+ Function *ToolFunction `json:"function"`
}

-// JSONSchema is the subset of json-shcema.org that we need.
-type JSONSchema struct {
- Type string `json:"type"`
- Properties map[string]JSONSchema `json:"properties,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"`
- Required []string `json:"required,omitempty"`
+type ToolFunction struct {
+ Name string `json:"name"`
+ Description string `json:"description"`
+ InputSchema interface{} `json:"input_schema"`
}
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
Type string `json:"type"`
64
Description string `json:"description"`
64
Function *ToolFunction `json:"function"`
65
InputSchema JSONSchema `json:"input_schema"`
66
}
65
}
67
66
68
// JSONSchema is the subset of json-shcema.org that we need.
67
type ToolFunction struct {
69
type JSONSchema struct {
68
Name string `json:"name"`
70
Type string `json:"type"`
69
Description string `json:"description"`
71
Properties map[string]JSONSchema `json:"properties,omitempty"`
70
InputSchema interface{} `json:"input_schema"`
72
Items bool `json:"items,omitempty"`
73
PrefixItems []JSONSchema `json:"prefixItems,omitempty"`
74
UnevaluatedItems bool `json:"unevaluatedItems,omitempty"`
75
AdditionalProperties bool `json:"additionalProperties,omitempty"`
76
UnevaluatedProperties bool `json:"unevaluatedProperties,omitempty"`
77
Required []string `json:"required,omitempty"`
78
}
71
}