codebee 0.1.95 → 0.1.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +733 -720
- package/LICENSE +21 -21
- package/README.md +516 -509
- package/app/core/acceptance.py +100 -100
- package/app/core/agent_context.py +118 -0
- package/app/core/aiflavor.py +197 -197
- package/app/core/analytics.py +38 -38
- package/app/core/artifacts.py +148 -148
- package/app/core/assets.py +110 -110
- package/app/core/attachments.py +623 -623
- package/app/core/audit.py +30 -30
- package/app/core/backup.py +470 -470
- package/app/core/beekeeper.py +183 -183
- package/app/core/benchstore.py +102 -95
- package/app/core/board.py +246 -209
- package/app/core/bookmeta.py +1036 -1036
- package/app/core/bookmeta_catalog.py +180 -180
- package/app/core/branching.py +137 -137
- package/app/core/builtin_agent.py +2055 -1680
- package/app/core/capability.py +144 -144
- package/app/core/chaptersafe.py +32 -32
- package/app/core/checkpoints.py +648 -0
- package/app/core/cleanup.py +303 -303
- package/app/core/compaction.py +201 -201
- package/app/core/contracts.py +255 -255
- package/app/core/covergen.py +356 -356
- package/app/core/defectretro.py +43 -43
- package/app/core/diagnostics.py +114 -114
- package/app/core/dispatch.py +198 -191
- package/app/core/dispatch_log.py +128 -128
- package/app/core/env_scrub.py +85 -85
- package/app/core/errorlog.py +137 -137
- package/app/core/eval_matrix.py +82 -0
- package/app/core/evalbench.py +184 -91
- package/app/core/evaluation.py +174 -174
- package/app/core/failure_notify.py +290 -290
- package/app/core/flow_graph.py +33 -0
- package/app/core/goal_service.py +167 -167
- package/app/core/health.py +389 -389
- package/app/core/history.py +38 -38
- package/app/core/hooks.py +162 -162
- package/app/core/jobs.py +25 -4
- package/app/core/knowledge_pipeline.py +86 -0
- package/app/core/manager.py +2232 -2232
- package/app/core/mcp_client.py +200 -29
- package/app/core/mocks.py +64 -64
- package/app/core/notify.py +201 -201
- package/app/core/novel_quality.py +181 -189
- package/app/core/openapi.py +177 -154
- package/app/core/operations.py +228 -228
- package/app/core/paihang.py +145 -145
- package/app/core/pipeline.py +319 -59
- package/app/core/planner.py +17 -11
- package/app/core/policy.py +84 -0
- package/app/core/portguard.py +111 -111
- package/app/core/presence.py +77 -77
- package/app/core/preview.py +293 -293
- package/app/core/project_memory.py +139 -0
- package/app/core/prompt_guard.py +78 -78
- package/app/core/publish/__init__.py +7 -7
- package/app/core/publish/auto.py +106 -22
- package/app/core/publish/browser.py +694 -655
- package/app/core/publish/chaprows.py +138 -0
- package/app/core/publish/fanqie.py +212 -165
- package/app/core/publish/flow.py +832 -640
- package/app/core/publish/flows-fanqie-calibrated.json +361 -336
- package/app/core/publish/ledger.py +51 -2
- package/app/core/publish/manager.py +1150 -1118
- package/app/core/publish/qimao.py +176 -176
- package/app/core/publish/volumes.py +108 -0
- package/app/core/publish/ws.py +139 -139
- package/app/core/quality_gate.py +194 -194
- package/app/core/redact.py +38 -38
- package/app/core/repeat_guard.py +129 -129
- package/app/core/retrieval.py +137 -137
- package/app/core/router.py +398 -398
- package/app/core/runner.py +2239 -2238
- package/app/core/selfupdate.py +384 -384
- package/app/core/session_log.py +161 -161
- package/app/core/sessions.py +312 -312
- package/app/core/settings.py +33 -5
- package/app/core/settings_schema.py +282 -271
- package/app/core/share_page.py +114 -114
- package/app/core/skill_scan.py +139 -139
- package/app/core/skillpacks/fanqie-novel.md +8 -6
- package/app/core/skillpacks/market/character-bible.md +66 -66
- package/app/core/skillpacks/market/code-risk-checklist.md +58 -58
- package/app/core/skillpacks/market/git-workflow.md +57 -57
- package/app/core/skillpacks/market/release-notes.md +72 -72
- package/app/core/skillpacks/market/weekly-report.md +71 -71
- package/app/core/skillpacks/market/worldview-consistency.md +70 -70
- package/app/core/skillpacks/qimao-signing.md +14 -11
- package/app/core/skills.py +32 -21
- package/app/core/step_runner.py +132 -132
- package/app/core/store.py +24 -0
- package/app/core/story_tracking.py +275 -275
- package/app/core/task_compile.py +199 -199
- package/app/core/telemetry.py +292 -292
- package/app/core/tlsctx.py +64 -64
- package/app/core/token_meter.py +147 -147
- package/app/core/tool_outputs.py +107 -0
- package/app/core/tracing.py +207 -144
- package/app/core/upstream.py +41 -41
- package/app/core/usage.py +1038 -1038
- package/app/core/volumes.py +389 -389
- package/app/core/webhooks.py +89 -0
- package/app/core/wxdigest.py +865 -858
- package/app/core/zentao.py +2692 -2692
- package/app/main.py +179 -10
- package/app/mcp_server.py +244 -244
- package/app/pick_dialog.py +110 -110
- package/app/ui/app.js +563 -21
- package/app/ui/artdiff.js +74 -74
- package/app/ui/assets/community-qr.png +0 -0
- package/app/ui/assets/donate-alipay.jpg +0 -0
- package/app/ui/assets/donate-qr.jpg +0 -0
- package/app/ui/assets/workbench-reference.png +0 -0
- package/app/ui/board.css +451 -666
- package/app/ui/board.html +165 -162
- package/app/ui/board.js +509 -305
- package/app/ui/hive3d.js +242 -0
- package/app/ui/i18n.js +125 -9
- package/app/ui/icons/bee.svg +79 -79
- package/app/ui/index.html +60 -3
- package/app/ui/manifest.json +16 -16
- package/app/ui/qrcode.js +2297 -2297
- package/app/ui/style.css +189 -9
- package/bin/tutti.js +147 -147
- package/package.json +49 -48
- package/tools/wx_reader.py +261 -261
- package/app/.playwright-cli/console-2026-09-23T08-26-03-635Z.log +0 -88
- package/app/.playwright-cli/page-2026-09-23T08-26-03-845Z.yml +0 -126
- package/app/.playwright-cli/page-2026-09-23T08-29-44-203Z.png +0 -0
- package/app/.playwright-cli/page-2026-09-23T08-35-42-046Z.yml +0 -210
- package/app/.playwright-cli/page-2026-09-23T08-36-52-858Z.png +0 -0
- package/app/.playwright-cli/page-2026-09-23T08-37-33-938Z.png +0 -0
- package/app/.playwright-cli/run-detail-after.png +0 -0
- package/app/output/_createbook_body.json +0 -1
- package/app/output/_probe_fq_click.py +0 -50
- package/app/output/_probe_fq_form.py +0 -42
- package/app/output/_probe_fq_modal.py +0 -55
- package/app/output/_probe_fq_points.py +0 -71
- package/app/output/_probe_fq_submit.py +0 -34
- package/app/output/_probe_fq_watch.py +0 -62
package/app/core/dispatch.py
CHANGED
|
@@ -1,191 +1,198 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""统一调度评分:任务画像、CLI 亲和度与模型链排序。
|
|
3
|
-
|
|
4
|
-
调用方先完成协议、启停、健康、密钥等硬约束过滤,再把可用候选交给这里评分;
|
|
5
|
-
静态能力与近期用量台账只提供软信号,相同分数保持用户原顺序。
|
|
6
|
-
"""
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
import math
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TYPE_DIMENSIONS = {
|
|
13
|
-
"direct": "reasoning",
|
|
14
|
-
"code": "coding",
|
|
15
|
-
"novel": "writing",
|
|
16
|
-
"serial_novel": "writing",
|
|
17
|
-
"article": "writing",
|
|
18
|
-
"video_script": "writing",
|
|
19
|
-
"doc": "writing",
|
|
20
|
-
"translation": "writing",
|
|
21
|
-
"rank_scan": "reasoning",
|
|
22
|
-
"research": "reasoning",
|
|
23
|
-
"speech": "writing",
|
|
24
|
-
"presentation": "writing",
|
|
25
|
-
"weekly_report": "writing",
|
|
26
|
-
"email": "writing",
|
|
27
|
-
"tech_proposal": "reasoning",
|
|
28
|
-
"resume": "writing",
|
|
29
|
-
"bid_doc": "writing", # 标书:正文应答写作量大(合规判断由契约规则约束)
|
|
30
|
-
"defect_retro": "reasoning", # 禅道工单:排查定责推理向
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_KIND_AFFINITY = {
|
|
34
|
-
"coding": {"codex": 10, "aider": 8, "opencode": 7, "qwen": 6,
|
|
35
|
-
"claude": 5, "generic": 2},
|
|
36
|
-
"writing": {"claude": 10, "qwen": 7, "generic": 5, "codex": 3,
|
|
37
|
-
"opencode": 2, "aider": 0},
|
|
38
|
-
"reasoning": {"claude": 9, "codex": 8, "qwen": 6, "opencode": 4,
|
|
39
|
-
"generic": 3, "aider": 1},
|
|
40
|
-
"vision": {"codex": 10, "claude": 8, "qwen": 5, "opencode": 2,
|
|
41
|
-
"generic": 1, "aider": 0},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
_TIER_SCORE = {
|
|
45
|
-
"easy": {"budget": 18.0, "standard": 8.0, "premium": -6.0},
|
|
46
|
-
"default": {"budget": 2.0, "standard": 6.0, "premium": 5.0},
|
|
47
|
-
"hard": {"budget": -8.0, "standard": 4.0, "premium": 12.0},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def task_dimension(task_type, role=""):
|
|
52
|
-
"""把预置任务与步骤角色归一为 writing/coding/reasoning/vision。"""
|
|
53
|
-
ttype = str(task_type or "").strip().lower()
|
|
54
|
-
role = str(role or "").strip().lower()
|
|
55
|
-
if ttype in ("writing", "coding", "reasoning", "vision"):
|
|
56
|
-
return ttype
|
|
57
|
-
if role in ("plan", "review", "critique", "selector", "qa") \
|
|
58
|
-
or "review" in role or "critique" in role:
|
|
59
|
-
return "reasoning"
|
|
60
|
-
return TYPE_DIMENSIONS.get(ttype, "reasoning")
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def agent_affinity(kind, task_type, role=""):
|
|
64
|
-
"""CLI 类型对任务维度的温和偏好;只作加分,不覆盖健康与历史信号。"""
|
|
65
|
-
dim = task_dimension(task_type, role)
|
|
66
|
-
score = float((_KIND_AFFINITY.get(dim) or {}).get(kind, 0))
|
|
67
|
-
if role == "review" or "critique" in str(role or ""):
|
|
68
|
-
score += {"claude": 4, "codex": 3, "qwen": 2}.get(kind, 0)
|
|
69
|
-
return score, "%s 匹配 %+.1f" % (dim, score)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def _model_meta(provider, model):
|
|
73
|
-
for item in (provider or {}).get("models") or []:
|
|
74
|
-
if isinstance(item, dict) and item.get("name") == model:
|
|
75
|
-
return item
|
|
76
|
-
return {}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def _price_score(pricing, model, difficulty):
|
|
80
|
-
price = (pricing or {}).get(model) or {}
|
|
81
|
-
try:
|
|
82
|
-
# 输出通常比输入贵且更影响整步成本,按 2 倍权重估算。
|
|
83
|
-
blended = max(0.0, float(price.get("in") or 0.0)
|
|
84
|
-
+ 2.0 * float(price.get("out") or 0.0))
|
|
85
|
-
except (TypeError, ValueError):
|
|
86
|
-
return 0.0, "价格未知"
|
|
87
|
-
if blended <= 0:
|
|
88
|
-
return 0.0, "价格未知"
|
|
89
|
-
magnitude = max(0.0, math.log10(blended + 1.0))
|
|
90
|
-
score = -min(18.0, magnitude * (7.0 if difficulty == "easy" else 2.0))
|
|
91
|
-
return score, "估算价 %.3g(%+.1f)" % (blended, score)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def _online_model_bonus(entry, task_type, role):
|
|
95
|
-
"""把真实运行指标作为模型链软信号,硬约束仍由调用方负责。"""
|
|
96
|
-
try:
|
|
97
|
-
from . import usage
|
|
98
|
-
metrics = usage.routing_stats(
|
|
99
|
-
task_type=task_type, role=role,
|
|
100
|
-
provider=entry.get("provider_id") or "",
|
|
101
|
-
model=entry.get("model") or "")
|
|
102
|
-
samples = int(metrics.get("samples") or 0)
|
|
103
|
-
if not samples:
|
|
104
|
-
return 0.0, ""
|
|
105
|
-
rate = float(metrics.get("success_rate") or 0.0)
|
|
106
|
-
success_score = max(-6.0, min(6.0, (rate - 0.75) * 18.0))
|
|
107
|
-
p95 = max(0.0, float(metrics.get("p95_duration_s") or 0.0))
|
|
108
|
-
# 模型链也必须让真实延迟影响排序,不能让 P95 数分钟的链靠静态质量分
|
|
109
|
-
# 长期压在十几秒的健康链前面。
|
|
110
|
-
latency_score = -min(12.0, max(0.0, (p95 - 30.0) / 8.0))
|
|
111
|
-
cost = max(0.0, float(metrics.get("avg_cost_usd") or 0.0))
|
|
112
|
-
cost_score = -min(3.0, max(0.0, (cost - 0.01) / 0.01))
|
|
113
|
-
total = round(success_score + latency_score + cost_score, 2)
|
|
114
|
-
success_samples = int(metrics.get("success_samples") or samples)
|
|
115
|
-
reason = ("在线 %d/%d 验收成功(%+.1f),P95 %.1fs(%+.1f),均价 $%.4f(%+.1f)"
|
|
116
|
-
% (int(metrics.get("successes") or 0), success_samples,
|
|
117
|
-
success_score, p95, latency_score, cost, cost_score))
|
|
118
|
-
return total, reason
|
|
119
|
-
except Exception:
|
|
120
|
-
return 0.0, ""
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _bench_bonus(entry):
|
|
124
|
-
"""评测基准台实测分软信号(promptfoo 式样题榜单;14 天新鲜度,过期记 0)。
|
|
125
|
-
|
|
126
|
-
与在线信号同理念:软加减分,硬约束(健康/冷却/协议)仍由调用方负责;
|
|
127
|
-
无数据不猜分——没上过评测台的候选保持原排序。
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""统一调度评分:任务画像、CLI 亲和度与模型链排序。
|
|
3
|
+
|
|
4
|
+
调用方先完成协议、启停、健康、密钥等硬约束过滤,再把可用候选交给这里评分;
|
|
5
|
+
静态能力与近期用量台账只提供软信号,相同分数保持用户原顺序。
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
TYPE_DIMENSIONS = {
|
|
13
|
+
"direct": "reasoning",
|
|
14
|
+
"code": "coding",
|
|
15
|
+
"novel": "writing",
|
|
16
|
+
"serial_novel": "writing",
|
|
17
|
+
"article": "writing",
|
|
18
|
+
"video_script": "writing",
|
|
19
|
+
"doc": "writing",
|
|
20
|
+
"translation": "writing",
|
|
21
|
+
"rank_scan": "reasoning",
|
|
22
|
+
"research": "reasoning",
|
|
23
|
+
"speech": "writing",
|
|
24
|
+
"presentation": "writing",
|
|
25
|
+
"weekly_report": "writing",
|
|
26
|
+
"email": "writing",
|
|
27
|
+
"tech_proposal": "reasoning",
|
|
28
|
+
"resume": "writing",
|
|
29
|
+
"bid_doc": "writing", # 标书:正文应答写作量大(合规判断由契约规则约束)
|
|
30
|
+
"defect_retro": "reasoning", # 禅道工单:排查定责推理向
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_KIND_AFFINITY = {
|
|
34
|
+
"coding": {"codex": 10, "aider": 8, "opencode": 7, "qwen": 6,
|
|
35
|
+
"claude": 5, "generic": 2},
|
|
36
|
+
"writing": {"claude": 10, "qwen": 7, "generic": 5, "codex": 3,
|
|
37
|
+
"opencode": 2, "aider": 0},
|
|
38
|
+
"reasoning": {"claude": 9, "codex": 8, "qwen": 6, "opencode": 4,
|
|
39
|
+
"generic": 3, "aider": 1},
|
|
40
|
+
"vision": {"codex": 10, "claude": 8, "qwen": 5, "opencode": 2,
|
|
41
|
+
"generic": 1, "aider": 0},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_TIER_SCORE = {
|
|
45
|
+
"easy": {"budget": 18.0, "standard": 8.0, "premium": -6.0},
|
|
46
|
+
"default": {"budget": 2.0, "standard": 6.0, "premium": 5.0},
|
|
47
|
+
"hard": {"budget": -8.0, "standard": 4.0, "premium": 12.0},
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def task_dimension(task_type, role=""):
|
|
52
|
+
"""把预置任务与步骤角色归一为 writing/coding/reasoning/vision。"""
|
|
53
|
+
ttype = str(task_type or "").strip().lower()
|
|
54
|
+
role = str(role or "").strip().lower()
|
|
55
|
+
if ttype in ("writing", "coding", "reasoning", "vision"):
|
|
56
|
+
return ttype
|
|
57
|
+
if role in ("plan", "review", "critique", "selector", "qa") \
|
|
58
|
+
or "review" in role or "critique" in role:
|
|
59
|
+
return "reasoning"
|
|
60
|
+
return TYPE_DIMENSIONS.get(ttype, "reasoning")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def agent_affinity(kind, task_type, role=""):
|
|
64
|
+
"""CLI 类型对任务维度的温和偏好;只作加分,不覆盖健康与历史信号。"""
|
|
65
|
+
dim = task_dimension(task_type, role)
|
|
66
|
+
score = float((_KIND_AFFINITY.get(dim) or {}).get(kind, 0))
|
|
67
|
+
if role == "review" or "critique" in str(role or ""):
|
|
68
|
+
score += {"claude": 4, "codex": 3, "qwen": 2}.get(kind, 0)
|
|
69
|
+
return score, "%s 匹配 %+.1f" % (dim, score)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _model_meta(provider, model):
|
|
73
|
+
for item in (provider or {}).get("models") or []:
|
|
74
|
+
if isinstance(item, dict) and item.get("name") == model:
|
|
75
|
+
return item
|
|
76
|
+
return {}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _price_score(pricing, model, difficulty):
|
|
80
|
+
price = (pricing or {}).get(model) or {}
|
|
81
|
+
try:
|
|
82
|
+
# 输出通常比输入贵且更影响整步成本,按 2 倍权重估算。
|
|
83
|
+
blended = max(0.0, float(price.get("in") or 0.0)
|
|
84
|
+
+ 2.0 * float(price.get("out") or 0.0))
|
|
85
|
+
except (TypeError, ValueError):
|
|
86
|
+
return 0.0, "价格未知"
|
|
87
|
+
if blended <= 0:
|
|
88
|
+
return 0.0, "价格未知"
|
|
89
|
+
magnitude = max(0.0, math.log10(blended + 1.0))
|
|
90
|
+
score = -min(18.0, magnitude * (7.0 if difficulty == "easy" else 2.0))
|
|
91
|
+
return score, "估算价 %.3g(%+.1f)" % (blended, score)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _online_model_bonus(entry, task_type, role):
|
|
95
|
+
"""把真实运行指标作为模型链软信号,硬约束仍由调用方负责。"""
|
|
96
|
+
try:
|
|
97
|
+
from . import usage
|
|
98
|
+
metrics = usage.routing_stats(
|
|
99
|
+
task_type=task_type, role=role,
|
|
100
|
+
provider=entry.get("provider_id") or "",
|
|
101
|
+
model=entry.get("model") or "")
|
|
102
|
+
samples = int(metrics.get("samples") or 0)
|
|
103
|
+
if not samples:
|
|
104
|
+
return 0.0, ""
|
|
105
|
+
rate = float(metrics.get("success_rate") or 0.0)
|
|
106
|
+
success_score = max(-6.0, min(6.0, (rate - 0.75) * 18.0))
|
|
107
|
+
p95 = max(0.0, float(metrics.get("p95_duration_s") or 0.0))
|
|
108
|
+
# 模型链也必须让真实延迟影响排序,不能让 P95 数分钟的链靠静态质量分
|
|
109
|
+
# 长期压在十几秒的健康链前面。
|
|
110
|
+
latency_score = -min(12.0, max(0.0, (p95 - 30.0) / 8.0))
|
|
111
|
+
cost = max(0.0, float(metrics.get("avg_cost_usd") or 0.0))
|
|
112
|
+
cost_score = -min(3.0, max(0.0, (cost - 0.01) / 0.01))
|
|
113
|
+
total = round(success_score + latency_score + cost_score, 2)
|
|
114
|
+
success_samples = int(metrics.get("success_samples") or samples)
|
|
115
|
+
reason = ("在线 %d/%d 验收成功(%+.1f),P95 %.1fs(%+.1f),均价 $%.4f(%+.1f)"
|
|
116
|
+
% (int(metrics.get("successes") or 0), success_samples,
|
|
117
|
+
success_score, p95, latency_score, cost, cost_score))
|
|
118
|
+
return total, reason
|
|
119
|
+
except Exception:
|
|
120
|
+
return 0.0, ""
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _bench_bonus(entry):
|
|
124
|
+
"""评测基准台实测分软信号(promptfoo 式样题榜单;14 天新鲜度,过期记 0)。
|
|
125
|
+
|
|
126
|
+
与在线信号同理念:软加减分,硬约束(健康/冷却/协议)仍由调用方负责;
|
|
127
|
+
无数据不猜分——没上过评测台的候选保持原排序。
|
|
128
|
+
settings.bench_feedback_enabled=False 时整路关闭(纯榜单展示,不影响选路)。
|
|
129
|
+
"""
|
|
130
|
+
try:
|
|
131
|
+
from . import settings as settings_mod
|
|
132
|
+
if settings_mod.load().get("bench_feedback_enabled", True) is False:
|
|
133
|
+
return 0.0, ""
|
|
134
|
+
except Exception:
|
|
135
|
+
pass
|
|
136
|
+
try:
|
|
137
|
+
from . import benchstore
|
|
138
|
+
return benchstore.bonus_for(entry.get("provider_id") or "",
|
|
139
|
+
entry.get("model") or "")
|
|
140
|
+
except Exception:
|
|
141
|
+
return 0.0, ""
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def score_model_entry(entry, providers, pricing, difficulty, task_type="", role=""):
|
|
145
|
+
"""给已通过硬约束的模型链条目评分,返回 (score, explanation)。"""
|
|
146
|
+
provider = (providers or {}).get(entry.get("provider_id")) \
|
|
147
|
+
or entry.get("provider") or {}
|
|
148
|
+
model = entry.get("model") or ""
|
|
149
|
+
meta = _model_meta(provider, model)
|
|
150
|
+
try:
|
|
151
|
+
priority = max(1, int(meta.get("priority") or 99))
|
|
152
|
+
except (TypeError, ValueError):
|
|
153
|
+
priority = 99
|
|
154
|
+
quality = 0.0 if priority == 99 else max(-8.0, 20.0 - (priority - 1) * 4.0)
|
|
155
|
+
tier = meta.get("tier") or provider.get("tier") or "standard"
|
|
156
|
+
tier_score = (_TIER_SCORE.get(difficulty) or {}).get(tier, 0.0)
|
|
157
|
+
price_score, price_reason = _price_score(pricing, model, difficulty)
|
|
158
|
+
dim = task_dimension(task_type, role)
|
|
159
|
+
strengths = provider.get("strengths") if isinstance(provider.get("strengths"), list) else []
|
|
160
|
+
strength_score = 10.0 if dim in strengths else 0.0
|
|
161
|
+
if difficulty == "easy":
|
|
162
|
+
quality *= 0.25
|
|
163
|
+
elif difficulty != "hard":
|
|
164
|
+
# 普通任务兼顾质量、成本与能力匹配;是否真的重排由调用方决定,
|
|
165
|
+
# 因而手工链仍可保持原顺序,自动推荐则能使用这组平衡分。
|
|
166
|
+
quality *= 0.65
|
|
167
|
+
vision_score = 0.0
|
|
168
|
+
if dim == "vision":
|
|
169
|
+
vision_score = 24.0 if meta.get("image_in") else -24.0
|
|
170
|
+
online_score, online_reason = _online_model_bonus(entry, task_type, role)
|
|
171
|
+
bench_score, bench_reason = _bench_bonus(entry)
|
|
172
|
+
total = (quality + tier_score + price_score + strength_score + vision_score
|
|
173
|
+
+ online_score + bench_score)
|
|
174
|
+
reason = ("质量 %+.1f,档位 %s %+.1f,%s,能力 %s %+.1f%s%s%s%s"
|
|
175
|
+
% (quality, tier, tier_score, price_reason, dim,
|
|
176
|
+
strength_score + vision_score,
|
|
177
|
+
"," if online_reason else "", online_reason,
|
|
178
|
+
"," if bench_reason else "", bench_reason))
|
|
179
|
+
return round(total, 2), reason
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def rank_model_entries(entries, providers, pricing, difficulty,
|
|
183
|
+
task_type="", role="", force=False):
|
|
184
|
+
"""稳定排序模型链并返回脱敏决策明细;default 难度保持人工顺序。"""
|
|
185
|
+
rows = []
|
|
186
|
+
for index, entry in enumerate(entries or []):
|
|
187
|
+
score, reason = score_model_entry(
|
|
188
|
+
entry, providers, pricing, difficulty, task_type, role)
|
|
189
|
+
rows.append((score, index, entry, reason))
|
|
190
|
+
if difficulty in ("easy", "hard") or force:
|
|
191
|
+
rows.sort(key=lambda row: (-row[0], row[1]))
|
|
192
|
+
ranked = [row[2] for row in rows]
|
|
193
|
+
decisions = [{"provider_id": row[2].get("provider_id") or "",
|
|
194
|
+
"provider": (row[2].get("provider") or {}).get("name") or "",
|
|
195
|
+
"model": row[2].get("model") or "",
|
|
196
|
+
"score": row[0], "reason": row[3]}
|
|
197
|
+
for row in rows]
|
|
198
|
+
return ranked, decisions
|