feat: embedding 配置搬上控制面 — 数据源页可视化配置 + 热更新
embedding 从 env 改为控制面驱动(持久化+可视化),复用 chat 模型同套范式: 配置控制面泛化为按 kind(chat/embedding),加 embedding kind。 - shared: 配置 subjects 泛化 sundynix.config.<kind>.get/.updated;bus 方法改 kind 参数 (RequestConfig/ServeConfig/PublishConfigUpdated/SubscribeConfigUpdated) - gateway: sundynix_model 加 kind 列(每 kind 唯一激活)+旧行回填 chat;admin 按 kind 增删改/激活/列表,测试连接 embedding 走 POST /embeddings;main 按 kind ServeConfig; 变更广播各 kind - dispatcher: 取 chat 配置(kind 化) - mcp-go: rag.Engine.SetEmbedding 热更新(RWMutex);main 取/订阅 embedding 控制面配置 (覆盖 env) - admin 控制台: api 按 kind;抽出复用 ModelManager;ModelsPage(chat)+新 DatasourcesPage (embedding + 向量/图库占位);routes 数据源页就绪 - 验证: 全模块 build✓ + e2e PASS + 控制台 npm build✓;live 全跑通——chat(DeepSeek 回填 kind 仍工作);mcp-go 不带 EMBED env 启动→控制台配 embedding(百炼)→测试连接✓→激活 →NATS 热更新 mcp-go→入库+语义检索'存向量的数据库'→Milvus;浏览器数据源页拉到激活配置 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+15
-15
@@ -185,10 +185,10 @@ func respond(m *nats.Msg, res *contract.ToolResult) {
|
||||
|
||||
// ---- 配置控制面(core NATS request-reply + broadcast)----
|
||||
|
||||
// RequestModelConfig 向控制面(Gateway)请求当前激活的模型配置。
|
||||
// RequestConfig 向控制面(Gateway)请求某 kind 当前激活配置(chat/embedding)。
|
||||
// 无人应答 / 无激活配置时返回 (nil, nil),由调用方降级。
|
||||
func (b *Bus) RequestModelConfig(ctx context.Context) (*contract.ModelConfig, error) {
|
||||
msg, err := b.nc.RequestWithContext(ctx, contract.SubjectConfigModelGet, nil)
|
||||
func (b *Bus) RequestConfig(ctx context.Context, kind string) (*contract.ModelConfig, error) {
|
||||
msg, err := b.nc.RequestWithContext(ctx, contract.ConfigGetSubject(kind), nil)
|
||||
if err != nil {
|
||||
return nil, nil // 控制面暂不可用,降级
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (b *Bus) RequestModelConfig(ctx context.Context) (*contract.ModelConfig, er
|
||||
}
|
||||
var cfg contract.ModelConfig
|
||||
if err := json.Unmarshal(msg.Data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal model config: %w", err)
|
||||
return nil, fmt.Errorf("unmarshal %s config: %w", kind, err)
|
||||
}
|
||||
if !cfg.Ready() {
|
||||
return nil, nil
|
||||
@@ -205,9 +205,9 @@ func (b *Bus) RequestModelConfig(ctx context.Context) (*contract.ModelConfig, er
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// ServeModelConfig 让控制面响应配置请求;provide 返回当前激活配置(可为 nil)。
|
||||
func (b *Bus) ServeModelConfig(provide func() *contract.ModelConfig) (unsub func() error, err error) {
|
||||
sub, err := b.nc.Subscribe(contract.SubjectConfigModelGet, func(m *nats.Msg) {
|
||||
// ServeConfig 让控制面响应某 kind 的配置请求;provide 返回当前激活配置(可为 nil)。
|
||||
func (b *Bus) ServeConfig(kind string, provide func() *contract.ModelConfig) (unsub func() error, err error) {
|
||||
sub, err := b.nc.Subscribe(contract.ConfigGetSubject(kind), func(m *nats.Msg) {
|
||||
var data []byte
|
||||
if cfg := provide(); cfg != nil {
|
||||
data, _ = json.Marshal(cfg)
|
||||
@@ -215,30 +215,30 @@ func (b *Bus) ServeModelConfig(provide func() *contract.ModelConfig) (unsub func
|
||||
_ = m.Respond(data)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("serve model config: %w", err)
|
||||
return nil, fmt.Errorf("serve %s config: %w", kind, err)
|
||||
}
|
||||
return sub.Unsubscribe, nil
|
||||
}
|
||||
|
||||
// PublishModelConfigUpdated 广播模型配置变更(Dispatcher 据此热更新)。
|
||||
func (b *Bus) PublishModelConfigUpdated(cfg *contract.ModelConfig) error {
|
||||
// PublishConfigUpdated 广播某 kind 的配置变更(消费方据此热更新)。
|
||||
func (b *Bus) PublishConfigUpdated(kind string, cfg *contract.ModelConfig) error {
|
||||
data, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.nc.Publish(contract.SubjectConfigModelUpdated, data)
|
||||
return b.nc.Publish(contract.ConfigUpdatedSubject(kind), data)
|
||||
}
|
||||
|
||||
// SubscribeModelConfigUpdated 订阅模型配置变更。
|
||||
func (b *Bus) SubscribeModelConfigUpdated(onUpdate func(*contract.ModelConfig)) (unsub func() error, err error) {
|
||||
sub, err := b.nc.Subscribe(contract.SubjectConfigModelUpdated, func(m *nats.Msg) {
|
||||
// SubscribeConfigUpdated 订阅某 kind 的配置变更。
|
||||
func (b *Bus) SubscribeConfigUpdated(kind string, onUpdate func(*contract.ModelConfig)) (unsub func() error, err error) {
|
||||
sub, err := b.nc.Subscribe(contract.ConfigUpdatedSubject(kind), func(m *nats.Msg) {
|
||||
var cfg contract.ModelConfig
|
||||
if json.Unmarshal(m.Data, &cfg) == nil {
|
||||
onUpdate(&cfg)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("subscribe model config: %w", err)
|
||||
return nil, fmt.Errorf("subscribe %s config: %w", kind, err)
|
||||
}
|
||||
return sub.Unsubscribe, nil
|
||||
}
|
||||
|
||||
@@ -30,18 +30,23 @@ const (
|
||||
// MetaSessionID 是 Task.Meta 中承载会话标识的键(用于短期多轮历史)。
|
||||
MetaSessionID = "session_id"
|
||||
|
||||
// 配置控制面(Gateway 持有配置,Dispatcher 经 NATS 取用/订阅变更)。
|
||||
SubjectConfigModelGet = "sundynix.config.model.get" // request-reply:取当前激活模型配置
|
||||
SubjectConfigModelUpdated = "sundynix.config.model.updated" // broadcast:模型配置变更通知
|
||||
// 配置控制面按 kind 寻址:sundynix.config.<kind>.get / .updated。
|
||||
// Gateway 持有配置,消费方(Dispatcher/mcp-go)经 NATS 取用/订阅变更。
|
||||
ConfigKindChat = "chat" // 对话模型(Dispatcher 用)
|
||||
ConfigKindEmbedding = "embedding" // 向量模型(mcp-go RAG 用)
|
||||
)
|
||||
|
||||
// ModelConfig 是一个 LLM 后端的连接配置(provider 抽象)。
|
||||
// 开发期指向第三方在线 API(OpenAI 兼容);生产期可换自部署(vLLM)或其它在线模型。
|
||||
// ConfigGetSubject / ConfigUpdatedSubject 返回某类配置的 request / 广播主题。
|
||||
func ConfigGetSubject(kind string) string { return "sundynix.config." + kind + ".get" }
|
||||
func ConfigUpdatedSubject(kind string) string { return "sundynix.config." + kind + ".updated" }
|
||||
|
||||
// ModelConfig 是一个模型后端的连接配置(provider 抽象,chat 与 embedding 同形)。
|
||||
// 开发期指向第三方在线 API(OpenAI 兼容);生产期可换自部署或其它在线模型。
|
||||
type ModelConfig struct {
|
||||
Provider string `json:"provider"` // openai-compatible / vllm / ...
|
||||
BaseURL string `json:"base_url"` // 如 https://api.deepseek.com/v1
|
||||
BaseURL string `json:"base_url"` // 如 https://api.deepseek.com
|
||||
APIKey string `json:"api_key,omitempty"`
|
||||
Model string `json:"model"` // 如 deepseek-chat
|
||||
Model string `json:"model"` // 如 deepseek-chat / text-embedding-v3
|
||||
}
|
||||
|
||||
// Ready 报告该配置是否足以发起真实推理。
|
||||
|
||||
Reference in New Issue
Block a user