/* * Package time provides a Ollama tool to control the time. */ package time import ( "context" "fmt" "github.com/ollama/ollama/api" "tipsy.codes/charles/mc-god/v2/internal/pkg/rcon" ) func Get() *Tool { return &Tool{} } type Tool struct{} func (t *Tool) Name() string { return "change_time" } func (t *Tool) Desc() api.Tool { toolPropertiesMap := api.NewToolPropertiesMap() toolPropertiesMap.Set("time", api.ToolProperty{ Type: api.PropertyType{"string"}, Description: "What to set the weather too", Enum: []any{"day", "noon", "midnight"}, }) return api.Tool{ Type: "function", Function: api.ToolFunction{ Name: Get().Name(), Description: "Changes the current time", Parameters: api.ToolFunctionParameters{ Type: "object", Properties: &api.ToolPropertiesMap{}, Required: []string{"time"}, }, }, } } func (t *Tool) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error { time, found := toolCall.Function.Arguments.Get("time") if !found { return fmt.Errorf("missing time argument") } timeSting, ok := time.(string) if !ok { return fmt.Errorf("incorrect data type %v; want string", time) } if _, err := client.Execute("/time set " + timeSting); err != nil { return fmt.Errorf("failed to call tool") } return nil }