update qwen3-coder example

This commit is contained in:
musistudio
2025-07-25 17:19:52 +08:00
parent 179bab605e
commit 6883fff352
3 changed files with 124 additions and 119 deletions

223
README.md
View File

@@ -8,12 +8,12 @@
## ✨ Features ## ✨ Features
- **Model Routing**: Route requests to different models based on your needs (e.g., background tasks, thinking, long context). - **Model Routing**: Route requests to different models based on your needs (e.g., background tasks, thinking, long context).
- **Multi-Provider Support**: Supports various model providers like OpenRouter, DeepSeek, Ollama, Gemini, Volcengine, and SiliconFlow. - **Multi-Provider Support**: Supports various model providers like OpenRouter, DeepSeek, Ollama, Gemini, Volcengine, and SiliconFlow.
- **Request/Response Transformation**: Customize requests and responses for different providers using transformers. - **Request/Response Transformation**: Customize requests and responses for different providers using transformers.
- **Dynamic Model Switching**: Switch models on-the-fly within Claude Code using the `/model` command. - **Dynamic Model Switching**: Switch models on-the-fly within Claude Code using the `/model` command.
- **GitHub Actions Integration**: Trigger Claude Code tasks in your GitHub workflows. - **GitHub Actions Integration**: Trigger Claude Code tasks in your GitHub workflows.
- **Plugin System**: Extend functionality with custom transformers. - **Plugin System**: Extend functionality with custom transformers.
## 🚀 Getting Started ## 🚀 Getting Started
@@ -36,6 +36,7 @@ npm install -g @musistudio/claude-code-router
Create and configure your `~/.claude-code-router/config.json` file. For more details, you can refer to `config.example.json`. Create and configure your `~/.claude-code-router/config.json` file. For more details, you can refer to `config.example.json`.
The `config.json` file has several key sections: The `config.json` file has several key sections:
- **`PROXY_URL`** (optional): You can set a proxy for API requests, for example: `"PROXY_URL": "http://127.0.0.1:7890"`. - **`PROXY_URL`** (optional): You can set a proxy for API requests, for example: `"PROXY_URL": "http://127.0.0.1:7890"`.
- **`LOG`** (optional): You can enable logging by setting it to `true`. The log file will be located at `$HOME/.claude-code-router.log`. - **`LOG`** (optional): You can enable logging by setting it to `true`. The log file will be located at `$HOME/.claude-code-router.log`.
- **`APIKEY`** (optional): You can set a secret key to authenticate requests. When set, clients must provide this key in the `Authorization` header (e.g., `Bearer your-secret-key`) or the `x-api-key` header. Example: `"APIKEY": "your-secret-key"`. - **`APIKEY`** (optional): You can set a secret key to authenticate requests. When set, clients must provide this key in the `Authorization` header (e.g., `Bearer your-secret-key`) or the `x-api-key` header. Example: `"APIKEY": "your-secret-key"`.
@@ -112,9 +113,10 @@ Here is a comprehensive example:
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
}, },
@@ -128,9 +130,10 @@ Here is a comprehensive example:
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
} }
@@ -145,7 +148,6 @@ Here is a comprehensive example:
} }
``` ```
### 3. Running Claude Code with the Router ### 3. Running Claude Code with the Router
Start Claude Code using the router: Start Claude Code using the router:
@@ -155,6 +157,7 @@ ccr code
``` ```
> **Note**: After modifying the configuration file, you need to restart the service for the changes to take effect: > **Note**: After modifying the configuration file, you need to restart the service for the changes to take effect:
>
> ```shell > ```shell
> ccr restart > ccr restart
> ``` > ```
@@ -163,73 +166,74 @@ ccr code
The `Providers` array is where you define the different model providers you want to use. Each provider object requires: The `Providers` array is where you define the different model providers you want to use. Each provider object requires:
- `name`: A unique name for the provider. - `name`: A unique name for the provider.
- `api_base_url`: The full API endpoint for chat completions. - `api_base_url`: The full API endpoint for chat completions.
- `api_key`: Your API key for the provider. - `api_key`: Your API key for the provider.
- `models`: A list of model names available from this provider. - `models`: A list of model names available from this provider.
- `transformer` (optional): Specifies transformers to process requests and responses. - `transformer` (optional): Specifies transformers to process requests and responses.
#### Transformers #### Transformers
Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs. Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs.
- **Global Transformer**: Apply a transformer to all models from a provider. In this example, the `openrouter` transformer is applied to all models under the `openrouter` provider. - **Global Transformer**: Apply a transformer to all models from a provider. In this example, the `openrouter` transformer is applied to all models under the `openrouter` provider.
```json ```json
{ {
"name": "openrouter", "name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions", "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "sk-xxx", "api_key": "sk-xxx",
"models": [ "models": [
"google/gemini-2.5-pro-preview", "google/gemini-2.5-pro-preview",
"anthropic/claude-sonnet-4", "anthropic/claude-sonnet-4",
"anthropic/claude-3.5-sonnet" "anthropic/claude-3.5-sonnet"
], ],
"transformer": { "use": ["openrouter"] } "transformer": { "use": ["openrouter"] }
} }
``` ```
- **Model-Specific Transformer**: Apply a transformer to a specific model. In this example, the `deepseek` transformer is applied to all models, and an additional `tooluse` transformer is applied only to the `deepseek-chat` model. - **Model-Specific Transformer**: Apply a transformer to a specific model. In this example, the `deepseek` transformer is applied to all models, and an additional `tooluse` transformer is applied only to the `deepseek-chat` model.
```json
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": {
"use": ["deepseek"],
"deepseek-chat": { "use": ["tooluse"] }
}
}
```
- **Passing Options to a Transformer**: Some transformers, like `maxtoken`, accept options. To pass options, use a nested array where the first element is the transformer name and the second is an options object. ```json
```json {
{ "name": "deepseek",
"name": "siliconflow", "api_base_url": "https://api.deepseek.com/chat/completions",
"api_base_url": "https://api.siliconflow.cn/v1/chat/completions", "api_key": "sk-xxx",
"api_key": "sk-xxx", "models": ["deepseek-chat", "deepseek-reasoner"],
"models": ["moonshotai/Kimi-K2-Instruct"], "transformer": {
"transformer": { "use": ["deepseek"],
"use": [ "deepseek-chat": { "use": ["tooluse"] }
[
"maxtoken",
{
"max_tokens": 16384
}
]
]
}
} }
``` }
```
- **Passing Options to a Transformer**: Some transformers, like `maxtoken`, accept options. To pass options, use a nested array where the first element is the transformer name and the second is an options object.
```json
{
"name": "siliconflow",
"api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
"api_key": "sk-xxx",
"models": ["moonshotai/Kimi-K2-Instruct"],
"transformer": {
"use": [
[
"maxtoken",
{
"max_tokens": 16384
}
]
]
}
}
```
**Available Built-in Transformers:** **Available Built-in Transformers:**
- `deepseek`: Adapts requests/responses for DeepSeek API. - `deepseek`: Adapts requests/responses for DeepSeek API.
- `gemini`: Adapts requests/responses for Gemini API. - `gemini`: Adapts requests/responses for Gemini API.
- `openrouter`: Adapts requests/responses for OpenRouter API. - `openrouter`: Adapts requests/responses for OpenRouter API.
- `groq`: Adapts requests/responses for groq API. - `groq`: Adapts requests/responses for groq API.
- `maxtoken`: Sets a specific `max_tokens` value. - `maxtoken`: Sets a specific `max_tokens` value.
- `tooluse`: Optimizes tool usage for certain models via `tool_choice`. - `tooluse`: Optimizes tool usage for certain models via `tool_choice`.
- `gemini-cli` (experimental): Unofficial support for Gemini via Gemini CLI [gemini-cli.js](https://gist.github.com/musistudio/1c13a65f35916a7ab690649d3df8d1cd). - `gemini-cli` (experimental): Unofficial support for Gemini via Gemini CLI [gemini-cli.js](https://gist.github.com/musistudio/1c13a65f35916a7ab690649d3df8d1cd).
**Custom Transformers:** **Custom Transformers:**
@@ -238,12 +242,12 @@ You can also create your own transformers and load them via the `transformers` f
```json ```json
{ {
"transformers": [ "transformers": [
{ {
"path": "$HOME/.claude-code-router/plugins/gemini-cli.js", "path": "$HOME/.claude-code-router/plugins/gemini-cli.js",
"options": { "options": {
"project": "xxx" "project": "xxx"
}
} }
}
] ]
} }
``` ```
@@ -252,12 +256,11 @@ You can also create your own transformers and load them via the `transformers` f
The `Router` object defines which model to use for different scenarios: The `Router` object defines which model to use for different scenarios:
- `default`: The default model for general tasks. - `default`: The default model for general tasks.
- `background`: A model for background tasks. This can be a smaller, local model to save costs. - `background`: A model for background tasks. This can be a smaller, local model to save costs.
- `think`: A model for reasoning-heavy tasks, like Plan Mode. - `think`: A model for reasoning-heavy tasks, like Plan Mode.
- `longContext`: A model for handling long contexts (e.g., > 60K tokens). - `longContext`: A model for handling long contexts (e.g., > 60K tokens).
- `webSearch`: Used for handling web search tasks and this requires the model itself to support the feature. If you're using openrouter, you need to add the `:online` suffix after the model name. - `webSearch`: Used for handling web search tasks and this requires the model itself to support the feature. If you're using openrouter, you need to add the `:online` suffix after the model name.
You can also switch models dynamically in Claude Code with the `/model` command: You can also switch models dynamically in Claude Code with the `/model` command:
`/model provider_name,model_name` `/model provider_name,model_name`
@@ -290,11 +293,11 @@ Here is an example of a `custom-router.js` based on `custom-router.example.js`:
* @returns {Promise<string|null>} - A promise that resolves to the "provider,model_name" string, or null to use the default router. * @returns {Promise<string|null>} - A promise that resolves to the "provider,model_name" string, or null to use the default router.
*/ */
module.exports = async function router(req, config) { module.exports = async function router(req, config) {
const userMessage = req.body.messages.find(m => m.role === 'user')?.content; const userMessage = req.body.messages.find((m) => m.role === "user")?.content;
if (userMessage && userMessage.includes('explain this code')) { if (userMessage && userMessage.includes("explain this code")) {
// Use a powerful model for code explanation // Use a powerful model for code explanation
return 'openrouter,anthropic/claude-3.5-sonnet'; return "openrouter,anthropic/claude-3.5-sonnet";
} }
// Fallback to the default router configuration // Fallback to the default router configuration
@@ -302,7 +305,6 @@ module.exports = async function router(req, config) {
}; };
``` ```
## 🤖 GitHub Actions ## 🤖 GitHub Actions
Integrate Claude Code Router into your CI/CD pipeline. After setting up [Claude Code Actions](https://docs.anthropic.com/en/docs/claude-code/github-actions), modify your `.github/workflows/claude.yaml` to use the router: Integrate Claude Code Router into your CI/CD pipeline. After setting up [Claude Code Actions](https://docs.anthropic.com/en/docs/claude-code/github-actions), modify your `.github/workflows/claude.yaml` to use the router:
@@ -364,8 +366,8 @@ This setup allows for interesting automations, like running tasks during off-pea
## 📝 Further Reading ## 📝 Further Reading
- [Project Motivation and How It Works](blog/en/project-motivation-and-how-it-works.md) - [Project Motivation and How It Works](blog/en/project-motivation-and-how-it-works.md)
- [Maybe We Can Do More with the Router](blog/en/maybe-we-can-do-more-with-the-route.md) - [Maybe We Can Do More with the Router](blog/en/maybe-we-can-do-more-with-the-route.md)
## ❤️ Support & Sponsoring ## ❤️ Support & Sponsoring
@@ -387,39 +389,38 @@ A huge thank you to all our sponsors for their generous support!
- @Simon Leischnig - @Simon Leischnig
- [@duanshuaimin](https://github.com/duanshuaimin) - [@duanshuaimin](https://github.com/duanshuaimin)
- [@vrgitadmin](https://github.com/vrgitadmin) - [@vrgitadmin](https://github.com/vrgitadmin)
- @*o - @\*o
- [@ceilwoo](https://github.com/ceilwoo) - [@ceilwoo](https://github.com/ceilwoo)
- @*说 - @\*说
- @*更 - @\*更
- @K*g - @K\*g
- @R*R - @R\*R
- [@bobleer](https://github.com/bobleer) - [@bobleer](https://github.com/bobleer)
- @*苗 - @\*苗
- @*划 - @\*划
- [@Clarence-pan](https://github.com/Clarence-pan) - [@Clarence-pan](https://github.com/Clarence-pan)
- [@carter003](https://github.com/carter003) - [@carter003](https://github.com/carter003)
- @S*r - @S\*r
- @*晖 - @\*晖
- @*敏 - @\*敏
- @Z*z - @Z\*z
- @*然 - @\*然
- [@cluic](https://github.com/cluic) - [@cluic](https://github.com/cluic)
- @*苗 - @\*苗
- [@PromptExpert](https://github.com/PromptExpert) - [@PromptExpert](https://github.com/PromptExpert)
- @*应 - @\*应
- [@yusnake](https://github.com/yusnake) - [@yusnake](https://github.com/yusnake)
- @*飞 - @\*飞
- @董* - @董\*
- @*汀 - @\*汀
- @*涯 - @\*涯
- @*:- - @\*:-
- @**磊 - @\*\*磊
- @*琢 - @\*琢
- @*成 - @\*成
- @Z*o - @Z\*o
- @*琨 - @\*琨
- [@congzhangzh](https://github.com/congzhangzh) - [@congzhangzh](https://github.com/congzhangzh)
- @*_ - @\*\_
(If your name is masked, please contact me via my homepage email to update it with your GitHub username.) (If your name is masked, please contact me via my homepage email to update it with your GitHub username.)

View File

@@ -109,9 +109,10 @@ npm install -g @musistudio/claude-code-router
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
}, },
@@ -125,9 +126,10 @@ npm install -g @musistudio/claude-code-router
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
} }

View File

@@ -76,9 +76,10 @@
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
}, },
@@ -92,9 +93,10 @@
[ [
"maxtoken", "maxtoken",
{ {
"max_tokens": 8192 "max_tokens": 65536
} }
] ],
"enhancetool"
] ]
} }
} }