实际应答的模型版本,例如 xiangxin-1.0.0(即使请求里写的是别名 xiangxin-latest)。
答案与响应
所有响应与答案模型都是不可变(frozen)的 pydantic v2 模型,会忽略未知字段,可以用 .model_dump() 转成字典、用 .model_dump_json() 转成 JSON。HTTP 层面的响应格式见 API 参考 · 答案类型。
响应
xiangxin.SystemOneResponse
pydantic 模型
system_one() 的返回值:按问题名索引的答案,以及实际模型和用量信息。原理见系统一。
配置:extra="ignore"、frozen=True
字段
modelstr必填answersdict[str, Answer]必填全部答案,键为问题名。无法识别类型的答案会被跳过,并记录一条警告。
usageUsage本次请求的 token 用量;响应中缺失时为全 None 的 Usage。
nouls
属性
nouls: dict[str, NoulAnswer]按问题名索引的是非题答案。
choices
属性
choices: dict[str, ChoiceAnswer]按问题名索引的单选题答案。
scores
属性
scores: dict[str, ScoreAnswer]按问题名索引的打分题答案。
__getitem__
resp[name] -> NoulAnswer | ChoiceAnswer | ScoreAnswerresp.answers[name] 的简写。
request_id
属性
request_id: str | None响应头 x-request-id。联系技术支持时请附上。
model_ms
属性
model_ms: float | None响应头 x-xiangxin-model-ms:模型推理耗时(毫秒)。
total_ms
属性
total_ms: float | None响应头 x-xiangxin-total-ms:网关总耗时(毫秒)。
raw_http_response
属性
raw_http_response: httpx.Response | None底层的 httpx.Response,可读取状态码、全部响应头和原始 JSON。
带类型的子类
继承 SystemOneResponse 并声明与问题同名的字段,再通过 system_one(..., response_model=...) 传入,即可按属性访问答案。这些字段会自动从 answers 中填充:
from xiangxin import ChoiceAnswer, NoulAnswer, SystemOneResponse
class TicketResult(SystemOneResponse):
is_urgent: NoulAnswer
department: ChoiceAnswer
r = client.system_one(state, questions, response_model=TicketResult)
print(r.is_urgent.noul, r.department.choice)xiangxin.Usage
pydantic 模型
本次请求的 token 用量(以 API 报告为准)。
配置:extra="ignore"、frozen=True
字段
input_tokensint | None默认 None输入 token 数,是计费依据,见定价;API 未报告时为 None。
output_tokensint | None默认 None输出 token 数,不计费;API 未报告时为 None。
答案
每个答案都带有与问题一致的 type 字段,SDK 据此解析成对应的类。什么时候看 confidence、什么时候直接用概率,见置信度。
xiangxin.NoulAnswer
pydantic 模型
是非题的答案。详见 Noul 原语。
字段
noulfloat必填回答为“是”、或陈述成立的概率,0–1。接近 1 倾向“是”,接近 0 倾向“否”,0.5 附近表示不确定。Noul 答案没有单独的 confidence。
typeLiteral['noul']默认 'noul'xiangxin.ChoiceAnswer
pydantic 模型
所选的选项及各选项的概率。详见 Choice 原语。
字段
choicestr必填问题 criteria 中概率最高的选项名。
confidencefloat必填对所选选项的置信度,0–1。越高越确定;可以把低置信度的样本转人工复核。
probabilitiesdict[str, float]必填每个选项的概率,键为选项名,0–1,总和约为 1。可以看出其他选项有多接近。
typeLiteral['choice']默认 'choice'xiangxin.ScoreAnswer
pydantic 模型
期望分数,以及量表和各档概率。详见 Score 原语。
字段
scorefloat必填期望分数,即各档分数按概率加权的平均值 Σ i·pᵢ,可能落在两个整数档之间。
confidencefloat必填对分数的置信度,0–1,即最可能那一档的概率。可以把低置信度的评分转人工复核。
legenddict[int, Any]整数分数 → 该档描述。
probabilitiesdict[int, float]必填整数分数 → 概率。
typeLiteral['score']默认 'score'说明
HTTP 响应里 legend 和 probabilities 的键是字符串 "0"、"1"……,SDK 解析时会转换成整数,所以请写 ans.probabilities[2],而不是 ans.probabilities["2"]。
ans = resp.scores["severity"]
print(ans.score) # 期望分数,可能落在两档之间
print(ans.probabilities[1]) # 第 1 档的概率
print(ans.legend[round(ans.score)]) # 最接近的那一档的描述xiangxin.Answer
类型别名
Answer: TypeAlias = Annotated[NoulAnswer | ChoiceAnswer | ScoreAnswer, Field(discriminator="type")]单个问题的答案,按 type 区分。
可用模型
xiangxin.ListModelsResponse
pydantic 模型
client.models.list() 的返回值:当前账号可用的模型。
配置:extra="ignore"、frozen=True
字段
modelslist[ModelInfo]必填可用模型列表。
同样提供 request_id 与 raw_http_response 属性。
xiangxin.ModelInfo
pydantic 模型
单个可用模型的元数据。
字段
namestr必填可以填进请求 model 字段的名称或别名,例如 xiangxin-latest、xiangxin-1.0.0。
descriptionstr默认 ''模型及其能力的说明。
release_datestr | None默认 None发布日期,格式 YYYY-MM-DD。
基类与原始响应
xiangxin.XiangxinResponse
pydantic 模型
所有 SDK 响应模型的基类,携带底层 HTTP 响应,提供 request_id 与 raw_http_response 两个属性。一般不需要直接使用。
xiangxin.RawResponse
RawResponse[T]with_raw_response 的返回值:在解析之前先拿到 HTTP 层面的信息。
| 成员 | 类型 | 说明 |
|---|---|---|
http_response | httpx.Response | 底层 HTTP 响应。 |
status_code | int | HTTP 状态码。 |
headers | httpx.Headers | 全部响应头。 |
request_id | str | None | 响应头 x-request-id。 |
json() | Any | 未经解析的 JSON 响应体。 |
parse() | T | 解析为带类型的响应模型(结果会缓存);结构不符时抛出 APIResponseValidationError。 |

