Skip to content

Commit

Permalink
support coze.cn
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed May 23, 2024
1 parent f7e9898 commit b457a62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BOT_ID=default_bot_id
BOT_CONFIG={"model_name_1": "bot_id_1", "model_name_2": "bot_id_2", "model_name_3": "bot_id_3"}
BOT_CONFIG={"model_name_1": "bot_id_1", "model_name_2": "bot_id_2", "model_name_3": "bot_id_3"}
COZE_API_BASE=api.coze.com
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project converts the Coze API to the OpenAI API format, giving you access t
- Supports multi-bot switching

## Preparation
1. Register with [Coze](https://www.coze.com) and obtain your API token
1. Register with [coze.com](https://www.coze.com) or [coze.cn](https://www.coze.cn)and obtain your API token
![cozeapitoken](pictures/token.png)

2. Create your bot and publish it to the API
Expand Down Expand Up @@ -85,6 +85,7 @@ This project provides some additional configuration items set with environment v
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `BOT_ID` | Yes | The ID of the bot. Obtain it from the Develop page URL of your bot in Coze. The number after the bot parameter is the bot ID.| `73428668*****`|
| `BOT_CONFIG` | No | Configure different models to correspond to different bot ids to enable fast bot switching on the client side. Models that are not included will request the default BOT_ID | `{"model_name_1": "bot_id_1", "model_name_2": "bot_id_2", "model_name_3": "bot_id_3"}`|
| `COZE_API_BASE` | No | Choose coze.com or coze.cn | `api.coze.com, api.coze.cn`|

## Roadmap
**Coming Soon**
Expand All @@ -94,6 +95,7 @@ This project provides some additional configuration items set with environment v
* Docker support

**Available Now**
* Coze.cn
* Multi-bot switching
* Workflow, Plugins, Knowledge base
* Continuous dialogue with the history of chat
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- 支持多机器人快速切换

# 准备工作
1.[Coze](https://www.coze.com)注册并获取您的 API 令牌
1.[coze.com](https://www.coze.com)[coze.cn](https://www.coze.cn)注册并获取您的 API 令牌
![cozeapitoken](pictures/token.png)

2. 创建您的机器人并发布到 API
Expand Down Expand Up @@ -87,6 +87,7 @@ console.log(data);
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `BOT_ID` | Yes | 机器人的 ID。从 Coze 中机器人的开发页面 URL 获取它。 bot参数后面的数字是bot id.| `73428668*****`|
| `BOT_CONFIG` | No | 配置模型和机器人ID的对应关系,实现在客户端切换模型来调用不同的机器人的效果。如果调用不在配置文件的模型,则走默认的BOT_ID| `{"model_name_1": "bot_id_1", "model_name_2": "bot_id_2", "model_name_3": "bot_id_3"}`|
| `COZE_API_BASE` | No | 选择coze.com或者coze.cn| `api.coze.com, api.coze.cn`|


# 路线图
Expand All @@ -97,6 +98,7 @@ console.log(data);
* Docker 部署

**现在可用**
* 支持 coze.cn
* 多机器人切换
* 连续对话,有对话历史
* Zeabur&Vercel&Railway 部署
Expand Down
5 changes: 3 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dotenv.config();

const app = express();
app.use(bodyParser.json());
const coze_api_base = process.env.COZE_API_BASE || "api.coze.com";
const default_bot_id = process.env.BOT_ID || "";
const botConfig = process.env.BOT_CONFIG ? JSON.parse(process.env.BOT_CONFIG) : {};
var corsHeaders = {
Expand Down Expand Up @@ -87,8 +88,8 @@ app.post("/v1/chat/completions", async (req, res) => {
bot_id: bot_id,
chat_history: chatHistory
};

const resp = await fetch("https://api.coze.com/open_api/v2/chat", {
const coze_api_url = `https://${coze_api_base}/open_api/v2/chat`;
const resp = await fetch(coze_api_url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit b457a62

Please sign in to comment.