创建嵌入

POST /v1/embeddings

MethodPOST
Path/v1/embeddings
Typehttp
Status1
Module2102810
Folder45008046

说明

获取给定输入的矢量表示,机器学习模型和算法可以轻松使用该表示。

相关指南:嵌入

创建表示输入文本的嵌入向量。

概览

MethodPOST
Path/v1/embeddings
Typehttp
Status1
Module2102810
Folder45008046

参数

{
  "query": [],
  "path": [],
  "cookie": [],
  "header": [
    {
      "required": false,
      "description": "",
      "type": "string",
      "id": "tiNTkyHARU",
      "enable": true,
      "name": "Authorization",
      "sampleValue": "Bearer {{YOUR_API_KEY}}"
    }
  ]
}

请求体

{
  "type": "application/json",
  "parameters": [],
  "jsonSchema": {
    "type": "object",
    "properties": {
      "model": {
        "type": "string",
        "description": "要使用的模型的 ID。您可以使用[List models](https://platform.openai.com/docs/api-reference/models/list) API 来查看所有可用模型,或查看我们的[模型概述](https://platform.openai.com/docs/models/overview)以了解它们的描述。"
      },
      "input": {
        "type": "string",
        "description": "输入文本以获取嵌入,编码为字符串或标记数组。要在单个请求中获取多个输入的嵌入,请传递一个字符串数组或令牌数组数组。每个输入的长度不得超过 8192 个标记。"
      }
    },
    "required": [
      "model",
      "input"
    ],
    "x-apifox-orders": [
      "model",
      "input"
    ]
  },
  "mediaType": "",
  "examples": [
    {
      "value": "{\n  \"model\": \"text-embedding-3-large\",\n  \"input\": \"喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵\"\n}",
      "mediaType": "application/json",
      "description": ""
    }
  ],
  "oasExtensions": ""
}

响应

[
  {
    "id": 562499891,
    "name": "Create embeddings",
    "code": 200,
    "contentType": "json",
    "jsonSchema": {
      "type": "object",
      "properties": {
        "object": {
          "type": "string"
        },
        "data": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "object": {
                "type": "string"
              },
              "embedding": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "index": {
                "type": "integer"
              }
            },
            "x-apifox-orders": [
              "object",
              "embedding",
              "index"
            ]
          }
        },
        "model": {
          "type": "string"
        },
        "usage": {
          "type": "object",
          "properties": {
            "prompt_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "prompt_tokens",
            "total_tokens"
          ],
          "x-apifox-orders": [
            "prompt_tokens",
            "total_tokens"
          ]
        }
      },
      "required": [
        "object",
        "data",
        "model",
        "usage"
      ],
      "x-apifox-orders": [
        "object",
        "data",
        "model",
        "usage"
      ]
    },
    "itemSchema": {},
    "description": "",
    "mediaType": "",
    "headers": [],
    "oasExtensions": ""
  }
]

响应示例

[
  {
    "name": "Create embeddings",
    "responseId": 562499891,
    "data": "{\n  \"object\": \"list\",\n  \"data\": [\n    {\n      \"object\": \"embedding\",\n      \"embedding\": [\n        0.0023064255,\n        -0.009327292,\n        .... (1536 floats total for ada-002)\n        -0.0028842222\n      ],\n      \"index\": 0\n    }\n  ],\n  \"model\": \"text-embedding-ada-002\",\n  \"usage\": {\n    \"prompt_tokens\": 8,\n    \"total_tokens\": 8\n  }\n}",
    "description": "",
    "oasKey": "",
    "oasExtensions": "",
    "id": 440608997
  }
]