3c65189f30
后端从占位回显变为真实生成:管理员经控制面登记/激活模型,Gateway 经 NATS 下发,Dispatcher 热更新 LLM Pool,Eino 图用 OpenAI 兼容流式真实推理。 - shared: contract.ModelConfig(provider/base_url/api_key/model) + 配置 subjects; bus.RequestModelConfig/ServeModelConfig/Publish/Subscribe ModelConfigUpdated - gateway: store.LLMModel→sundynix_model(AutoMigrate,唯一激活) + admin REST (GET/POST/active/delete/test models, api_key 脱敏) + main ServeModelConfig + 变更广播; 路由 /api/v1/admin/models* - dispatcher: llm.Pool OpenAI 兼容 SSE 流式客户端(ChatStream) + 热更新配置 + 未配置则降级桩; poolModel.Ready()?真实流式:注入记忆的桩; main 取配置+订阅 - 开发期接在线 API 不拉本地模型(见 llm-provider-strategy memory) - 验证: 4 模块 build✓ + e2e PASS; mock OpenAI 服务 live 跑通——登记/测试连接✓/ 激活→NATS 热更新→提交→真实 SSE 流出 mock 回复, mock 日志证明端点被调用且 注入画像(老王)进了模型上下文 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
// Command dispatcher 启动 sundynix-dispatcher —— 第 4 层 AI Agent 调度集群。
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/sundynix/sundynix-dispatcher/internal/eino"
|
|
"github.com/sundynix/sundynix-dispatcher/internal/harness"
|
|
"github.com/sundynix/sundynix-dispatcher/internal/llm"
|
|
dnats "github.com/sundynix/sundynix-dispatcher/internal/nats"
|
|
)
|
|
|
|
func main() {
|
|
natsURL := envOr("NATS_URL", "nats://localhost:4222")
|
|
|
|
pool := llm.NewPool() // LLM Pool: vLLM / Ollama 集群
|
|
breaker := harness.NewCircuitBreaker() // Harness: 熔断降级中心
|
|
|
|
sub := dnats.MustConnect(natsURL)
|
|
defer sub.Close()
|
|
|
|
// 配置控制面:启动时取激活模型配置,并订阅热更新。
|
|
cctx, ccancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
if cfg, _ := sub.RequestModelConfig(cctx); cfg != nil {
|
|
pool.SetConfig(cfg)
|
|
} else {
|
|
log.Println("[dispatcher] 未取到在线模型配置,降级桩运行(控制台配置后将热更新)")
|
|
}
|
|
ccancel()
|
|
if _, err := sub.SubscribeModelConfigUpdated(pool.SetConfig); err != nil {
|
|
log.Printf("[dispatcher] subscribe model config: %v", err)
|
|
}
|
|
|
|
// sub 同时作为 Token 回流出口(TokenSink)与 MCP 工具调用出口(ToolCaller)。
|
|
orch, err := eino.NewOrchestrator(pool, breaker, sub, sub)
|
|
if err != nil {
|
|
log.Fatalf("[dispatcher] build eino graph: %v", err)
|
|
}
|
|
|
|
// 监听退出信号,优雅停止消费。
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
log.Println("[dispatcher] consuming sundynix.tasks.* (Ctrl-C to quit)")
|
|
if err := sub.ConsumeTasks(ctx, orch.Handle); err != nil && err != context.Canceled {
|
|
log.Fatalf("[dispatcher] exit: %v", err)
|
|
}
|
|
}
|
|
|
|
func envOr(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|