# 对话生成 chatGpt 接口

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/chat/completions:
    post:
      summary: 对话生成 chatGpt 接口
      deprecated: false
      description: |+
        **冰橙API提供与OPENAI官方的API兼容的接口方式，方便国内开发者进行与OPENAI的CHATGPT的接口对接服务**



        :::highlight purple 💡
        >注：GPT3.5所有模型将强制指向gpt-4o-mini，即最新模型
        >有关非流式请求的消耗将降为原来的一半
        :::


        :::highlight purple 💡
        > 对话生成 GPT3.5  采用非SSE方式（流式），对话响应一般，需等待官方数据全部接收后才会进行响应输出
        > **推荐采用流式输出 ，效果更好**
        :::

        ### token获取方式：
        - 访问公众号《冰橙云》进入菜单冰橙AI助手后，访问右上角 / API密钥 可查看 token
        - 访问：https://yewu.bcwhkj.cn 》 个人 》API密钥 》Token令牌 


        只列出部分常用参数，完整参数说明参考 
        **OpenAI 官方文档**：https://platform.openai.com/docs/api-reference/chat


      tags:
        - 文生文 对话生成
      parameters:
        - name: Content-Type
          in: header
          description: 固定值
          required: false
          example: application/json
          schema:
            type: string
        - name: Authorization
          in: header
          description: token要更换为个人自己的TOKEN
          example: Bearer token
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                        x-apifox:
                          enumDescriptions:
                            system: 表示系统默认语境
                            user: 表示用户角色
                            assistant: 表示AI角色
                      content:
                        type: string
                        description: 提问的内容
                    x-apifox-orders:
                      - role
                      - content
                    required:
                      - role
                      - content
                model:
                  type: string
                  description: 模型
                  enum:
                    - gpt-3.5-turbo-0125
                    - gpt-3.5-turbo
                    - gpt-3.5-turbo-16k
                    - gpt-4o
                    - gpt-4-0125-preview
                    - gpt-4-turbo-preview
                  x-apifox:
                    enumDescriptions:
                      gpt-3.5-turbo-0125: 推荐，新版更快，默认支持16K
                      gpt-3.5-turbo: '    '
                      gpt-3.5-turbo-16k: ''
                      gpt-4o: ''
                      gpt-4-0125-preview: ''
                      gpt-4-turbo-preview: ''
                  default: gpt-3.5-turbo-0613
                stream:
                  type: boolean
                  description: 是否启用流式
                  default: false
                max_tokens:
                  type: integer
                  description: >-
                    回复的最大内容长度。限制一次请求中模型生成 completion 的最大 token 数。输入 token 和输出
                    token 的总长度受模型的上下文长度的限制。
                  default: 4000
                frequency_penalty:
                  type: integer
                  description: >-
                    频率惩罚，-2.0 到 2.0
                    之间的数字。正值根据新标记在文本中到目前为止的现有频率进行惩罚，降低模型重复相同行文字的可能性。
                temperature:
                  type: integer
                  description: >-
                    使用什么采样温度，介于 0 和 2 之间。较高的值（如 0.8）将使输出更加随机，而较低的值（如
                    0.2）将使输出更加集中和确定。 我们通常建议改变这个或top_p但不是两者。
                top_p:
                  type: integer
                  description: >-
                    一种替代温度采样的方法，称为核采样，其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前
                    10% 概率质量的标记。 我们通常建议改变这个或temperature但不是两者同时提交。
                'n':
                  type: integer
                  description: 为每个输入消息生成多少个聊天补全选择。
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                      default: json_object
                  description: >-
                    指定模型必须输出的格式的对象。 将 { "type": "json_object" } 启用 JSON
                    模式,这可以确保模型生成的消息是有效的 JSON。 重要提示:使用 JSON
                    模式时,还必须通过系统或用户消息指示模型生成
                    JSON。如果不这样做,模型可能会生成无休止的空白流,直到生成达到令牌限制,从而导致延迟增加和请求“卡住”的外观。另请注意,如果
                    finish_reason="length",则消息内容可能会被部分切断,这表示生成超过了 max_tokens
                    或对话超过了最大上下文长度。 显示属性
                  x-apifox-orders:
                    - type
                tools:
                  type: array
                  items:
                    type: string
                  description: 模型可以调用的一组工具列表。目前,只支持作为工具的函数。使用此功能来提供模型可以为之生成 JSON 输入的函数列表。
                tool_choice:
                  type: object
                  properties: {}
                  description: >-
                    控制模型调用哪个函数(如果有的话)。none 表示模型不会调用函数,而是生成消息。auto
                    表示模型可以在生成消息和调用函数之间进行选择。通过 {"type": "function", "function":
                    {"name": "my_function"}} 强制模型调用该函数。 如果没有函数存在,默认为
                    none。如果有函数存在,默认为 auto。 显示可能的类型
                  x-apifox-orders: []
              required:
                - messages
                - model
              x-apifox-orders:
                - messages
                - model
                - stream
                - max_tokens
                - frequency_penalty
                - temperature
                - top_p
                - 'n'
                - response_format
                - tools
                - tool_choice
            example:
              messages:
                - role: system
                  content: 你是一个能干的助手.
                - role: user
                  content: 谁赢得了2020年的世界职业棒球大赛?
                - role: assistant
                  content: 洛杉矶道奇队在2020年赢得了世界职业棒球大赛冠军.
                - role: user
                  content: 它在哪里举办的?
              model: gpt-4o-mini
              stream: false
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  model:
                    type: string
                    description: 使用的模型
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        message:
                          type: object
                          properties:
                            role:
                              type: string
                            content:
                              type: string
                              description: 主要内容
                          required:
                            - role
                            - content
                          x-apifox-orders:
                            - role
                            - content
                      x-apifox-orders:
                        - message
                required:
                  - id
                  - model
                  - choices
                x-apifox-orders:
                  - id
                  - model
                  - choices
              examples:
                '1':
                  summary: 成功示例
                  value:
                    id: chatcmpl-7stavzrezgeImDvdKABNHVNbZvIN4
                    object: chat.completion
                    created: 1693317773
                    model: gpt-3.5-turbo-0613
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: 2020年的世界职业棒球大赛是在美国德州州的阿灵顿的球场举办的.
                        finish_reason: stop
                    usage:
                      prompt_tokens: 101
                      completion_tokens: 40
                      total_tokens: 141
                '2':
                  summary: 密钥错误
                  value:
                    codes: 900
                    mess: 密钥错误或已过期，请通过微信访问yewu.bcwhkj.cn个人中心获取
                    data: token
                '3':
                  summary: 非法内容
                  value:
                    codes: 400
                    mess: 非法字符。请勿提交
                    data: ''
                '4':
                  summary: 内容安全
                  value:
                    codes: 402
                    mess: 提交问题涉及内容安全，请修改问题
                    data: ''
                '5':
                  summary: 额度不足
                  value:
                    codes: 300
                    mess: 当前额度不足，请充值后继续使用
                    data: ''
                '6':
                  summary: 官方API维护中
                  value:
                    error:
                      code: 502
                      message: Bad gateway.
                      param: null
                      type: cf_bad_gateway
          headers: {}
          x-apifox-name: 成功
      security: []
      x-apifox-folder: 文生文 对话生成
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/3216478/apis/api-106414419-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://yewu.bcwhkj.cn
    description: 正式环境
security: []

```
