mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-05 21:01:50 +08:00
feat: 接入 Jev 拦截判定模型
Add TypeSafe System One as an isolated intercept judge backend.
This commit is contained in:
1 parent
0ed68d9143
commit
b0e25d766f
18 files changed
+552
-32
No files matched your search
+47
-2
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
"github.com/Autumn-27/artex/db"
|
||||
"github.com/Autumn-27/artex/intercept"
|
||||
"github.com/Autumn-27/artex/intercept/jev"
|
||||
"github.com/Autumn-27/artex/llmpool"
|
||||
"github.com/Autumn-27/artex/llmrec"
|
||||
"github.com/Autumn-27/artex/report"
|
||||
@@ -383,8 +384,9 @@ func (s *Server) loadLLMConfig() (agent.Config, bool) {
|
||||
|
||||
// saveLLMConfig persists the LLM config as the active "default" profile in PG.
|
||||
func (s *Server) saveLLMConfig(cfg agent.Config) error {
|
||||
// cfg.Provider() already returns one of the three valid format strings
|
||||
// (anthropic / openai / openai-responses), matching the DB CHECK constraint.
|
||||
// cfg.Provider() returns one of the chat format strings
|
||||
// (anthropic / openai / openai-responses), matching the DB CHECK constraint;
|
||||
// Jev is intentionally handled by the dedicated intercept path.
|
||||
format := cfg.Provider()
|
||||
var id int64
|
||||
// 这个 legacy 端点的请求体不含轮询/收发/输出上限参数,故把库里已存的值原样带回 —
|
||||
@@ -464,6 +466,9 @@ func maxTokensResolver(cfg agent.Config) func() int {
|
||||
// applyLLM (re)builds the planner/worker/main-agent from cfg and installs them on
|
||||
// the running engine as the GLOBAL active pair. Safe to call at runtime (UI configures LLM).
|
||||
func (s *Server) applyLLM(cfg agent.Config) error {
|
||||
if cfg.Jev {
|
||||
return fmt.Errorf("Jev System One 仅可用于拦截判定模型,不能作为聊天 provider")
|
||||
}
|
||||
var prov llm.Provider
|
||||
// A persisted active profile must use the same cached provider as task chains
|
||||
// and Agent bindings, otherwise each path owns a separate rate limiter.
|
||||
@@ -534,6 +539,9 @@ func (s *Server) loadProfileConfig(id int64) (agent.Config, bool) {
|
||||
if err != nil || p == nil {
|
||||
return agent.Config{}, false
|
||||
}
|
||||
if p.Format == "jev" {
|
||||
return agent.Config{}, false
|
||||
}
|
||||
cfg := agent.ConfigFrom(p.Format, p.Model, p.BaseURL, p.APIKey, p.Proxy)
|
||||
cfg.RatePerSecond, cfg.RatePerMinute = p.RatePerSecond, p.RatePerMinute
|
||||
cfg.ContextWindowK = p.ContextWindowK
|
||||
@@ -599,6 +607,9 @@ func (s *Server) chatUnavailableReason() string {
|
||||
// ok=false when the profile is missing/invalid; pinned callers surface that error
|
||||
// while legacy callers retain their existing fallback behavior.
|
||||
func (s *Server) providerForProfile(id int64) (llm.Provider, agent.Config, bool) {
|
||||
if p, err := s.m.pg.ProfileByID(id); err != nil || p == nil || p.Format == "jev" {
|
||||
return nil, agent.Config{}, false
|
||||
}
|
||||
s.provCacheMu.Lock()
|
||||
if e := s.provByProfile[id]; e != nil {
|
||||
s.provCacheMu.Unlock()
|
||||
@@ -1499,6 +1510,37 @@ func (s *Server) testLLM(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(req.Provider) == "jev" {
|
||||
apiKey := strings.TrimSpace(req.APIKey)
|
||||
baseURL, model := strings.TrimSpace(req.BaseURL), strings.TrimSpace(req.Model)
|
||||
if req.ProfileID != nil {
|
||||
if p, err := s.m.pg.ProfileByID(*req.ProfileID); err == nil && p != nil {
|
||||
if apiKey == "" {
|
||||
apiKey = p.APIKey
|
||||
}
|
||||
if baseURL == "" {
|
||||
baseURL = p.BaseURL
|
||||
}
|
||||
if model == "" {
|
||||
model = p.Model
|
||||
}
|
||||
}
|
||||
}
|
||||
if apiKey == "" {
|
||||
writeJSON(w, 200, map[string]any{"ok": false, "error": "未提供 API Key"})
|
||||
return
|
||||
}
|
||||
if model == "" {
|
||||
model = jev.DefaultModel
|
||||
}
|
||||
lat, reply, err := (jev.Config{BaseURL: baseURL, APIKey: apiKey, Model: model}).TestConnection(r.Context())
|
||||
if err != nil {
|
||||
writeJSON(w, 200, map[string]any{"ok": false, "error": err.Error()})
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"ok": true, "latency_ms": lat.Milliseconds(), "model": model, "reply": truncateReply(reply)})
|
||||
return
|
||||
}
|
||||
cfg := agent.ConfigFrom(req.Provider, req.Model, req.BaseURL, req.APIKey, req.Proxy)
|
||||
// mirror production: send the SAME thinking params so a provider that rejects the
|
||||
// reasoning_effort/thinking field fails the test too (no false "test ok, run 400").
|
||||
@@ -1693,6 +1735,9 @@ func (s *Server) validateTaskProfileIDs(ids []int64) error {
|
||||
return fmt.Errorf("LLM 配置 id 无效或重复")
|
||||
}
|
||||
seen[id] = true
|
||||
if p, err := s.m.pg.ProfileByID(id); err == nil && p != nil && p.Format == "jev" {
|
||||
return db.ErrJevProfileJudgeOnly
|
||||
}
|
||||
if _, ok := s.loadProfileConfig(id); !ok {
|
||||
return fmt.Errorf("LLM 配置 #%d 不存在或未设置 API Key", id)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user