基础设施
将每次 LLM 调用转到能处理的最便宜模型,路由由 TypeSafe Jev 约 180 毫秒内决定,无需训练数据,策略用 YAML 编写,支持 TypeScript 和 Python。
Shift every LLM call to the cheapest model that can handle it. Routing decided by TypeSafe Jev in ~180 ms. No training data. Policy in plain YAML. TypeScript and Python.
import { TypeSafeClient } from "@typesafe-ai/sdk";链接指向我们抓取当天的那个 commit,行号是准的。
下面是从这个项目源码里原样取出来的 question 组合。
取自 python/tiershift/signals.py:17
difficulty打分How hard is it to answer `request.user_message` well? Consider `request.system_prompt` and `request.step` for context.
0 — trivial: a lookup, a formatting change, an acknowledgement, or a one-line reply1 — moderate: needs domain knowledge or a few reasoning steps; a competent generalist can do it2 — hard: needs deep expertise, long multi-step reasoning, careful trade-off analysis, or novel designneeds_reasoning是/否Does `request.user_message` require multi-step logical reasoning, proof, debugging, or planning rather than recall, rewriting, or formatting?
stakes打分How costly is a wrong or low-quality answer to `request.user_message` for the user?
0 — low: easy to spot and redo; no external consequence1 — medium: wastes real time or money if wrong; affects work product2 — high: legal, financial, medical, safety, security, or production-system impactdomain选项Which domain does `request.user_message` belong to?
code — writing, debugging, reviewing, or explaining softwaremath_logic — mathematics, proofs, formal logic, puzzleswriting — prose, tone, editing, summarizing, translationarchitecture — system design, infrastructure, migrations, planninglegal_finance — contracts, compliance, money, taxdata — data analysis, SQL, spreadsheets, statisticsgeneral — general knowledge, conversation, simple questionshas_code是/否Does `request.user_message` contain code or ask for code to be written, fixed, or reviewed?
ambiguous是/否Is `request.user_message` missing information that an expert would need before answering well?
output_length打分How long should a good answer to `request.user_message` be?
0 — one line or a single value1 — one to three paragraphs or a short code snippet2 — a long document, a detailed plan, or multi-file codecreative是/否Does `request.user_message` ask for creative or stylistic writing rather than factual or technical output?
import { experimental_evaluate as evaluate } from 'ai';
const { answers } = await evaluate({
model: 'typesafe-ai/jev',
state,
questions: {
difficulty: { type: 'score', instructions: 'How hard is it to answer `request.user_message` well? Consider `request.system_prompt` and `request.step` for context.',
criteria: ['trivial: a lookup, a formatting change, an acknowledgement, or a one-line reply', 'moderate: needs domain knowledge or a few reasoning steps; a competent generalist can do it', 'hard: needs deep expertise, long multi-step reasoning, careful trade-off analysis, or novel design'] },
needs_reasoning: { type: 'boolean', instructions: 'Does `request.user_message` require multi-step logical reasoning, proof, debugging, or planning rather than recall, rewriting, or formatting?' },
stakes: { type: 'score', instructions: 'How costly is a wrong or low-quality answer to `request.user_message` for the user?',
criteria: ['low: easy to spot and redo; no external consequence', 'medium: wastes real time or money if wrong; affects work product', 'high: legal, financial, medical, safety, security, or production-system impact'] },
domain: { type: 'choice', instructions: 'Which domain does `request.user_message` belong to?',
criteria: { code: 'writing, debugging, reviewing, or explaining software', math_logic: 'mathematics, proofs, formal logic, puzzles', writing: 'prose, tone, editing, summarizing, translation', architecture: 'system design, infrastructure, migrations, planning', legal_finance: 'contracts, compliance, money, tax', data: 'data analysis, SQL, spreadsheets, statistics', general: 'general knowledge, conversation, simple questions' } },
has_code: { type: 'boolean', instructions: 'Does `request.user_message` contain code or ask for code to be written, fixed, or reviewed?' },
ambiguous: { type: 'boolean', instructions: 'Is `request.user_message` missing information that an expert would need before answering well?' },
output_length: { type: 'score', instructions: 'How long should a good answer to `request.user_message` be?',
criteria: ['one line or a single value', 'one to three paragraphs or a short code snippet', 'a long document, a detailed plan, or multi-file code'] },
creative: { type: 'boolean', instructions: 'Does `request.user_message` ask for creative or stylistic writing rather than factual or technical output?' },
},
});取自 python/tiershift/signals.py:154
addresses是/否question
import { experimental_evaluate as evaluate } from 'ai';
const { answers } = await evaluate({
model: 'typesafe-ai/jev',
state,
questions: {
addresses: { type: 'boolean', instructions: 'question' },
},
});addresses是/否Does `answer` fully and correctly address `request`?
import { experimental_evaluate as evaluate } from 'ai';
const { answers } = await evaluate({
model: 'typesafe-ai/jev',
state,
questions: {
addresses: { type: 'boolean', instructions: 'Does `answer` fully and correctly address `request`?' },
},
});