Include chat, weather, image, travel, streaming ASR and text examples, shared model initialization, documentation, and existing tests. Co-authored-by: TRAE CLI <traecli@bytedance.com>
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
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: "需要查询的城市或地点,例如北京、上海"},
|
|
"start_date": {Type: schema.String, Desc: "预报开始日期,日期格式: YYYY-MM-DD"},
|
|
"end_date": {Type: schema.String, Desc: "预报结束日期,日期格式: YYYY-MM-DD"},
|
|
}),
|
|
}, 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
|
|
}
|