TS TypeSafe 文档中文版 原文 ↗

答案与响应

读取 TypeSafe API 返回的答案、置信度分数、token 用量与可用模型。

响应

typesafe_sdk.SystemOneResponse

pydantic-model

基类:Response

按问题类型分组的答案,附带模型与用量元数据。

详见 System One。

注意

显示 JSON schema:

详情
json
{
  "$defs": {
    "ChoiceAnswer": {
      "description": "A selected label and its probabilities.\n\nSee the [choice primitive](https://docs.typesafe.ai/primitives/choice) for details.",
      "properties": {
        "type": {
          "const": "choice",
          "default": "choice",
          "title": "Type",
          "type": "string"
        },
        "choice": {
          "description": "The name of the choice with the highest probability among the question's criteria.",
          "examples": [
            "angry"
          ],
          "title": "Choice",
          "type": "string"
        },
        "confidence": {
          "description": "Confidence in the selected choice, from 0 to 1. Higher values indicate greater certainty; use lower values to flag uncertain selections for review.",
          "examples": [
            0.9
          ],
          "title": "Confidence",
          "type": "number"
        },
        "probabilities": {
          "additionalProperties": {
            "type": "number"
          },
          "description": "Probability of each choice in criteria, keyed by choice name, from 0 to 1. Shows how likely the alternatives are; values sum to approximately 1.",
          "examples": [
            {
              "angry": 0.8,
              "calm": 0.1,
              "excited": 0.1
            }
          ],
          "title": "Probabilities",
          "type": "object"
        }
      },
      "required": [
        "choice",
        "confidence",
        "probabilities"
      ],
      "title": "ChoiceAnswer",
      "type": "object"
    },
    "NoulAnswer": {
      "description": "A yes/no answer.\n\nSee the [noul primitive](https://docs.typesafe.ai/primitives/noul) for details.",
      "properties": {
        "type": {
          "const": "noul",
          "default": "noul",
          "title": "Type",
          "type": "string"
        },
        "noul": {
          "description": "Probability of a yes answer or a true statement, from 0 to 1. Values near 1 favor yes or true, values near 0 favor no or false, and values near 0.5 indicate uncertainty.",
          "examples": [
            0.98
          ],
          "title": "Noul",
          "type": "number"
        }
      },
      "required": [
        "noul"
      ],
      "title": "NoulAnswer",
      "type": "object"
    },
    "ScoreAnswer": {
      "description": "An expected score with its rubric and probabilities.\n\nSee the [score primitive](https://docs.typesafe.ai/primitives/score) for details.",
      "properties": {
        "type": {
          "const": "score",
          "default": "score",
          "title": "Type",
          "type": "string"
        },
        "score": {
          "description": "Expected score: the probability-weighted average of the rubric levels. May fall between integer levels.",
          "examples": [
            1.7
          ],
          "title": "Score",
          "type": "number"
        },
        "confidence": {
          "description": "Confidence in the score, from 0 to 1. Higher values indicate greater certainty; use lower values to flag uncertain ratings for review.",
          "examples": [
            0.9
          ],
          "title": "Confidence",
          "type": "number"
        },
        "legend": {
          "additionalProperties": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "items": {},
                "type": "array"
              }
            ]
          },
          "title": "Legend",
          "type": "object"
        },
        "probabilities": {
          "additionalProperties": {
            "type": "number"
          },
          "title": "Probabilities",
          "type": "object"
        }
      },
      "required": [
        "score",
        "confidence",
        "legend",
        "probabilities"
      ],
      "title": "ScoreAnswer",
      "type": "object"
    },
    "Usage": {
      "description": "Token counts for a request, when reported by the API.",
      "properties": {
        "input_tokens": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Input Tokens"
        },
        "output_tokens": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Output Tokens"
        }
      },
      "title": "Usage",
      "type": "object"
    }
  },
  "description": "Answers grouped by question type with model and usage metadata.\n\nSee [System One](https://docs.typesafe.ai/concepts/system-one) for details.",
  "properties": {
    "model": {
      "title": "Model",
      "type": "string"
    },
    "usage": {
      "$ref": "#/$defs/Usage"
    },
    "answers": {
      "additionalProperties": {
        "discriminator": {
          "mapping": {
            "choice": "#/$defs/ChoiceAnswer",
            "noul": "#/$defs/NoulAnswer",
            "score": "#/$defs/ScoreAnswer"
          },
          "propertyName": "type"
        },
        "oneOf": [
          {
            "$ref": "#/$defs/NoulAnswer"
          },
          {
            "$ref": "#/$defs/ChoiceAnswer"
          },
          {
            "$ref": "#/$defs/ScoreAnswer"
          }
        ]
      },
      "title": "Answers",
      "type": "object"
    }
  },
  "required": [
    "model",
    "usage"
  ],
  "title": "SystemOneResponse",
  "type": "object"
}
 

配置:

  • extra:ignore
  • frozen:True
  • strict:True

字段:

request_id

cached property

x-typesafe-request-id 响应头。

raw_http_response

property

python
raw_http_response: httpx2.Response
 

底层的 httpx2.Response,暴露状态、响应头与响应体。

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

model

pydantic-field

用于回答该请求的模型。

usage

pydantic-field

该请求的 token 用量。

answers

pydantic-field

以问题名称作为键的所有答案对象。

nouls

cached property

以问题名称作为键的是/否答案。

choices

cached property

以问题名称作为键的 Choice 答案。

scores

cached property

以问题名称作为键的 Score 答案。

typesafe_sdk.Usage

pydantic-model

基类:wire.Usage

请求的 token 计数,在 API 报告时提供。

注意

显示 JSON schema:

详情
json
{
  "description": "Token counts for a request, when reported by the API.",
  "properties": {
    "input_tokens": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Input Tokens"
    },
    "output_tokens": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Output Tokens"
    }
  },
  "title": "Usage",
  "type": "object"
}
 

配置:

  • extra:ignore
  • frozen:True
  • strict:True

字段:

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

input_tokens

pydantic-field

使用的输入 token 数量;若 API 未报告,则为 None。

output_tokens

pydantic-field

使用的输出 token 数量;若 API 未报告,则为 None。

答案

typesafe_sdk.NoulAnswer

pydantic-model

基类:wire.NoulAnswer

一个是/否答案。

详见 noul 原语。

注意

显示 JSON schema:

详情
json
{
  "description": "A yes/no answer.\n\nSee the [noul primitive](https://docs.typesafe.ai/primitives/noul) for details.",
  "properties": {
    "type": {
      "const": "noul",
      "default": "noul",
      "title": "Type",
      "type": "string"
    },
    "noul": {
      "description": "Probability of a yes answer or a true statement, from 0 to 1. Values near 1 favor yes or true, values near 0 favor no or false, and values near 0.5 indicate uncertainty.",
      "examples": [
        0.98
      ],
      "title": "Noul",
      "type": "number"
    }
  },
  "required": [
    "noul"
  ],
  "title": "NoulAnswer",
  "type": "object"
}
 

配置:

  • extra:ignore
  • frozen:True
  • strict:True

字段:

noul

pydantic-field

是/否答案或真陈述的概率,取值 0 到 1。接近 1 的值偏向「是」或真,接近 0 的值偏向「否」或假,接近 0.5 的值表示不确定。

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

typesafe_sdk.ChoiceAnswer

pydantic-model

基类:wire.ChoiceAnswer

被选中的标签及其概率。

详见 choice 原语。

注意

显示 JSON schema:

详情
json
{
  "description": "A selected label and its probabilities.\n\nSee the [choice primitive](https://docs.typesafe.ai/primitives/choice) for details.",
  "properties": {
    "type": {
      "const": "choice",
      "default": "choice",
      "title": "Type",
      "type": "string"
    },
    "choice": {
      "description": "The name of the choice with the highest probability among the question's criteria.",
      "examples": [
        "angry"
      ],
      "title": "Choice",
      "type": "string"
    },
    "confidence": {
      "description": "Confidence in the selected choice, from 0 to 1. Higher values indicate greater certainty; use lower values to flag uncertain selections for review.",
      "examples": [
        0.9
      ],
      "title": "Confidence",
      "type": "number"
    },
    "probabilities": {
      "additionalProperties": {
        "type": "number"
      },
      "description": "Probability of each choice in criteria, keyed by choice name, from 0 to 1. Shows how likely the alternatives are; values sum to approximately 1.",
      "examples": [
        {
          "angry": 0.8,
          "calm": 0.1,
          "excited": 0.1
        }
      ],
      "title": "Probabilities",
      "type": "object"
    }
  },
  "required": [
    "choice",
    "confidence",
    "probabilities"
  ],
  "title": "ChoiceAnswer",
  "type": "object"
}
 

配置:

  • extra:ignore
  • frozen:True
  • strict:True

字段:

choice

pydantic-field

在该问题的 criteria 中概率最高的 choice 名称。

confidence

pydantic-field

对所选 choice 的置信度,取值 0 到 1。值越高表示确定性越大;用较低的值把不确定的选择标记出来以供复核。

probabilities

pydantic-field

criteria 中每个 choice 的概率,以 choice 名称作为键,取值 0 到 1。它展示各备选项的可能性大小;各值之和约等于 1。

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

typesafe_sdk.ScoreAnswer

pydantic-model

基类:wire.ScoreAnswer

带有评分细则与概率的期望 score。

详见 score 原语。

注意

显示 JSON schema:

详情
json
{
  "description": "An expected score with its rubric and probabilities.\n\nSee the [score primitive](https://docs.typesafe.ai/primitives/score) for details.",
  "properties": {
    "type": {
      "const": "score",
      "default": "score",
      "title": "Type",
      "type": "string"
    },
    "score": {
      "description": "Expected score: the probability-weighted average of the rubric levels. May fall between integer levels.",
      "examples": [
        1.7
      ],
      "title": "Score",
      "type": "number"
    },
    "confidence": {
      "description": "Confidence in the score, from 0 to 1. Higher values indicate greater certainty; use lower values to flag uncertain ratings for review.",
      "examples": [
        0.9
      ],
      "title": "Confidence",
      "type": "number"
    },
    "legend": {
      "additionalProperties": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "additionalProperties": true,
            "type": "object"
          },
          {
            "items": {},
            "type": "array"
          }
        ]
      },
      "title": "Legend",
      "type": "object"
    },
    "probabilities": {
      "additionalProperties": {
        "type": "number"
      },
      "title": "Probabilities",
      "type": "object"
    }
  },
  "required": [
    "score",
    "confidence",
    "legend",
    "probabilities"
  ],
  "title": "ScoreAnswer",
  "type": "object"
}
 

配置:

  • extra:ignore
  • frozen:True
  • strict:True

字段:

score

pydantic-field

期望 score:各评分细则等级的概率加权平均值。可能落在整数等级之间。

confidence

pydantic-field

对 score 的置信度,取值 0 到 1。值越高表示确定性越大;用较低的值把不确定的评分标记出来以供复核。

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

legend

pydantic-field

以整数 score 作为键的评分细则描述。

probabilities

pydantic-field

以整数 score 作为键的概率。

typesafe_sdk.Answer

module-attribute

对单个问题的答案,由其 type 标识。

可用模型

typesafe_sdk.ListModelsResponse

pydantic-model

基类:Response

该账户可用的模型。

注意

显示 JSON schema:

详情
json
{
  "$defs": {
    "ModelMetadata": {
      "description": "Metadata describing a single available model.",
      "properties": {
        "name": {
          "title": "Name",
          "type": "string"
        },
        "description": {
          "title": "Description",
          "type": "string"
        },
        "release_date": {
          "title": "Release Date",
          "type": "string"
        }
      },
      "required": [
        "name",
        "description",
        "release_date"
      ],
      "title": "ModelMetadata",
      "type": "object"
    }
  },
  "description": "The models available to the account.",
  "properties": {
    "models": {
      "items": {
        "$ref": "#/$defs/ModelMetadata"
      },
      "title": "Models",
      "type": "array"
    }
  },
  "required": [
    "models"
  ],
  "title": "ListModelsResponse",
  "type": "object"
}
 

字段:

request_id

cached property

x-typesafe-request-id 响应头。

raw_http_response

property

python
raw_http_response: httpx2.Response
 

底层的 httpx2.Response,暴露状态、响应头与响应体。

model_config

class-attribute instance-attribute

python
model_config = ConfigDict(
    extra="ignore", frozen=True, strict=True
)
 

models

pydantic-field

可用的模型。

typesafe_sdk.ModelMetadata

pydantic-model

基类:Schema

描述单个可用模型的元数据。

注意

显示 JSON schema:

详情
json
{
  "description": "Metadata describing a single available model.",
  "properties": {
    "name": {
      "title": "Name",
      "type": "string"
    },
    "description": {
      "title": "Description",
      "type": "string"
    },
    "release_date": {
      "title": "Release Date",
      "type": "string"
    }
  },
  "required": [
    "name",
    "description",
    "release_date"
  ],
  "title": "ModelMetadata",
  "type": "object"
}
 

字段:

name

pydantic-field

请求的 model 字段所接受的模型名称或别名。

description

pydantic-field

对模型及其能力的人类可读描述。

release_date

pydantic-field

模型发布日期,格式为 YYYY-MM-DD。