基础设施

tiershift

@iamvatsalpatel2TypeScriptMIT更新于 2026-09-18可当场跑

将每次 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.

iamvatsalpatel/tiershift

它在哪儿调用了 Jev

import { TypeSafeClient } from "@typesafe-ai/sdk";

src/router.ts:2

链接指向我们抓取当天的那个 commit,行号是准的。

它问 Jev 的问题

下面是从这个项目源码里原样取出来的 question 组合。

取自 python/tiershift/signals.py:17

  1. difficulty打分

    How hard is it to answer `request.user_message` well? Consider `request.system_prompt` and `request.step` for context.

    • 0trivial: a lookup, a formatting change, an acknowledgement, or a one-line reply
    • 1moderate: needs domain knowledge or a few reasoning steps; a competent generalist can do it
    • 2hard: needs deep expertise, long multi-step reasoning, careful trade-off analysis, or novel design
  2. needs_reasoning是/否

    Does `request.user_message` require multi-step logical reasoning, proof, debugging, or planning rather than recall, rewriting, or formatting?

  3. stakes打分

    How costly is a wrong or low-quality answer to `request.user_message` for the user?

    • 0low: easy to spot and redo; no external consequence
    • 1medium: wastes real time or money if wrong; affects work product
    • 2high: legal, financial, medical, safety, security, or production-system impact
  4. domain选项

    Which domain does `request.user_message` belong to?

    • codewriting, debugging, reviewing, or explaining software
    • math_logicmathematics, proofs, formal logic, puzzles
    • writingprose, tone, editing, summarizing, translation
    • architecturesystem design, infrastructure, migrations, planning
    • legal_financecontracts, compliance, money, tax
    • datadata analysis, SQL, spreadsheets, statistics
    • generalgeneral knowledge, conversation, simple questions
  5. has_code是/否

    Does `request.user_message` contain code or ask for code to be written, fixed, or reviewed?

  6. ambiguous是/否

    Is `request.user_message` missing information that an expert would need before answering well?

  7. output_length打分

    How long should a good answer to `request.user_message` be?

    • 0one line or a single value
    • 1one to three paragraphs or a short code snippet
    • 2a long document, a detailed plan, or multi-file code
  8. creative是/否

    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

  1. addresses是/否

    question

用你自己的内容跑一遍

代码
import { experimental_evaluate as evaluate } from 'ai';

const { answers } = await evaluate({
  model: 'typesafe-ai/jev',
  state,
  questions: {
    addresses: { type: 'boolean', instructions: 'question' },
  },
});

取自 src/signals.ts:132

  1. 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`?' },
  },
});

同类的其他项目