-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
50 lines (41 loc) · 1.52 KB
/
tools.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
package aichat
import (
"encoding/json"
"fmt"
)
// Tool represents a single tool
type Tool struct {
Type string `yaml:"type" json:"type"`
Function Function `yaml:"function" json:"function"`
}
// Function represents a function definition
type Function struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
// Arguments field is used by LLM to call tools
Arguments string `yaml:"arguments,omitempty" json:"arguments,omitempty"`
// Parameters field is provides available tool calling schema to LLM
Parameters Parameters `yaml:"parameters,omitempty" json:"parameters,omitempty"`
}
// Parameters defines the structure of function parameters
type Parameters struct {
Type string `yaml:"type" json:"type"`
Properties map[string]Property `yaml:"properties" json:"properties"`
Required []string `yaml:"required" json:"required"`
}
// Property contains the individual parameter definitions
type Property struct {
Type string `yaml:"type" json:"type"`
Description string `yaml:"description" json:"description"`
}
// ArgumentsMap parses the Arguments JSON string into a map[string]interface{}
func (f *Function) ArgumentsMap() (map[string]interface{}, error) {
if f.Arguments == "" {
return make(map[string]interface{}), nil
}
var result map[string]interface{}
if err := json.Unmarshal([]byte(f.Arguments), &result); err != nil {
return nil, fmt.Errorf("failed to parse arguments: %v", err)
}
return result, nil
}