流式传输 (v1)
旧版
流式传输执行运行或在提交工具输出后恢复运行的结果。
你可以通过在创建会话和运行、创建运行和提交工具输出端点传递 "stream": true 来流式传输事件。响应将是一个服务器发送事件流。
我们的 Node 和 Python SDK 提供了有用的实用工具,使流式传输变得简单。参考 Assistants API 快速入门了解更多信息。
消息增量对象 (v1)
旧版
表示一个消息增量,即在流式传输期间消息上任何更改的字段。
| 参数名 | 类型 | 描述 | 
|---|---|---|
| id | string | 消息的标识符,可在 API 端点中引用。 | 
| object | string | 对象类型,始终为 thread.message.delta。 | 
| delta | object | 包含消息上已更改字段的增量。 | 
消息增量对象示例
{
  "id": "msg_123",
  "object": "thread.message.delta",
  "delta": {
    "content": [
      {
        "index": 0,
        "type": "text",
        "text": { "value": "Hello", "annotations": [] }
      }
    ]
  }
}
运行步骤增量对象 (v1)
旧版
表示一个运行步骤增量,即在流式传输期间运行步骤上任何更改的字段。
| 参数名 | 类型 | 描述 | 
|---|---|---|
| id | string | 运行步骤的标识符,可在 API 端点中引用。 | 
| object | string | 对象类型,始终为 thread.run.step.delta。 | 
| delta | object | 包含运行步骤上已更改字段的增量。 | 
运行步骤增量对象示例
{
  "id": "step_123",
  "object": "thread.run.step.delta",
  "delta": {
    "step_details": {
      "type": "tool_calls",
      "tool_calls": [
        {
          "index": 0,
          "id": "call_123",
          "type": "code_interpreter",
          "code_interpreter": { "input": "", "outputs": [] }
        }
      ]
    }
  }
}
(助手流事件 v1)
表示流式运行时发出的事件。
每个服务器发送的事件流中的事件都有一个 event 和 data 属性:
event: thread.created
data: {"id": "thread_123", "object": "thread", ...}
当创建新对象、转换到新状态或部分流式传输(增量)时,我们会发出事件。例如,当创建新的运行时,我们会发出 thread.run.created,当运行完成时发出 thread.run.completed,以此类推。当助手在运行过程中选择创建消息时,我们会发出一个 thread.message.created 事件、一个 thread.message.in_progress 事件、多个 thread.message.delta 事件,最后是一个 thread.message.completed 事件。
我们可能会随着时间添加其他事件,因此我们建议在代码中优雅地处理未知事件。请参阅Assistants API quickstart,了解如何将 Assistants API 与流式传输集成。
| 事件名称 | 数据 | 描述 | 
|---|---|---|
| thread.created | data是一个 thread | 当创建新的 thread 时发生 | 
| thread.run.created | data是一个 run | 当创建新的 run 时发生 | 
| thread.run.queued | data是一个 run | 当 run 移至 queued状态时发生 | 
| thread.run.in_progress | data是一个 run | 当 run 移至 in_progress状态时发生 | 
| thread.run.requires_action | data是一个 run | 当 run 移至 requires_action状态时发生 | 
| thread.run.completed | data是一个 run | 当 run 完成时发生 | 
| thread.run.failed | data是一个 run | 当 run 失败时发生 | 
| thread.run.cancelling | data是一个 run | 当 run 移至 cancelling状态时发生 | 
| thread.run.cancelled | data是一个 run | 当 run 被取消时发生 | 
| thread.run.expired | data是一个 run | 当 run 过期时发生 | 
| thread.run.step.created | data是一个 run step | 当创建 run step 时发生 | 
| thread.run.step.in_progress | data是一个 run step | 当 run step 进入 in_progress状态时发生 | 
| thread.run.step.delta | data是一个 run step delta | 当 run step 的部分内容被流式传输时发生 | 
| thread.run.step.completed | data是一个 run step | 当 run step 完成时发生 | 
| thread.run.step.failed | data是一个 run step | 当 run step 失败时发生 | 
| thread.run.step.cancelled | data是一个 run step | 当 run step 被取消时发生 | 
| thread.run.step.expired | data是一个 run step | 当 run step 过期时发生 | 
| thread.message.created | data是一个 message | 当创建 message 时发生 | 
| thread.message.in_progress | data是一个 message | 当 message 进入 in_progress状态时发生 | 
| thread.message.delta | data是一个 message delta | 当 message 的部分内容被流式传输时发生 | 
| thread.message.completed | data是一个 message | 当 message 完成时发生 | 
| thread.message.incomplete | data是一个 message | 当 message 在完成之前结束时发生 | 
| error | data是一个 error | 当发生 error 时发生。这可能是由于内部服务器错误或超时导致的 | 
| done | data是[DONE] | 当流结束时发生 |