add: finalize logic
This commit is contained in:
59
internal/pkg/tools/weather/weather.go
Normal file
59
internal/pkg/tools/weather/weather.go
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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",
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user