Threads

The Threads API is very useful for creating a chat-like experience with a relatively large message history

API Reference

删除话题。

delete

删除话题,永久删除对话。

路径参数
threadIdstring必填
响应
200成功
application/json
delete
/threads/{threadId}
DELETE /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Accept: */*
200成功
{
  "id": "text",
  "object": "thread.deleted",
  "deleted": true
}

创建新的对话主题。

post

创建新线程,发起对话或互动。

请求体
messagesstring[]必填
metadataobject可选
响应
200成功
application/json
post
/threads
POST /threads HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 35

{
  "messages": [
    "text"
  ],
  "metadata": {}
}
200成功
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

获取特定线程的详细信息。

get

通过 ID 检索单个线程,提供对其详细信息和消息的访问。

路径参数
threadIdstring必填
响应
200成功
application/json
get
/threads/{threadId}
GET /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Accept: */*
200成功
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

更新主题的信息。

post

更新现有线程的信息或上下文。

路径参数
threadIdstring必填
请求体
metadataobject可选
响应
200成功
application/json
post
/threads/{threadId}
POST /threads/{threadId} HTTP/1.1
Host: api.aimlapi.com
Content-Type: application/json
Accept: */*
Content-Length: 15

{
  "metadata": {}
}
200成功
{
  "id": "text",
  "created_at": 1,
  "metadata": null,
  "object": "thread",
  "tool_resources": {
    "code_interpreter": {
      "file_ids": [
        "text"
      ]
    },
    "file_search": {
      "vector_store_ids": [
        "text"
      ]
    }
  }
}

Example

thread = client.beta.threads.create(
  messages=[
    {
      "role": "user",
      "content": "Create 3 data visualizations based on the trends in this file.",
      "attachments": [
        {
          "file_id": file.id,
          "tools": [{"type": "code_interpreter"}]
        }
      ]
    }
  ]
)        

最后更新于