没腿的鸟 发表于 2024-8-18 11:07:24

Coze API接口实战应用

Coze API先容


[*]概述 Coze API作为Coze平台对外的桥梁,让开发者可以或许灵活地使用Coze的功能和服务,促进业务流程自动化和系统集成。它覆盖了从数据获取到智能交互的全方位功能,旨在提升工作服从和创造更多大概。
Coze API申请接入流程
1. 发现API
– 通过API HUB查找AI相干API,找到Coze API并跳转访问Coze官方网站,注册开发者账号,填写须要的个人信息和公司信息。

https://img-blog.csdnimg.cn/img_convert/aa536ddf0131785391a3f028f50b1a86.png
2. 创建应用与密钥


[*]登录到首页后创建Bot

https://img-blog.csdnimg.cn/img_convert/0425e9c07650ecab79ecb3d696800cf9.png

https://img-blog.csdnimg.cn/img_convert/0c662f2c084dcca643286ad78ebb57ad.png


[*]打开API令牌管理页面添加新令牌

https://img-blog.csdnimg.cn/img_convert/3370c554f1d0051987fa05ed6965d039.png
3. API配置
– 在个人访问令牌界面,配置所需API接口权限。

https://img-blog.csdnimg.cn/img_convert/0c662f2c084dcca643286ad78ebb57ad.png


[*]Coze API的使用限定
当前扣子 API 免费供开发者使用,每个空间的 API 请求限额如下:​
QPS (每秒发送的请求数):2​
QPM (每分钟发送的请求数):60​
QPD (每天发送的请求数):3000


[*]Coze API调用过程
发起对话
请求地址
POST https://api.coze.cn/open_api/v2/chat
curl --location --request POST 'https://api.coze.cn/open_api/v2/chat' \
--header 'Authorization: Bearer {{Personal_Access_Token}}' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.coze.cn' \
--header 'Connection: keep-alive' \
-d '{
    "conversation_id": "123",
    "bot_id": "{{Bot_Id}}",
    "user": "29032201862555",
    "query": "hello",
    "stream":flase
}'
{{Personal_Access_Token}}更换为前面申请的令牌
进入 Bot 的开发页面,开发页面 URL 中 bot 参数后的数字就是 Bot ID。例如https://www.coze.cn/space/73428668341****/bot/73428668*****,bot ID 为73428668*****。
示例

https://img-blog.csdnimg.cn/img_convert/532be51e5a5b450c075adbb8a1a3a33b.png
同时支持流式返回,仅需将stream参数置为ture

https://img-blog.csdnimg.cn/img_convert/5f57473fe994eb260a845c83b71c9dbb.png

https://img-blog.csdnimg.cn/img_convert/b2f8efd04bbdf11ab4683483f8d33603.png


[*]Coze API的相应
data:{"event":"message","message":{"role":"assistant","type":"answer","content":"Hello","content_type":"text","extra_info":null},"is_finish":false,"index":0,"conversation_id":"123"}

data:{"event":"message","message":{"role":"assistant","type":"answer","content":"!","content_type":"text","extra_info":null},"is_finish":false,"index":0,"conversation_id":"123"}

...

data:{"event":"message","message":{"role":"assistant","type":"answer","content":"","content_type":"text","extra_info":null},"is_finish":true,"index":0,"conversation_id":"123"}

data:{"event":"done"}
Coze API的协议和格式
Coze的API使用HTTPS协议,返回值为JSON格式。支持流式和非流式数据返回
本指南旨在资助开发者快速上手Coze API,相识从注册到现实调用的全过程,并把握其在差别场景下的应用,以充实发挥Coze平台的潜能。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Coze API接口实战应用