JEV DEVELOPER GUIDE / 连续教程

Jev 开发指南:核心概念、SDK 与学习路径

先用一篇紧凑指南理解 Jev 的类型化决策与调用流程,再选择 Python SDK、TypeScript SDK 或 LangChain 专题,完成可测试的实现。

约 25 分钟 入门 → 可运行代码 更新于 2026-10-26
STATE→QUESTION→JEV→ANSWER→POLICY
教程大纲
  1. 01核心概念
  2. 02实现原理
  3. 03代码实战
  4. 04官方 SDK
  5. 05LangChain
01
核心概念

Jev 是一个类型化判断模型

Jev 不负责续写文本。它接收一份状态(state)和一组边界明确的问题,然后返回可以被程序读取的 Choice、Score 或 Noul。适合它的任务通常答案空间已知,但无法只靠 if/else 从原始输入中精确判断。

Choice

从命名选项中选择一个,例如把工单路由到 billing、technical 或 human。

Score

落在有序等级上,例如 calm → frustrated → angry。

Noul

估计一个命题为真的概率,例如“该请求是否紧急”。

02
实现原理

判断和执行必须分开

一次可靠调用有五个层次。业务先整理证据,再声明问题;Jev 返回概率化答案;应用策略检查结构、阈值和风险;最后才允许代码执行动作。模型没有退款、删库或发布内容的权限。

  1. 1
    State

    只保留会影响当前判断的证据,字段名、单位和来源要清晰。

  2. 2
    Question

    用 Choice、Score 或 Noul 声明答案形状与判断标准。

  3. 3
    Typed answer

    读取胜出项、完整分布或 P(true),不要把结果当自然语言。

  4. 4
    Policy

    校验选项、置信度、业务风险和是否需要人工复核。

  5. 5
    Action

    由业务代码执行,并记录问题版本、模型版本和最终动作。

03
代码实战

贯穿全文的工单路由案例

假设输入是一条客户消息。我们需要判断应该交给哪个团队,并判断是否紧急。路由是 Choice,紧急性是 Noul;真正的派单动作仍由程序决定。

INPUT / STATE
{
  "message": "Stripe has failed for three days. Help ASAP.",
  "account_tier": "enterprise"
}
OUTPUT / CONTRACT
route   → billing | technical | human
urgent  → P(true)
policy  → automate | review

这个拆分很重要:模型只回答两个小问题,业务策略再组合答案。以后增加 SLA、VIP 客户或高风险词规则时,不需要把隐藏策略塞进一段超长提示词。

04
官方 SDK

用 Python 完成第一次 Jev 调用

官方 Python 客户端是 typesafe-sdk。密钥只放在服务端环境变量中,先从一个可撤销、容易人工核对的任务开始。

python -m pip install "typesafe-sdk==0.7.2" "truststore>=0.10.5"export TYPESAFE_API_KEY="your-api-key"
from typesafe_sdk import Choice, Noul, TypeSafeClient

questions = {
    "route": Choice(
        instructions="Which team should handle this request?",
        criteria={
            "billing": "Payments or subscriptions",
            "technical": "Bugs or integrations",
            "human": "Ambiguous or sensitive cases",
        },
    ),
    "urgent": Noul(
        instructions="Does this message express urgency?"
    ),
}

with TypeSafeClient() as client:
    result = client.system_one(
        state={
            "message": "Stripe has failed for three days. Help ASAP.",
            "account_tier": "enterprise",
        },
        questions=questions,
    )

route = result.answers["route"]
urgent = result.answers["urgent"]

import math

# Demonstration threshold, not a calibrated production policy.
confidence = route.confidence
valid = (
    route.choice in {"billing", "technical", "human"}
    and isinstance(confidence, (int, float))
    and not isinstance(confidence, bool)
    and math.isfinite(confidence)
    and 0 <= confidence <= 1
)
if not valid or route.choice == "human" or confidence < 0.75:
    print("Human review required")
else:
    print("Suggested team:", route.choice)  # No real ticket is changed.

print(route.probabilities, urgent.noul)
上线前校验

选项键是否存在、questions 是否非空、响应结构是否完整。

风险策略

低置信度转人工;不可逆动作不因高分自动获得权限。

可复现日志

记录模型、问题版本、分布、阈值与最终动作。

05
LANGCHAIN

把同一决策契约接入 Runnable

LangChain 的官方 TypeSafe 集成把 TypeSafeClassifier 实现为 Runnable。state 和 questions 都随每次 invoke 传入,因此可以进入批处理、异步调用、回调和追踪链路。

uv add langchain-typesafe==0.0.1a3 langchain-core==1.6.6 typesafe-sdk==0.7.2 "truststore>=0.10.5"export TYPESAFE_API_KEY="your-api-key"
from math import isfinite
from langchain_typesafe import Choice, Noul, Score, TypeSafeClassifier


def classify_ticket(classifier):
    questions = {
        "route": Choice(instructions="Which team owns this incident?", criteria={
            "technical": "Bugs or integrations", "billing": "Invoices", "human": "Unclear ownership"}),
        "severity": Score(instructions="How blocked are customers?", criteria=[
            "Unaffected", "Workaround available", "Core workflow blocked"]),
        "urgent": Noul(instructions="Does the message describe an ongoing service disruption?"),
    }
    if not questions:
        raise ValueError("At least one question is required")
    response = classifier.invoke({
        "state": {"message": "Checkout fails for every customer.", "scope": "all customers"},
        "questions": questions,
    })
    route = response.choices["route"]
    valid = route.choice in {"technical", "billing", "human"} and isfinite(route.confidence) and 0 <= route.confidence <= 1
    # Teaching threshold only; calibrate with your independently labeled outcomes.
    return {"action": "review" if not valid or route.choice == "human" or route.confidence < 0.75 else "suggest",
            "team": route.choice, "severity": response.scores["severity"].score,
            "urgent_probability": response.nouls["urgent"].noul}


if __name__ == "__main__":
    try:
        print(classify_ticket(TypeSafeClassifier(model="jev-1.13.0", timeout=2)))
    except Exception:
        print({"action": "review", "reason": "provider_or_configuration_failure"})
下载完整 LangChain 示例
LANGCHAIN

编排、批处理、回调与追踪

JEV

封闭问题的概率化判断

YOUR CODE

阈值、权限、人工复核与副作用

继续深入

现在按问题继续查阅