Version: 0.4.0.dev.260302
修改了gitignore文件,使得yaml不会被上传,保护隐私 接入eino,实现了agent的消息sse流式传输
This commit is contained in:
35
backend/service/agent.go
Normal file
35
backend/service/agent.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LoveLosita/smartflow/backend/agent"
|
||||
"github.com/LoveLosita/smartflow/backend/inits"
|
||||
)
|
||||
|
||||
type AgentService struct {
|
||||
AIHub *inits.AIHub
|
||||
}
|
||||
|
||||
func NewAgentService(aiHub *inits.AIHub) *AgentService {
|
||||
return &AgentService{
|
||||
AIHub: aiHub,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AgentService) AgentChat(ctx context.Context, userMessage string) (<-chan string, <-chan error) {
|
||||
//1. 创建一个输出通道
|
||||
outChan := make(chan string, 5)
|
||||
errChan := make(chan error)
|
||||
//2. 启动一个 goroutine 来处理聊天逻辑
|
||||
go func() {
|
||||
defer close(outChan) // 确保在函数结束时关闭通道
|
||||
//3. 调用 StreamChat 函数进行流式聊天
|
||||
err := agent.StreamChat(ctx, s.AIHub.Worker, userMessage, outChan)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
}()
|
||||
return outChan, errChan
|
||||
}
|
||||
Reference in New Issue
Block a user