特别感谢@wren @CN_Free 还有其他一些大佬。
说明
这里只是给仓库增加了docker支持,修改了一下readme,未做其他修改。如果需要查看使用教程的,可以参考
https://linux.do/t/topic/96828
仓库地址:
https://github.com/forose/coze2openai
原仓库地址:
https://github.com/fatwang2/coze2openai
使用说明
- 仓库克隆到本地
- 修改.env环境变量 主要修改BOT_ID和COZE_API_BASE,COM是国际版收费,CN免费,有额度限制,自己选择。
- 构建本地镜像
cd coze2openai
docker build -t coze2openai .
- 启动容器
docker run -d -p 3000:3000 -v "$PWD/.env:/app/.env" coze2openai
- 浏览器访问http://localhost:3000 提示如下信息即表示正常
Coze2OpenAI
Congratulations! Your project has been successfully deployed.
用法
- 代码里直接调用
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);
- 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
}'
- 增加到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
}'
评论区