add: weather control
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
mcgod
|
mcgod
|
||||||
|
.env
|
||||||
|
|||||||
@@ -118,11 +118,30 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start goroutines to do the things
|
// 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{
|
chatRequest := &api.ChatRequest{
|
||||||
Model: "qwen3-coder",
|
Model: "qwen3-coder",
|
||||||
Stream: proto.Bool(false),
|
Stream: proto.Bool(false),
|
||||||
KeepAlive: &api.Duration{Duration: time.Hour},
|
KeepAlive: &api.Duration{Duration: time.Hour},
|
||||||
Tools: api.Tools{},
|
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},
|
Think: &api.ThinkValue{Value: false},
|
||||||
Shift: proto.Bool(true),
|
Shift: proto.Bool(true),
|
||||||
Messages: []api.Message{
|
Messages: []api.Message{
|
||||||
@@ -184,6 +203,24 @@ func handleOllama(ctx context.Context, client *api.Client, chat *chatContext, rC
|
|||||||
slog.Error("error calling ollama", "error", err)
|
slog.Error("error calling ollama", "error", err)
|
||||||
}
|
}
|
||||||
chat.AddSelf(chatResponse.Message)
|
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 {
|
if err := rClient.Say(chatResponse.Message.Content); err != nil {
|
||||||
slog.Error("error talking", "error", err)
|
slog.Error("error talking", "error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user