/* * Package zombie provides a Ollama tool to summon zombies. */ package zombie 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 "summon_zombies" } func (t *Tool) Desc() api.Tool { toolPropertiesMap := api.NewToolPropertiesMap() toolPropertiesMap.Set("player", api.ToolProperty{ Type: api.PropertyType{"string"}, Description: "Player to target with zombie summons", }) toolPropertiesMap.Set("count", api.ToolProperty{ Type: api.PropertyType{"int"}, Description: "Number of zombies to summon, between 1 and 3. If omitted, 1 zombie is spawned", }) 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{"player"}, }, }, } } func (t *Tool) Do(ctx context.Context, toolCall api.ToolCall, client *rcon.Client) error { player, found := toolCall.Function.Arguments.Get("player") if !found { return fmt.Errorf("missing weather argument") } playerString, ok := player.(string) if !ok { return fmt.Errorf("incorrect data type %v; want string", player) } zombieCount := 1 if count, found := toolCall.Function.Arguments.Get("count"); found { countInt, ok := count.(int) if !ok { return fmt.Errorf("incorrect data type %v; want int", countInt) } zombieCount = countInt } if zombieCount > 4 { zombieCount = 4 } for i := 0; i < zombieCount; i += 1 { client.Execute(fmt.Sprintf("/execute at %q run summon zombie ~ ~ ~", playerString)) } return nil }