创建完成

POST /v1/completions

MethodPOST
Path/v1/completions
Typehttp
Status1
Module2102810
Folder45008045

说明

给定一个提示,该模型将返回一个或多个预测的完成,并且还可以返回每个位置的替代标记的概率。

为提供的提示和参数创建完成

https://platform.openai.com/docs/api-reference/completions

概览

MethodPOST
Path/v1/completions
Typehttp
Status1
Module2102810
Folder45008045

参数

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

请求体

{
  "type": "application/json",
  "parameters": [],
  "jsonSchema": {
    "type": "object",
    "properties": {
      "model": {
        "type": "string",
        "title": "",
        "description": "要使用的模型的 ID。您可以使用[List models](https://platform.openai.com/docs/api-reference/models/list) API 来查看所有可用模型,或查看我们的[模型概述](https://platform.openai.com/docs/models/overview)以了解它们的描述。"
      },
      "prompt": {
        "type": "string",
        "title": "",
        "description": "生成完成的提示,编码为字符串、字符串数组、标记数组或标记数组数组。  请注意,<|endoftext|> 是模型在训练期间看到的文档分隔符,因此如果未指定提示,模型将生成新文档的开头。"
      },
      "max_tokens": {
        "type": "integer",
        "title": "",
        "description": "默认为16\n在补全中生成的最大令牌数。\n\n提示的令牌计数加上max_tokens不能超过模型的上下文长度。 计数令牌的Python代码示例。"
      },
      "temperature": {
        "type": "integer",
        "title": "",
        "description": "默认为1 要使用的采样温度,介于0和2之间。更高的值(如0.8)将使输出更随机,而更低的值(如0.2)将使其更集中和确定。  我们通常建议更改这个或top_p,而不是两者都更改。"
      },
      "top_p": {
        "type": "integer",
        "description": "表示最终用户的唯一标识符,这可以帮助OpenAI监控和检测滥用。 了解更多。"
      },
      "n": {
        "type": "integer",
        "description": "默认为1\n为每个提示生成的补全数量。\n\n注意:因为这个参数会生成许多补全,所以它可以快速消耗您的令牌配额。请谨慎使用,并确保您对max_tokens和stop有合理的设置。"
      },
      "stream": {
        "type": "boolean",
        "title": "",
        "description": "默认为false 是否流回部分进度。如果设置,令牌将作为可用时发送为仅数据的服务器发送事件,流由数据 Terminated by a data: [DONE] message. 对象消息终止。 Python代码示例。"
      },
      "logprobs": {
        "type": "null",
        "title": "",
        "description": "默认为null\n包括logprobs个最可能令牌的日志概率,以及所选令牌。例如,如果logprobs为5,API将返回5个最有可能令牌的列表。 API总会返回采样令牌的logprob,因此响应中最多可能有logprobs+1个元素。\n\nlogprobs的最大值是5。"
      },
      "stop": {
        "type": "string",
        "title": "",
        "description": "默认为null 最多4个序列,API将停止在其中生成更多令牌。返回的文本不会包含停止序列。"
      },
      "best_of": {
        "type": "integer",
        "description": "默认为1 在服务器端生成best_of个补全,并返回“最佳”补全(每个令牌的日志概率最高的那个)。无法流式传输结果。  与n一起使用时,best_of控制候选补全的数量,n指定要返回的数量 – best_of必须大于n。  注意:因为这个参数会生成许多补全,所以它可以快速消耗您的令牌配额。请谨慎使用,并确保您对max_tokens和stop有合理的设置。"
      },
      "echo": {
        "type": "boolean",
        "description": "默认为false 除了补全之外,还回显提示"
      },
      "frequency_penalty": {
        "type": "number",
        "description": "默认为0 -2.0和2.0之间的数字。正值根据文本目前的现有频率处罚新令牌,降低模型逐字重复相同行的可能性。"
      },
      "logit_bias": {
        "type": "object",
        "properties": {},
        "description": "默认为null 修改完成中指定令牌出现的可能性。  接受一个JSON对象,该对象将令牌(由GPT令牌化器中的令牌ID指定)映射到关联偏差值,-100到100。您可以使用这个令牌化器工具(适用于GPT-2和GPT-3)将文本转换为令牌ID。从数学上讲,偏差在对模型进行采样之前添加到生成的logit中。确切效果因模型而异,但-1至1之间的值应降低或提高选择的可能性;像-100或100这样的值应导致相关令牌的禁用或专属选择。  例如,您可以传递{\"50256\": -100}来防止生成<|endoftext|>令牌。",
        "x-apifox-orders": []
      },
      "presence_penalty": {
        "type": "number",
        "description": "默认为0 -2.0和2.0之间的数字。正值根据它们是否出现在目前的文本中来惩罚新令牌,增加模型讨论新话题的可能性。  有关频率和存在惩罚的更多信息,请参阅。"
      },
      "seed": {
        "type": "integer",
        "description": "如果指定,我们的系统将尽最大努力确定性地进行采样,以便使用相同的种子和参数的重复请求应返回相同的结果。  不保证确定性,您应该参考system_fingerprint响应参数来监视后端的更改。"
      },
      "suffix": {
        "type": "string",
        "description": "默认为null 在插入文本的补全之后出现的后缀。"
      },
      "user": {
        "type": "string"
      }
    },
    "required": [
      "model",
      "prompt",
      "user"
    ],
    "x-apifox-orders": [
      "model",
      "prompt",
      "best_of",
      "echo",
      "frequency_penalty",
      "logit_bias",
      "logprobs",
      "max_tokens",
      "n",
      "presence_penalty",
      "seed",
      "stop",
      "stream",
      "suffix",
      "temperature",
      "user",
      "top_p"
    ]
  },
  "mediaType": "",
  "examples": [
    {
      "value": "{\n    \"model\": \"gpt-3.5-turbo-instruct\",\n    \"prompt\": \"你好,\",\n    \"max_tokens\": 30,\n    \"temperature\": 0\n  }",
      "mediaType": "application/json",
      "description": ""
    }
  ],
  "oasExtensions": ""
}

响应

[
  {
    "id": 562499890,
    "name": "Ok",
    "code": 200,
    "contentType": "json",
    "jsonSchema": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "object": {
          "type": "string"
        },
        "created": {
          "type": "integer"
        },
        "model": {
          "type": "string"
        },
        "system_fingerprint": {
          "type": "string"
        },
        "choices": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "text": {
                "type": "string"
              },
              "index": {
                "type": "integer"
              },
              "logprobs": {
                "type": "null"
              },
              "finish_reason": {
                "type": "string"
              }
            },
            "x-apifox-orders": [
              "text",
              "index",
              "logprobs",
              "finish_reason"
            ]
          }
        },
        "usage": {
          "type": "object",
          "properties": {
            "prompt_tokens": {
              "type": "integer"
            },
            "completion_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "prompt_tokens",
            "completion_tokens",
            "total_tokens"
          ],
          "x-apifox-orders": [
            "prompt_tokens",
            "completion_tokens",
            "total_tokens"
          ]
        }
      },
      "required": [
        "id",
        "object",
        "created",
        "model",
        "system_fingerprint",
        "choices",
        "usage"
      ],
      "x-apifox-orders": [
        "id",
        "object",
        "created",
        "model",
        "system_fingerprint",
        "choices",
        "usage"
      ]
    },
    "itemSchema": {},
    "description": "",
    "mediaType": "",
    "headers": [],
    "oasExtensions": ""
  }
]

响应示例

[
  {
    "name": "成功示例",
    "responseId": 562499890,
    "data": "{\r\n    \"id\": \"cmpl-ByvHP6AWeB1L5vWZSPNHsB12sU9db\",\r\n    \"object\": \"text_completion\",\r\n    \"created\": 1753859563,\r\n    \"model\": \"gpt-3.5-turbo-instruct\",\r\n    \"choices\": [\r\n        {\r\n            \"index\": 0,\r\n            \"logprobs\": null,\r\n            \"finish_reason\": \"length\",\r\n            \"text\": \"我是小冰,很高兴认识你。我是一个人工智能助手,可以回\"\r\n        }\r\n    ],\r\n    \"usage\": {\r\n        \"prompt_tokens\": 3,\r\n        \"completion_tokens\": 30,\r\n        \"total_tokens\": 33\r\n    }\r\n}",
    "description": "",
    "oasKey": "",
    "oasExtensions": "",
    "id": 440608996
  }
]