# 内容补全接口

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/completions:
    post:
      summary: 内容补全接口
      deprecated: false
      description: |+
        给定一个提示，该模型将返回一个或多个预测的完成，并且还可以返回每个位置的替代标记的概率。

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

      tags:
        - 模型接口/自动补全接口（Completions）
      parameters:
        - name: Authorization
          in: header
          description: ''
          required: true
          example: Bearer {{YOUR_API_KEY}}
          schema:
            type: string
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              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: >-
                    完成时生成的最大[令牌](https://platform.openai.com/tokenizer)数。 
                    您的提示加上的令牌计数`max_tokens`不能超过模型的上下文长度。大多数模型的上下文长度为 2048
                    个标记（最新模型除外，它支持 4096）。
                temperature:
                  type: integer
                  title: ''
                  description: >-
                    使用什么采样温度，介于 0 和 2 之间。较高的值（如 0.8）将使输出更加随机，而较低的值（如
                    0.2）将使输出更加集中和确定。  我们通常建议改变这个或`top_p`但不是两者。
                top_p:
                  type: integer
                  description: >-
                    一种替代温度采样的方法，称为核采样，其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前
                    10% 概率质量的标记。  我们通常建议改变这个或`temperature`但不是两者。
                'n':
                  type: integer
                  description: >-
                    为每个提示生成多少完成。 
                    **注意：**因为这个参数会产生很多完成，它会很快消耗你的令牌配额。请谨慎使用并确保您对`max_tokens`和进行了合理的设置`stop`。
                stream:
                  type: boolean
                  title: ''
                  description: >-
                    是否回流部分进度。如果设置，令牌将在可用时作为仅数据[服务器发送事件](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)发送，流由`data:
                    [DONE]`消息终止。
                logprobs:
                  type: 'null'
                  title: ''
                  description: >-
                    包括最有可能标记的对数概率`logprobs`，以及所选标记。例如，如果`logprobs`是 5，API 将返回 5
                    个最有可能的标记的列表。API 将始终返回采样令牌的
                    ，因此响应中`logprob`最多可能有元素。`logprobs+1`  的最大值`logprobs`为
                    5。如果您需要更多，请通过我们的[帮助中心](https://help.openai.com/)联系我们并描述您的用例。
                stop:
                  type: string
                  title: ''
                  description: API 将停止生成更多令牌的最多 4 个序列。返回的文本将不包含停止序列。
              required:
                - model
              x-apifox-orders:
                - model
                - prompt
                - max_tokens
                - temperature
                - top_p
                - 'n'
                - stream
                - logprobs
                - stop
            example:
              model: gpt-3.5-turbo-instruct
              prompt: Say this is a test
              max_tokens: 7
              temperature: 0
              top_p: 1
              'n': 1
              stream: false
              logprobs: null
              stop: |+

      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  object:
                    type: string
                  created:
                    type: integer
                  model:
                    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
                  - choices
                  - usage
                x-apifox-orders:
                  - id
                  - object
                  - created
                  - model
                  - choices
                  - usage
              example:
                id: cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7
                object: text_completion
                created: 1589478378
                model: text-davinci-003
                choices:
                  - text: |-


                      This is indeed a test
                    index: 0
                    logprobs: null
                    finish_reason: length
                usage:
                  prompt_tokens: 5
                  completion_tokens: 7
                  total_tokens: 12
          headers: {}
          x-apifox-name: Ok
      security: []
      x-apifox-folder: 模型接口/自动补全接口（Completions）
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/2946232/apis/api-92222077-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://api.chatanywhere.tech
    description: 正式环境
security: []

```
