Files
smartmate/backend/services/llm/service.go
Losita d7184b776b Version: 0.9.75.dev.260505
后端:
1.收口阶段 6 agent 结构迁移,将 newAgent 内核与 agentsvc 编排层迁入 services/agent
- 切换 Agent 启动装配与 HTTP handler 直连 agent sv,移除旧 service agent bridge
- 补齐 Agent 对 memory、task、task-class、schedule 的 RPC 适配与契约字段
- 扩展 schedule、task、task-class RPC/contract 支撑 Agent 查询、写入与 provider 切流
- 更新迁移文档、README 与相关注释,明确 agent 当前切流点和剩余 memory 迁移面
2026-05-05 16:00:57 +08:00

110 lines
3.0 KiB
Go
Raw 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 llm
import (
"strings"
"github.com/LoveLosita/smartflow/backend/inits"
)
// Service 只负责统一暴露已经构造好的模型客户端,不负责 prompt 和业务编排。
type Service struct {
liteClient *Client
proClient *Client
maxClient *Client
courseImageResponsesClient *ArkResponsesClient
}
// Options 描述 llm-service 初始化时需要接管的启动期依赖。
// 1. AIHub 仍然是当前进程内 Ark ChatModel 的来源,但服务层只保存统一 Client。
// 2. CourseImageResponsesClient 允许外部预先注入,便于测试或特殊启动路径复用。
// 3. 某个字段为空时不报错,直接保留 nil交给上层继续走兼容降级。
type Options struct {
AIHub *inits.AIHub
APIKey string
BaseURL string
CourseVisionModel string
CourseImageResponsesClient *ArkResponsesClient
}
// AgentModelClients 一次性暴露 agent 图常用的模型分配结果。
type AgentModelClients struct {
Chat *Client
Plan *Client
Execute *Client
Deliver *Client
Summary *Client
}
// New 构造 llm-service。
// 1. 不返回 error是为了让上层继续按 nil 客户端做逐步降级。
// 2. 只要 AIHub 已初始化,就把其中的 ChatModel 收敛成统一 Client。
// 3. 课程图片解析客户端在这里统一构建,避免业务层直接依赖 Responses SDK。
func New(opts Options) *Service {
svc := &Service{}
if opts.AIHub != nil {
svc.liteClient = WrapArkClient(opts.AIHub.Lite)
svc.proClient = WrapArkClient(opts.AIHub.Pro)
svc.maxClient = WrapArkClient(opts.AIHub.Max)
}
if opts.CourseImageResponsesClient != nil {
svc.courseImageResponsesClient = opts.CourseImageResponsesClient
} else {
apiKey := strings.TrimSpace(opts.APIKey)
baseURL := strings.TrimSpace(opts.BaseURL)
model := strings.TrimSpace(opts.CourseVisionModel)
if apiKey != "" && model != "" {
svc.courseImageResponsesClient = NewArkResponsesClient(apiKey, baseURL, model)
}
}
return svc
}
// LiteClient 返回低成本短输出模型客户端。
func (s *Service) LiteClient() *Client {
if s == nil {
return nil
}
return s.liteClient
}
// ProClient 返回默认复杂对话模型客户端。
func (s *Service) ProClient() *Client {
if s == nil {
return nil
}
return s.proClient
}
// MaxClient 返回深度推理模型客户端。
func (s *Service) MaxClient() *Client {
if s == nil {
return nil
}
return s.maxClient
}
// CourseImageResponsesClient 返回课程图片解析所用的 Responses 客户端。
func (s *Service) CourseImageResponsesClient() *ArkResponsesClient {
if s == nil {
return nil
}
return s.courseImageResponsesClient
}
// NewAgentModelClients 一次性返回 agent 图里常用的模型分配。
func (s *Service) NewAgentModelClients() AgentModelClients {
if s == nil {
return AgentModelClients{}
}
return AgentModelClients{
Chat: s.ProClient(),
Plan: s.MaxClient(),
Execute: s.MaxClient(),
Deliver: s.ProClient(),
Summary: s.LiteClient(),
}
}