Files
example-eino/pkg/tool/weather_eino.go
T

30 lines
915 B
Go

package tool
import (
"context"
einotool "github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/schema"
)
// Info 提供 Eino 所需的天气工具定义。
func (w *Weather) Info(ctx context.Context) (*schema.ToolInfo, error) {
definition := w.Definition().Function
return &schema.ToolInfo{
Name: definition.Name,
Desc: definition.Description,
ParamsOneOf: schema.NewParamsOneOfByParams(map[string]*schema.ParameterInfo{
"location": {Type: schema.String, Required: true, Desc: "需要查询的城市或地点,例如北京、上海"},
}),
}, nil
}
// InvokableRun 直接复用天气查询,执行失败时把错误交回模型。
func (w *Weather) InvokableRun(ctx context.Context, arguments string, _ ...einotool.Option) (string, error) {
result, err := w.Execute(ctx, arguments)
if err != nil {
return "工具执行失败: " + err.Error(), nil
}
return result, nil
}