add: weather control
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
mcgod
|
||||
.env
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user