feat: initialize Eino examples and ADK applications
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>
This commit is contained in:
commit
81deca8c8e
75 files changed
+7048
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"example.com/ueino/pkg/model"
|
||||
|
||||
einotool "github.com/cloudwego/eino/components/tool"
|
||||
)
|
||||
|
||||
var ErrImageRejected = errors.New("已取消生图")
|
||||
|
||||
// confirmedImage 将确认策略放在 ADK 应用层,公共生图工具仍只负责执行。
|
||||
type confirmedImage struct {
|
||||
einotool.InvokableTool
|
||||
}
|
||||
|
||||
func (i *confirmedImage) InvokableRun(ctx context.Context, arguments string, opts ...einotool.Option) (string, error) {
|
||||
var args model.ImageArguments
|
||||
if err := json.Unmarshal([]byte(arguments), &args); err != nil {
|
||||
return "", fmt.Errorf("生图参数无效: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(args.Prompt) == "" {
|
||||
return "", fmt.Errorf("生图提示词不能为空")
|
||||
}
|
||||
wasInterrupted, _, _ := einotool.GetInterruptState[any](ctx)
|
||||
if !wasInterrupted {
|
||||
return "", einotool.Interrupt(ctx, args.Prompt)
|
||||
}
|
||||
target, hasData, approved := einotool.GetResumeContext[bool](ctx)
|
||||
if !target || !hasData {
|
||||
return "", einotool.Interrupt(ctx, args.Prompt)
|
||||
}
|
||||
if !approved {
|
||||
return "", ErrImageRejected
|
||||
}
|
||||
return i.InvokableTool.InvokableRun(ctx, arguments, opts...)
|
||||
}
|
||||
Reference in new issue
Block a user