结构化评估(Jev)
结构化评估(Jev)
Jev 会根据 JSON 状态回答具名问题,并返回 boolean、choice 或 score 类型的答案;适用于把明确的判断标准转换为程序可读取的评估结果。
仅用于评估与判断
Jev 不支持聊天。请将 Jev 请求发送到 POST /v1/evaluations;若发送到 POST /v1/chat/completions,会收到 HTTP 400。
POST/v1/evaluations
使用 BazaarLink API 密钥调用以下接口。完整网址为 https://api.bazaarlink.ai/v1/evaluations。
字段说明
model
string
选填。省略时默认为 typesafe-ai/jev;其他模型标识会返回 HTTP 400,错误代码为 model_not_available。
state
string | object | array
必填,须为 JSON 字符串、对象或数组,作为待评估的状态数据。序列化后的 state 与 questions 合计超过 32,000 tokens 时,会返回 context_length_exceeded。
questions
record<string, Question>
必填,且至少包含一个具名问题。每个问题名称都会成为响应 answers 对象中的键。
type
boolean | choice | score
每个问题都必填;可选 boolean、choice 或 score。
instructions
string | object | array
每个问题都必填;可以是描述判断内容的 JSON 字符串、对象或数组。
criteria
object | array
根据 type 决定:boolean 可省略,若提供则为键名只能是 true 或 false 的对象;choice 必须是非空对象;score 必须是至少含两项且顺序有意义的数组。
答案类型
boolean — criteria 可以省略;如果提供,只接受 true 和 false 作为键。boolean 答案包含数值型 probability。choice — criteria 必须是非空对象,将选项名称映射到 JSON criteria。答案包含字符串 choice;probabilities 以选项名称为键。score — criteria 必须是至少包含两项的有序数组。答案包含数值 score;score 是按 criteria 数组顺序计算的索引 0..N-1 的期望值;probabilities 以相同索引的字符串形式为键。
请求示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
curl --fail-with-body https://api.bazaarlink.ai/v1/evaluations \
-H "Authorization: Bearer $BAZAARLINK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "typesafe-ai/jev",
"state": "The support agent issued a full refund and apologised for the delay.",
"questions": {
"refunded": {
"type": "boolean",
"instructions": "Was a refund issued?"
},
"tone": {
"type": "choice",
"instructions": "Tone of the agent?",
"criteria": {
"apologetic": "The agent apologises",
"neutral": "No emotional language",
"hostile": "The agent is rude"
}
},
"quality": {
"type": "score",
"instructions": "How complete was the resolution?",
"criteria": [
"poor",
"partial",
"complete"
]
}
}
}'
成功响应示例
示例响应包含 id、object、model、answers、usage、rounding 和 warnings。answers 以问题名称为键。usage 包含 input_tokens、output_tokens 和 total_tokens;rounding 显示 probabilityDecimals 和 scoreDecimals。warnings 是数组,本例为空。answers 中 choice 的 probabilities 以选项名称为键,score 的 probabilities 则以 criteria 项目的索引字符串为键。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
"id": "eval-a3d350e5-2705-4a9b-be7c-838fa4e4eb2b",
"object": "evaluation",
"model": "typesafe-ai/jev",
"answers": {
"refunded": {
"type": "boolean",
"probability": 0.99
},
"tone": {
"type": "choice",
"choice": "apologetic",
"probabilities": {
"apologetic": 1,
"neutral": 0,
"hostile": 0
}
},
"quality": {
"type": "score",
"score": 1.98,
"probabilities": {
"0": 0,
"1": 0.02,
"2": 0.98
}
}
},
"usage": {
"input_tokens": 394,
"output_tokens": 74,
"total_tokens": 468
},
"rounding": {
"probabilityDecimals": 2,
"scoreDecimals": 2
},
"warnings": []
}
聊天接口的错误响应
将 Jev 发送到聊天接口会收到 HTTP 400。以下字段和值与接口处理程序一致;message 使用占位文字,实际内容由服务器提供。
{
"error": {
"message": "<server-generated message>",
"type": "invalid_request_error",
"code": 400
}
}