ai-courseware/eino-project/internal/domain/tools/order.go

46 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tools
import (
"context"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/components/tool/utils"
)
var ordersMock = []*Order{
{ID: "O001", Status: "failed", Product: "商品 272", Amount: 1, CreateTime: "2025-11-11 14:45:00"},
{ID: "O004", Status: "created", Product: "手机 A1", Amount: 1, CreateTime: "2025-11-01 10:00:00"},
{ID: "O002", Status: "paid", Product: "手机 Pro X", Amount: 2, CreateTime: "2025-11-02 11:30:00"},
{ID: "O003", Status: "shipped", Product: "笔记本 M3", Amount: 1, CreateTime: "2025-11-05 09:15:00"},
{ID: "O271", Status: "created", Product: "商品 271", Amount: 3, CreateTime: "2025-11-10 12:00:00"},
}
type Order struct {
ID string `json:"id"`
Status string `json:"status"`
Product string `json:"product"`
Amount int `json:"amount"`
CreateTime string `json:"create_time"`
}
type OrderByIDInput struct {
OrderID string `json:"order_id" jsonschema:"description=订单ID"`
}
func NewOrderByIDTool() tool.InvokableTool {
t, err := utils.InferTool("get_order_by_id", "根据订单ID查询订单详情返回订单对象。", orderByID)
if err != nil {
panic(err)
}
return t
}
func orderByID(ctx context.Context, in *OrderByIDInput) (*Order, error) {
for _, it := range ordersMock {
if it.ID == in.OrderID {
return it, nil
}
}
return &Order{}, nil
}