Files
mc-god/internal/pkg/tools/weather/weather.go
2026-02-17 09:01:41 -08:00

60 lines
1.4 KiB
Go

/*
* Package weather provides a Ollama tool to control the weather.
*/
package weather
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_weather"
}
func (t *Tool) Desc() api.Tool {
toolPropertiesMap := api.NewToolPropertiesMap()
toolPropertiesMap.Set("weather", api.ToolProperty{
Type: api.PropertyType{"string"},
Description: "What to set the weather too. NOTE: case with the value provided is important. Keep it lower case.",
Enum: []any{"clear", "rain", "thunder"},
})
return api.Tool{
Type: "function",
Function: api.ToolFunction{
Name: Get().Name(),
Description: "Changes the weather on the server",
Parameters: api.ToolFunctionParameters{
Type: "object",
Properties: &api.ToolPropertiesMap{},
Required: []string{"weather"},
},
},
}
}
func (t *Tool) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error {
weather, found := toolCall.Function.Arguments.Get("weather")
if !found {
return fmt.Errorf("missing weather argument")
}
weatherString, ok := weather.(string)
if !ok {
return fmt.Errorf("incorrect data type %v; want string", weather)
}
if _, err := client.Execute("/weather " + weatherString); err != nil {
return fmt.Errorf("failed to call tool")
}
return nil
}