标签搜索

目 录CONTENT

文章目录

将CozeApi转换为OpenAi的Api使用

沙漠渔
2024-05-25 09:42:06 / 0 评论 / 0 点赞 / 237 阅读 / 1,808 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2024-05-25,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

特别感谢@wren @CN_Free 还有其他一些大佬。

说明

这里只是给仓库增加了docker支持,修改了一下readme,未做其他修改。如果需要查看使用教程的,可以参考

https://linux.do/t/topic/96828

仓库地址:

https://github.com/forose/coze2openai

原仓库地址:

https://github.com/fatwang2/coze2openai

使用说明

  1. 仓库克隆到本地
  2. 修改.env环境变量 主要修改BOT_ID和COZE_API_BASE,COM是国际版收费,CN免费,有额度限制,自己选择。
  3. 构建本地镜像
cd coze2openai
docker build -t coze2openai .
  1. 启动容器
docker run -d -p 3000:3000   -v "$PWD/.env:/app/.env"   coze2openai 
  1. 浏览器访问http://localhost:3000 提示如下信息即表示正常
Coze2OpenAI
Congratulations! Your project has been successfully deployed.

用法

  1. 代码里直接调用
const response = await fetch('http://localhost:3000/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_COZE_API_KEY',
  },
  body: JSON.stringify({
    model: 'model_name',
    messages: [
      { role: 'system', content: 'You are a helpful assistant.' },
      { role: 'user', content: 'Hello, how are you?' },
    ],
  }),
});

const data = await response.json();
console.log(data);
  1. shell调用
curl --location 'http://localhost:3000/v1/chat/completions' --header 'Content-Type: application/json' --header 'Authorization: Bearer pat_key' --data '{
     "model": "gpt-4",
     "messages": [{"role": "user", "content": "你好!"}],
     "stream": false
   }'
  1. 增加到new_api等

渠道选择自定义渠道
base url填写http://localhost:3000/v1/chat/completions
分组随意,因为实际是通过.env控制的

调用测试

curl --location 'http://localhost:9301/v1/chat/completions' --header 'Content-Type: application/json' --header 'Authorization: Bearer sk-B8scKkvhaUKwVEXo09C2B23dF1Ed4f688243F2Df8f26F7B8' --data '{
     "model": "gpt-4",
     "messages": [{"role": "user", "content": "你好!"}],
     "stream": false
   }'

相关链接

https://linux.do/t/topic/96658

0
广告 广告

评论区