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>
25 lines
679 B
Go
25 lines
679 B
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/cloudwego/eino/adk"
|
|
)
|
|
|
|
type DateHandler struct {
|
|
adk.BaseChatModelAgentMiddleware
|
|
}
|
|
|
|
func (h *DateHandler) BeforeAgent(ctx context.Context, runCtx *adk.ChatModelAgentContext) (context.Context, *adk.ChatModelAgentContext, error) {
|
|
// 每轮更新日期,避免程序跨天后仍使用启动时的日期。
|
|
now := time.Now().In(time.FixedZone("Asia/Shanghai", 8*60*60))
|
|
datePrompt := fmt.Sprintf("当前时区:Asia/Shanghai(UTC+08:00)\n当前时间:%s", now.Format("2006-01-02 15:04:05"))
|
|
sp := fmt.Sprintf(`%s
|
|
---
|
|
%s`, runCtx.Instruction, datePrompt)
|
|
runCtx.Instruction = sp
|
|
return ctx, runCtx, nil
|
|
}
|