feat: add weather tools to legacy and Eino chat
This commit is contained in:
1 parent
6e6171f481
commit
86e86bc9fa
18 files changed
+926
-77
No files matched your search
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user