base on Turn Coze API into OpenAI ## C2O **English** · [中文](README_CN.md) **Use Coze on your favorite OpenAI client.** This project converts the Coze API to the OpenAI API format, giving you access to [Coze](https://www.coze.com) LLMs, knowledge base, plugins, and workflows within your preferred OpenAI clients. ## Features - Convert Coze API into an OpenAI API - Support streaming and blocking - Supports multi-bot switching ## Preparation 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 ![cozeapi](pictures/api.png) 3. Obtain the bot's ID,the number after the bot parameter, and configure it as an environment variable ```bash https://www.coze.com/space/73428668341****/bot/73428668***** ``` ## Deployment ### Zeabur [![Deploy on Zeabur](https://zeabur.com/button.svg)](https://zeabur.com/templates/BZ515Z?referralCode=fatwang2) ### Vercel [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/fatwang2/coze2openai&env=BOT_ID&envDescription=COZE_BOT_ID) **Note:** Vercel's serverless functions have a 10-second timeout limit. ### Railway [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/yM5tQL?referralCode=mDim7U) ### Docker Deployment 1. Ensure Docker and Docker Compose are installed on your machine. 2. Clone the project repository: ``` git clone https://github.com/your-username/coze2openai.git cd coze2openai ``` 3. Create and configure the `.env` file: ``` cp .env.template .env ``` Edit the `.env` file and fill in your BOT_ID and other necessary configurations. 4. Build and start the Docker container: ``` docker-compose up -d ``` 5. Visit `http://localhost:3000` to confirm that the service is running correctly. To stop the service, run: ``` docker-compose down ``` Note: The Dockerfile uses Taobao NPM mirror, you can comment out or replace other different mirror: ```Dockerfile ENV NPM_CONFIG_REGISTRY=https://registry.npmmirror.com/ ENV PNPM_REGISTRY=https://registry.npmmirror.com/ ``` ### Local Deployment 1. Set the environment variable on `.env` file ```bash BOT_ID=xxxx ``` 2. Install dependencies ```bash pnpm install ``` 3. Run the project ```bash pnpm start ``` ## Usage 1. OpenAI Clients ![botgem](pictures/usage.png) 2. Code ```JavaScript 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); ``` ## Environment Variable This project provides some additional configuration items set with environment variables: | 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"}`| | `COZE_API_BASE` | No | Choose coze.com or coze.cn | `api.coze.com, api.coze.cn`| ## Roadmap **Coming Soon** * Image support * Audio-to-text * Text-to-audio **Available Now** * Coze.cn * Multi-bot switching * Workflow, Plugins, Knowledge base * Continuous dialogue with the history of chat * Zeabur & Vercel & Railway deployment * Streaming & Blocking * Docker deployment ## Contact Feel free to reach out for any questions or feedback [X](https://sum4all.site/twitter)\ [telegram](https://sum4all.site/telegram) <a href="https://www.buymeacoffee.com/fatwang2" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a> ## License This project is licensed under the MIT License. ", Assign "at most 3 tags" to the expected json: {"id":"9377","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"