百川智能
  1. 通用大模型
百川智能
  • 通用大模型
    • 接口说明
    • 同步接口
      POST
    • 同步请求知识库
      POST
    • 流式接口
      POST
  • 通用大模型(旧版)
    • 接口说明
    • 同步接口
      POST
    • 流式接口
      POST
  • 知识库
    • 创建知识库接口
      POST
    • 知识库检索接口
      GET
    • 修改知识库接口
      POST
    • 删除知识库接口
      DELETE
    • 知识库列表查询接口
      GET
    • 创建知识库文件接口
      POST
    • 知识库文件检索接口
      GET
    • 知识库文件删除接口
      DELETE
    • 知识库文件列表查询接口
      GET
  • 向量化模型
    • 单次请求
      POST
    • 批次请求
      POST
  • 文件管理
    • 文件列表查询
      GET
    • 文件上传接口
      POST
    • 文件删除接口
      DELETE
    • 文件检索接口
      POST
    • 文件下载接口
      GET
  • 财务相关
    • 发票
  1. 通用大模型

同步接口

开发环境
http://dev-cn.your-api-server.com
开发环境
http://dev-cn.your-api-server.com
POST
/v1/chat/completions
在使用 API 接口前,请先在百川 API 开放平台完成实名认证、充值、创建 APIkey 等流程,如下图所示
Alt text
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'http://dev-cn.your-api-server.com/v1/chat/completions' \
--header 'Authorization: Bearer ${api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
          "model": "Baichuan2-Turbo",
          "messages": [
            { "role": "user", "content": "我日薪8块钱,请问在闰年的二月,我月薪多少" }
          ],
          "temperature": 0.3,
          "stream": false
        }'
响应示例响应示例
{
  "id": "3213214123",
  "created": 1697932800,
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "首先,我们需要确定闰年的二月有多少天。闰年的二月有29天。\n\n然后,我们可以计算你的月薪:\n\n日薪 = 月薪 / (当月天数)\n\n所以,你的月薪 = 日薪 * 当月天数\n\n将数值代入公式:\n\n月薪 = 8元/天 * 29天 = 232元\n\n因此,你在闰年的二月的月薪是232元。"
      }
    }
  ],
  "model": "Baichuan2-Turbo",
  "object": "chat.completion",
  "usage": {
    "prompt_tokens": 17,
    "completion_tokens": 100,
    "total_tokens": 117
  }
}

请求参数

Header 参数
Content-Type
string 
响应的数据格式
必需
示例值:
application/json
Authorization
string 
必需
示例值:
Bearer ${api_key}
Body 参数application/json
model
string 
必需
使用的模型 ID,模型列表: Baichuan2-Turbo Baichuan2-Turbo-192k
messages
array [object {2}] 
必需
对话消息列表 (历史对话按从老到新顺序填入)
role
string 
可选
消息作者的角色,为以下其中之一 1. user 2. assistant
content
string 
消息内容
可选
temperature
number 
可选
取值范围: [.0f, 1.0f]。 多样性,越高,多样性越好, 缺省 0.3
stream
boolean 
可选
是否使用流式接口,默认值为 false
示例

返回响应

🟢200成功
application/json
Body
id
string 
必需
"Chat Complete"的唯一标识符
created
integer 
必需
创建聊天完成时的 Unix 时间戳(秒)
choices
array [object {3}] 
聊天完成选项的列表
必需
index
integer 
可选
choices 中对应的索引
finish_reason
string 
可选
模型停止生成 token 的原因,为以下值: 1. stop :模型达到自然停止点/用户 stop 指令 2. content_filter:被内容过滤器中过滤掉
message
object 
可选
模型生成的聊天完成消息
model
string 
用于完成聊天的模型
必需
object
string 
必需
始终为"chat.completion.chunk"
usage
object 
必需
完成请求的使用情况统计信息
prompt_tokens
integer 
必需
提示词中的 token 数
completion_tokens
integer 
必需
生成词中的 token 数
total_tokens
integer 
必需
会话的总 token 数
上一页
接口说明
下一页
同步请求知识库
Built with