Skip to content

Commit

Permalink
support multi-bot switching
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Apr 18, 2024
1 parent d54c483 commit 812788a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BOT_ID=
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"}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project converts the Coze API to the OpenAI API format, giving you access t
## Features
- Convert Coze API into an OpenAI API
- Support streaming and blocking
- Support Chatbots API on Coze
- Supports multi-robot switching

## Preparation
1. Register with [Coze](https://www.coze.com) and obtain your API token
Expand Down Expand Up @@ -61,7 +61,7 @@ const response = await fetch('http://localhost:3000/v1/chat/completions', {
'Authorization': 'Bearer YOUR_COZE_API_KEY',
},
body: JSON.stringify({
model: 'Coze',
model: 'model_name',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello, how are you?' },
Expand All @@ -78,21 +78,21 @@ This project provides some additional configuration items set with environment v
| Environment Variable | Required | Description | Example |
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `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"}`|

## Roadmap
**Coming Soon**
* Image support
* Audio-to-text
* Text-to-audio
* Docker support
* Workflow Bot
* Variables support

**Available Now**
* Continuous dialogue
* Multi-robot switching
* Workflow, Plugins, Knowledge base
* Continuous dialogue with the history of chat
* Zeabur & Vercel & Railway deployment
* Streaming & Blocking
* Plugins on Coze

## Contact
Feel free to reach out for any questions or feedback
Expand Down
26 changes: 16 additions & 10 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

该项目将 Coze API 转换为 OpenAI API 格式,使您可以在您喜爱的 OpenAI 客户端中访问 [Coze](https://www.coze.com) 的LLMs、知识库、插件和工作流程.

# 特点
- Coze API 转换为 OpenAI API
- 支持流式和阻塞
- 在 Coze 上支持 Chatbots API
# 功能
- 支持 Coze API 转换为 OpenAI API 格式
- 支持流式、非流式输出
- 支持多机器人快速切换

# 准备工作
1.[Coze](https://www.coze.com)注册并获取您的 API 令牌
Expand All @@ -31,6 +31,11 @@ https://www.coze.com/space/73428668341****/bot/73428668*****

**注意:** Vercel 的无服务器函数有 10 秒的超时限制


### Railway
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/yM5tQL?referralCode=mDim7U)


# 本地部署
1. 首先把`.env.template`文件复制改名为`.env`

Expand Down Expand Up @@ -58,7 +63,7 @@ const response = await fetch('http://localhost:3000/v1/chat/completions', {
'Authorization': 'Bearer YOUR_COZE_API_KEY',
},
body: JSON.stringify({
model: 'Coze',
model: 'model_name',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello, how are you?' },
Expand All @@ -74,22 +79,23 @@ console.log(data);

| 环境变量 | 必须的 | 描述 | 例子 |
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `BOT_ID` | Yes | 机器人的 ID。从 Coze 中机器人的开发页面 URL 获取它。 bot参数后面的数字是bot ID.| `73428668*****`|
| `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"}`|


# 路线图
**即将推出**
* 图像支持
* 音频转文字
* 文本转语音
* Docker 部署
* 工作流机器人
* 变量支持

**现在可用**
* 持续对话
* 多机器人切换
* 连续对话,有对话历史
* Zeabur&Vercel&Railway 部署
* 流式和非流式传输
* Coze 插件
* Workflow、插件、知识库

# 联系
如有任何问题或反馈,请随时联系
Expand Down
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ dotenv.config();

const app = express();
app.use(bodyParser.json());
const bot_id = process.env.BOT_ID || "";
const default_bot_id = process.env.BOT_ID || "";
const botConfig = process.env.BOT_CONFIG ? JSON.parse(process.env.BOT_CONFIG) : {};

app.get("/", (req, res) => {
res.send(`
Expand Down Expand Up @@ -42,6 +43,7 @@ app.post("/v1/chat/completions", async (req, res) => {
try {
const data = req.body;
const messages = data.messages;
const model = data.model;
const chatHistory = [];
for (let i = 0; i < messages.length - 1; i++) {
const message = messages[i];
Expand All @@ -59,6 +61,8 @@ app.post("/v1/chat/completions", async (req, res) => {
const queryString = lastMessage.content;
const stream = data.stream !== undefined ? data.stream : false;
let requestBody;
const bot_id = model && botConfig[model] ? botConfig[model] : default_bot_id;

requestBody = {
query: queryString,
stream: stream,
Expand Down

0 comments on commit 812788a

Please sign in to comment.