diff --git a/.gitignore b/.gitignore index d564802..9677d87 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ mcgod +.env diff --git a/cmd/mcgod/main.go b/cmd/mcgod/main.go index 021682f..f9889d2 100644 --- a/cmd/mcgod/main.go +++ b/cmd/mcgod/main.go @@ -118,13 +118,32 @@ func main() { } // Start goroutines to do the things + toolPropertiesMap := api.NewToolPropertiesMap() + toolPropertiesMap.Set("weather", api.ToolProperty{ + Type: api.PropertyType{"string"}, + Description: "What to set the weather too", + Enum: []any{"clear", "rain", "thunder"}, + }) chatRequest := &api.ChatRequest{ Model: "qwen3-coder", Stream: proto.Bool(false), KeepAlive: &api.Duration{Duration: time.Hour}, - Tools: api.Tools{}, - Think: &api.ThinkValue{Value: false}, - Shift: proto.Bool(true), + Tools: api.Tools{ + api.Tool{ + Type: "function", + Function: api.ToolFunction{ + Name: "change_weather", + Description: "Changes the weather on the server", + Parameters: api.ToolFunctionParameters{ + Type: "object", + Properties: &api.ToolPropertiesMap{}, + Required: []string{"weather"}, + }, + }, + }, + }, + Think: &api.ThinkValue{Value: false}, + Shift: proto.Bool(true), Messages: []api.Message{ api.Message{ Role: "system", @@ -184,6 +203,24 @@ func handleOllama(ctx context.Context, client *api.Client, chat *chatContext, rC slog.Error("error calling ollama", "error", err) } chat.AddSelf(chatResponse.Message) + for _, toolCall := range chatResponse.Message.ToolCalls { + switch toolCall.Function.Name { + case "change_weather": + weather, found := toolCall.Function.Arguments.Get("weather") + if !found { + slog.Warn("weather argument not found") + break + } + weatherString, ok := weather.(string) + if !ok { + slog.Warn("invalid type", "obj", weather) + break + } + if _, err := rClient.Execute("/weather " + weatherString); err != nil { + slog.Warn("failed to call rcon", "error", err) + } + } + } if err := rClient.Say(chatResponse.Message.Content); err != nil { slog.Error("error talking", "error", err) }