🛡️TypeSafe 中文文档
原文档 ↗

答案与响应

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

响应

typesafe_sdk.SystemOneResponse

pydantic-model

基类:Response

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

详见 System One。

📝注意

显示 JSON schema:

Details▾
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


  
    request_id
  

  
    :
  

   

  
    
      str
    
  

  

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


  
    model
  

  
    :
  

   

  
    
      str
    
  

  

用于回答该请求的模型。

usage

pydantic-field


  
    usage
  

  
    :
  

   

  
    
      Usage
    
  

  

该请求的 token 用量。

answers

pydantic-field


  
    answers
  

  
    :
  

   

  
    
      dict
    
  

  
    [
  

  
    
      str
    
  

  
    ,
  

   

  
    
      Answer
    
  

  
    ]
  

  

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

nouls

cached property

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

choices

cached property

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

scores

cached property

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

typesafe_sdk.Usage

pydantic-model

基类:wire.Usage

请求的 token 计数(当 API 有报告时)。

📝注意

显示 JSON schema:

Details▾
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


  
    input_tokens
  

  
    :
  

   

  
    
      int
    
  

   

  
    |
  

   

  
    None
  

   

  
    =
  

   

  
    None
  

  

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

output_tokens

pydantic-field


  
    output_tokens
  

  
    :
  

   

  
    
      int
    
  

   

  
    |
  

   

  
    None
  

   

  
    =
  

   

  
    None
  

  

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

答案

typesafe_sdk.NoulAnswer

pydantic-model

基类:wire.NoulAnswer

一个是/否答案。

详见 noul 原语。

📝注意

显示 JSON schema:

Details▾
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


  
    noul
  

  
    :
  

   

  
    
      float
    
  

  

是/否答案或真值陈述的概率,取值范围 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:

Details▾
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


  
    choice
  

  
    :
  

   

  
    
      str
    
  

  

在问题的评判标准中概率最高的选项名称。

confidence

pydantic-field


  
    confidence
  

  
    :
  

   

  
    
      float
    
  

  

所选选项的置信度,取值范围 0 到 1。值越高表示确定性越大;可用较低的值标记不确定的选择以便复核。

probabilities

pydantic-field


  
    probabilities
  

  
    :
  

   

  
    
      dict
    
  

  
    [
  

  
    
      str
    
  

  
    ,
  

   

  
    
      float
    
  

  
    ]
  

  

标准中每个选项的概率,以选项名称为键,取值范围 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 原语。

📝注意

显示 JSON schema:

Details▾
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
  

  
    :
  

   

  
    
      float
    
  

  

预期分数:各评分档位的概率加权平均值。可能落在整数档位之间。

confidence

pydantic-field


  
    confidence
  

  
    :
  

   

  
    
      float
    
  

  

分数的置信度,取值范围 0 到 1。值越高表示确定性越大;可用较低的值标记不确定的评分以便复核。

model_config

class-attribute instance-attribute

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

legend

pydantic-field


  legend: dict[
    int, str | dict[str, Any] | list[Any]
]

以整数分数为键的评分标准描述。

probabilities

pydantic-field


  
    probabilities
  

  
    :
  

   

  
    
      dict
    
  

  
    [
  

  
    
      int
    
  

  
    ,
  

   

  
    
      float
    
  

  
    ]
  

  

以整数分数为键的概率。

typesafe_sdk.Answer

module-attribute


  Answer: TypeAlias = Annotated[
    NoulAnswer | ChoiceAnswer | ScoreAnswer,
    Field(discriminator="type"),
]

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

可用模型

typesafe_sdk.ListModelsResponse

pydantic-model

基类:Response

该账户可用的模型。

📝注意

显示 JSON schema:

Details▾
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


  
    request_id
  

  
    :
  

   

  
    
      str
    
  

  

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


  
    models
  

  
    :
  

   

  
    
      tuple
    
  

  
    [
  

  
    
      ModelMetadata
    
  

  
    ,
  

   

  
    ...
  

  
    ]
  

  

可用模型。

typesafe_sdk.ModelMetadata

pydantic-model

基类:Schema

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

📝注意

显示 JSON schema:

Details▾
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


  
    name
  

  
    :
  

   

  
    
      str
    
  

  

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

description

pydantic-field


  
    description
  

  
    :
  

   

  
    
      str
    
  

  

关于该模型及其能力的人类可读描述。

release_date

pydantic-field


  
    release_date
  

  
    :
  

   

  
    
      str
    
  

  

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

本站为 docs.typesafe.ai 的中文翻译,仅供学习参考;内容版权归原作者所有。