# 对话生成  JSON回复模式

## OpenAPI Specification

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




        :::highlight purple 💡

        此方法可强制规定返回内容必须符合json类型，这样可更有效的生成符合更为预期的数据结果，来实现与现有系统软件的有效结合

        :::

        - 启用限定Json格式的回复，必须注意两点，一个是提交的Messages里必须包含json示例，以及必须设定max_tokens。

        - 若不设定max_tokens，则模型可能会生成无休止的空格流，并且请求可能会持续运行，直到达到令牌限制。

        - JSON 模式不保证输出与任何特定架构匹配，只保证它是有效的并且解析没有错误。

        - 当前只有新版模型支持此模式：gpt-4o、gpt-4-turbo、gpt-3.5-turbo

        - 如果模型返回的消息中的 JSON
        可能是部分的（即截断），这表示超出了生成次数或会话超出了令牌限制。若要防止这种情况，请在分析响应之前进行检查。finish_reasonlength、max_tokens、finish_reason
        这三项值是否对应匹配完整度


        ### token获取方式：

        - 访问公众号《冰橙云》进入菜单冰橙AI助手后，访问右上角 / API密钥 可查看 token

        - 访问：https://yewu.bcwhkj.cn 》 个人 》API密钥 》Token令牌 
      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
                      content:
                        type: string
                    x-apifox-orders:
                      - role
                      - content
                model:
                  type: string
                  description: 模型名
                  enum:
                    - gpt-4o
                    - gpt-3.5-turbo
                  x-apifox:
                    enumDescriptions:
                      gpt-4o: ''
                      gpt-3.5-turbo: ''
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                  required:
                    - type
                  x-apifox-orders:
                    - type
                  description: 返回格式，固定值
                max_tokens:
                  type: integer
                  description: 返回令牌限制数
              required:
                - messages
                - model
                - response_format
                - max_tokens
              x-apifox-orders:
                - messages
                - model
                - response_format
                - max_tokens
            example:
              messages:
                - role: user
                  content: 三国里哪个武将的武力值最高，是多少?json:{武将:武将名;武力值:数字}
              model: gpt-3.5-turbo
              response_format:
                type: json_object
              max_tokens: 2000
      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:
                        index:
                          type: integer
                        message:
                          type: object
                          properties:
                            role:
                              type: string
                            content:
                              type: string
                          required:
                            - role
                            - content
                          x-apifox-orders:
                            - role
                            - content
                        finish_reason:
                          type: string
                      x-apifox-orders:
                        - index
                        - message
                        - 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
                  system_fingerprint:
                    type: string
                required:
                  - id
                  - object
                  - created
                  - model
                  - choices
                  - usage
                  - system_fingerprint
                x-apifox-orders:
                  - id
                  - object
                  - created
                  - model
                  - choices
                  - usage
                  - system_fingerprint
              examples:
                '1':
                  summary: 成功示例
                  value:
                    id: chatcmpl-8KTtjVPGpfrvNjXCklSnCGvxTCDsT
                    object: chat.completion
                    created: 1699892179
                    model: gpt-3.5-turbo-1106
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: '{"武将":"关羽","武力值":100}'
                        finish_reason: stop
                    usage:
                      prompt_tokens: 46
                      completion_tokens: 16
                      total_tokens: 62
                    system_fingerprint: fp_eeff13170a
                '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-124566820-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://yewu.bcwhkj.cn
    description: 正式环境
security: []

```
