mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-02-02 23:00:50 +08:00
init doc
This commit is contained in:
329
docs/i18n/zh-CN/code.json
Normal file
329
docs/i18n/zh-CN/code.json
Normal file
@@ -0,0 +1,329 @@
|
||||
{
|
||||
"theme.ErrorPageContent.title": {
|
||||
"message": "页面已崩溃。",
|
||||
"description": "The title of the fallback page when the page crashed"
|
||||
},
|
||||
"theme.BackToTopButton.buttonAriaLabel": {
|
||||
"message": "回到顶部",
|
||||
"description": "The ARIA label for the back to top button"
|
||||
},
|
||||
"theme.blog.archive.title": {
|
||||
"message": "历史博文",
|
||||
"description": "The page & hero title of the blog archive page"
|
||||
},
|
||||
"theme.blog.archive.description": {
|
||||
"message": "历史博文",
|
||||
"description": "The page & hero description of the blog archive page"
|
||||
},
|
||||
"theme.blog.paginator.navAriaLabel": {
|
||||
"message": "博文列表分页导航",
|
||||
"description": "The ARIA label for the blog pagination"
|
||||
},
|
||||
"theme.blog.paginator.newerEntries": {
|
||||
"message": "较新的博文",
|
||||
"description": "The label used to navigate to the newer blog posts page (previous page)"
|
||||
},
|
||||
"theme.blog.paginator.olderEntries": {
|
||||
"message": "较旧的博文",
|
||||
"description": "The label used to navigate to the older blog posts page (next page)"
|
||||
},
|
||||
"theme.blog.post.paginator.navAriaLabel": {
|
||||
"message": "博文分页导航",
|
||||
"description": "The ARIA label for the blog posts pagination"
|
||||
},
|
||||
"theme.blog.post.paginator.newerPost": {
|
||||
"message": "较新一篇",
|
||||
"description": "The blog post button label to navigate to the newer/previous post"
|
||||
},
|
||||
"theme.blog.post.paginator.olderPost": {
|
||||
"message": "较旧一篇",
|
||||
"description": "The blog post button label to navigate to the older/next post"
|
||||
},
|
||||
"theme.tags.tagsPageLink": {
|
||||
"message": "查看所有标签",
|
||||
"description": "The label of the link targeting the tag list page"
|
||||
},
|
||||
"theme.colorToggle.ariaLabel.mode.system": {
|
||||
"message": "system mode",
|
||||
"description": "The name for the system color mode"
|
||||
},
|
||||
"theme.colorToggle.ariaLabel.mode.light": {
|
||||
"message": "浅色模式",
|
||||
"description": "The name for the light color mode"
|
||||
},
|
||||
"theme.colorToggle.ariaLabel.mode.dark": {
|
||||
"message": "暗黑模式",
|
||||
"description": "The name for the dark color mode"
|
||||
},
|
||||
"theme.colorToggle.ariaLabel": {
|
||||
"message": "切换浅色/暗黑模式(当前为{mode})",
|
||||
"description": "The ARIA label for the color mode toggle"
|
||||
},
|
||||
"theme.docs.breadcrumbs.navAriaLabel": {
|
||||
"message": "页面路径",
|
||||
"description": "The ARIA label for the breadcrumbs"
|
||||
},
|
||||
"theme.docs.DocCard.categoryDescription.plurals": {
|
||||
"message": "{count} 个项目",
|
||||
"description": "The default description for a category card in the generated index about how many items this category includes"
|
||||
},
|
||||
"theme.docs.paginator.navAriaLabel": {
|
||||
"message": "文件选项卡",
|
||||
"description": "The ARIA label for the docs pagination"
|
||||
},
|
||||
"theme.docs.paginator.previous": {
|
||||
"message": "上一页",
|
||||
"description": "The label used to navigate to the previous doc"
|
||||
},
|
||||
"theme.docs.paginator.next": {
|
||||
"message": "下一页",
|
||||
"description": "The label used to navigate to the next doc"
|
||||
},
|
||||
"theme.docs.tagDocListPageTitle.nDocsTagged": {
|
||||
"message": "{count} 篇文档带有标签",
|
||||
"description": "Pluralized label for \"{count} docs tagged\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)"
|
||||
},
|
||||
"theme.docs.tagDocListPageTitle": {
|
||||
"message": "{nDocsTagged}「{tagName}」",
|
||||
"description": "The title of the page for a docs tag"
|
||||
},
|
||||
"theme.docs.versionBadge.label": {
|
||||
"message": "版本:{versionLabel}"
|
||||
},
|
||||
"theme.docs.versions.unreleasedVersionLabel": {
|
||||
"message": "此为 {siteTitle} {versionLabel} 版尚未发行的文档。",
|
||||
"description": "The label used to tell the user that he's browsing an unreleased doc version"
|
||||
},
|
||||
"theme.docs.versions.unmaintainedVersionLabel": {
|
||||
"message": "此为 {siteTitle} {versionLabel} 版的文档,现已不再积极维护。",
|
||||
"description": "The label used to tell the user that he's browsing an unmaintained doc version"
|
||||
},
|
||||
"theme.docs.versions.latestVersionSuggestionLabel": {
|
||||
"message": "最新的文档请参阅 {latestVersionLink} ({versionLabel})。",
|
||||
"description": "The label used to tell the user to check the latest version"
|
||||
},
|
||||
"theme.docs.versions.latestVersionLinkLabel": {
|
||||
"message": "最新版本",
|
||||
"description": "The label used for the latest version suggestion link label"
|
||||
},
|
||||
"theme.common.headingLinkTitle": {
|
||||
"message": "{heading}的直接链接",
|
||||
"description": "Title for link to heading"
|
||||
},
|
||||
"theme.common.editThisPage": {
|
||||
"message": "编辑此页",
|
||||
"description": "The link label to edit the current page"
|
||||
},
|
||||
"theme.lastUpdated.atDate": {
|
||||
"message": "于 {date} ",
|
||||
"description": "The words used to describe on which date a page has been last updated"
|
||||
},
|
||||
"theme.lastUpdated.byUser": {
|
||||
"message": "由 {user} ",
|
||||
"description": "The words used to describe by who the page has been last updated"
|
||||
},
|
||||
"theme.lastUpdated.lastUpdatedAtBy": {
|
||||
"message": "最后{byUser}{atDate}更新",
|
||||
"description": "The sentence used to display when a page has been last updated, and by who"
|
||||
},
|
||||
"theme.NotFound.title": {
|
||||
"message": "找不到页面",
|
||||
"description": "The title of the 404 page"
|
||||
},
|
||||
"theme.navbar.mobileVersionsDropdown.label": {
|
||||
"message": "选择版本",
|
||||
"description": "The label for the navbar versions dropdown on mobile view"
|
||||
},
|
||||
"theme.tags.tagsListLabel": {
|
||||
"message": "标签:",
|
||||
"description": "The label alongside a tag list"
|
||||
},
|
||||
"theme.AnnouncementBar.closeButtonAriaLabel": {
|
||||
"message": "关闭",
|
||||
"description": "The ARIA label for close button of announcement bar"
|
||||
},
|
||||
"theme.admonition.caution": {
|
||||
"message": "警告",
|
||||
"description": "The default label used for the Caution admonition (:::caution)"
|
||||
},
|
||||
"theme.admonition.danger": {
|
||||
"message": "危险",
|
||||
"description": "The default label used for the Danger admonition (:::danger)"
|
||||
},
|
||||
"theme.admonition.info": {
|
||||
"message": "信息",
|
||||
"description": "The default label used for the Info admonition (:::info)"
|
||||
},
|
||||
"theme.admonition.note": {
|
||||
"message": "备注",
|
||||
"description": "The default label used for the Note admonition (:::note)"
|
||||
},
|
||||
"theme.admonition.tip": {
|
||||
"message": "提示",
|
||||
"description": "The default label used for the Tip admonition (:::tip)"
|
||||
},
|
||||
"theme.admonition.warning": {
|
||||
"message": "注意",
|
||||
"description": "The default label used for the Warning admonition (:::warning)"
|
||||
},
|
||||
"theme.blog.sidebar.navAriaLabel": {
|
||||
"message": "最近博文导航",
|
||||
"description": "The ARIA label for recent posts in the blog sidebar"
|
||||
},
|
||||
"theme.DocSidebarItem.expandCategoryAriaLabel": {
|
||||
"message": "展开侧边栏分类 '{label}'",
|
||||
"description": "The ARIA label to expand the sidebar category"
|
||||
},
|
||||
"theme.DocSidebarItem.collapseCategoryAriaLabel": {
|
||||
"message": "折叠侧边栏分类 '{label}'",
|
||||
"description": "The ARIA label to collapse the sidebar category"
|
||||
},
|
||||
"theme.IconExternalLink.ariaLabel": {
|
||||
"message": "(opens in new tab)",
|
||||
"description": "The ARIA label for the external link icon"
|
||||
},
|
||||
"theme.NavBar.navAriaLabel": {
|
||||
"message": "主导航",
|
||||
"description": "The ARIA label for the main navigation"
|
||||
},
|
||||
"theme.NotFound.p1": {
|
||||
"message": "我们找不到您要找的页面。",
|
||||
"description": "The first paragraph of the 404 page"
|
||||
},
|
||||
"theme.NotFound.p2": {
|
||||
"message": "请联系原始链接来源网站的所有者,并告知他们链接已损坏。",
|
||||
"description": "The 2nd paragraph of the 404 page"
|
||||
},
|
||||
"theme.navbar.mobileLanguageDropdown.label": {
|
||||
"message": "选择语言",
|
||||
"description": "The label for the mobile language switcher dropdown"
|
||||
},
|
||||
"theme.TOCCollapsible.toggleButtonLabel": {
|
||||
"message": "本页总览",
|
||||
"description": "The label used by the button on the collapsible TOC component"
|
||||
},
|
||||
"theme.blog.post.readMore": {
|
||||
"message": "阅读更多",
|
||||
"description": "The label used in blog post item excerpts to link to full blog posts"
|
||||
},
|
||||
"theme.blog.post.readMoreLabel": {
|
||||
"message": "阅读 {title} 的全文",
|
||||
"description": "The ARIA label for the link to full blog posts from excerpts"
|
||||
},
|
||||
"theme.CodeBlock.copy": {
|
||||
"message": "复制",
|
||||
"description": "The copy button label on code blocks"
|
||||
},
|
||||
"theme.CodeBlock.copied": {
|
||||
"message": "复制成功",
|
||||
"description": "The copied button label on code blocks"
|
||||
},
|
||||
"theme.CodeBlock.copyButtonAriaLabel": {
|
||||
"message": "复制代码到剪贴板",
|
||||
"description": "The ARIA label for copy code blocks button"
|
||||
},
|
||||
"theme.CodeBlock.wordWrapToggle": {
|
||||
"message": "切换自动换行",
|
||||
"description": "The title attribute for toggle word wrapping button of code block lines"
|
||||
},
|
||||
"theme.blog.post.readingTime.plurals": {
|
||||
"message": "阅读需 {readingTime} 分钟",
|
||||
"description": "Pluralized label for \"{readingTime} min read\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)"
|
||||
},
|
||||
"theme.docs.breadcrumbs.home": {
|
||||
"message": "主页面",
|
||||
"description": "The ARIA label for the home page in the breadcrumbs"
|
||||
},
|
||||
"theme.docs.sidebar.navAriaLabel": {
|
||||
"message": "文档侧边栏",
|
||||
"description": "The ARIA label for the sidebar navigation"
|
||||
},
|
||||
"theme.docs.sidebar.collapseButtonTitle": {
|
||||
"message": "收起侧边栏",
|
||||
"description": "The title attribute for collapse button of doc sidebar"
|
||||
},
|
||||
"theme.docs.sidebar.collapseButtonAriaLabel": {
|
||||
"message": "收起侧边栏",
|
||||
"description": "The title attribute for collapse button of doc sidebar"
|
||||
},
|
||||
"theme.docs.sidebar.closeSidebarButtonAriaLabel": {
|
||||
"message": "关闭导航栏",
|
||||
"description": "The ARIA label for close button of mobile sidebar"
|
||||
},
|
||||
"theme.navbar.mobileDropdown.collapseButton.expandAriaLabel": {
|
||||
"message": "Expand the dropdown",
|
||||
"description": "The ARIA label of the button to expand the mobile dropdown navbar item"
|
||||
},
|
||||
"theme.navbar.mobileDropdown.collapseButton.collapseAriaLabel": {
|
||||
"message": "Collapse the dropdown",
|
||||
"description": "The ARIA label of the button to collapse the mobile dropdown navbar item"
|
||||
},
|
||||
"theme.docs.sidebar.toggleSidebarButtonAriaLabel": {
|
||||
"message": "切换导航栏",
|
||||
"description": "The ARIA label for hamburger menu button of mobile navigation"
|
||||
},
|
||||
"theme.docs.sidebar.expandButtonTitle": {
|
||||
"message": "展开侧边栏",
|
||||
"description": "The ARIA label and title attribute for expand button of doc sidebar"
|
||||
},
|
||||
"theme.docs.sidebar.expandButtonAriaLabel": {
|
||||
"message": "展开侧边栏",
|
||||
"description": "The ARIA label and title attribute for expand button of doc sidebar"
|
||||
},
|
||||
"theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel": {
|
||||
"message": "← 回到主菜单",
|
||||
"description": "The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)"
|
||||
},
|
||||
"theme.blog.post.plurals": {
|
||||
"message": "{count} 篇博文",
|
||||
"description": "Pluralized label for \"{count} posts\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)"
|
||||
},
|
||||
"theme.blog.tagTitle": {
|
||||
"message": "{nPosts} 含有标签「{tagName}」",
|
||||
"description": "The title of the page for a blog tag"
|
||||
},
|
||||
"theme.blog.author.pageTitle": {
|
||||
"message": "{authorName} - {nPosts}",
|
||||
"description": "The title of the page for a blog author"
|
||||
},
|
||||
"theme.blog.authorsList.pageTitle": {
|
||||
"message": "作者",
|
||||
"description": "The title of the authors page"
|
||||
},
|
||||
"theme.blog.authorsList.viewAll": {
|
||||
"message": "查看所有作者",
|
||||
"description": "The label of the link targeting the blog authors page"
|
||||
},
|
||||
"theme.blog.author.noPosts": {
|
||||
"message": "该作者尚未撰写任何文章。",
|
||||
"description": "The text for authors with 0 blog post"
|
||||
},
|
||||
"theme.contentVisibility.unlistedBanner.title": {
|
||||
"message": "未列出页",
|
||||
"description": "The unlisted content banner title"
|
||||
},
|
||||
"theme.contentVisibility.unlistedBanner.message": {
|
||||
"message": "此页面未列出。搜索引擎不会对其索引,只有拥有直接链接的用户才能访问。",
|
||||
"description": "The unlisted content banner message"
|
||||
},
|
||||
"theme.contentVisibility.draftBanner.title": {
|
||||
"message": "草稿页",
|
||||
"description": "The draft content banner title"
|
||||
},
|
||||
"theme.contentVisibility.draftBanner.message": {
|
||||
"message": "此页面是草稿,仅在开发环境中可见,不会包含在正式版本中。",
|
||||
"description": "The draft content banner message"
|
||||
},
|
||||
"theme.ErrorPageContent.tryAgain": {
|
||||
"message": "重试",
|
||||
"description": "The label of the button to try again rendering when the React error boundary captures an error"
|
||||
},
|
||||
"theme.common.skipToMainContent": {
|
||||
"message": "跳到主要内容",
|
||||
"description": "The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation"
|
||||
},
|
||||
"theme.tags.tagsPageTitle": {
|
||||
"message": "标签",
|
||||
"description": "The title of the tag list page"
|
||||
}
|
||||
}
|
||||
14
docs/i18n/zh-CN/docusaurus-plugin-content-blog/options.json
Normal file
14
docs/i18n/zh-CN/docusaurus-plugin-content-blog/options.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"title": {
|
||||
"message": "Blog",
|
||||
"description": "The title for the blog used in SEO"
|
||||
},
|
||||
"description": {
|
||||
"message": "Blog",
|
||||
"description": "The description for the blog used in SEO"
|
||||
},
|
||||
"sidebar.title": {
|
||||
"message": "Recent posts",
|
||||
"description": "The label for the left sidebar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
---
|
||||
id: advanced/agents
|
||||
title: Agent 系统
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# Agent 系统
|
||||
|
||||
使用 Agent 系统扩展功能。
|
||||
|
||||
## 什么是 Agent?
|
||||
|
||||
Agent 是可插拔的功能模块,可以:
|
||||
- 检测是否应处理请求
|
||||
- 修改请求
|
||||
- 提供自定义工具
|
||||
|
||||
## 内置 Agent
|
||||
|
||||
### Image Agent
|
||||
|
||||
通过检测请求中的图像 URL 或文件路径来处理图像相关任务。
|
||||
|
||||
当检测到图像相关内容时,Image Agent 会:
|
||||
1. 标记请求需要图像处理
|
||||
2. 添加图像分析工具到请求中
|
||||
3. 拦截工具调用事件
|
||||
4. 执行图像分析并返回结果
|
||||
|
||||
## Agent 配置
|
||||
|
||||
Agent 在服务器配置中配置并自动加载。
|
||||
|
||||
### 启用 Image Agent
|
||||
|
||||
Image Agent 内置于服务器中,无需额外配置。当请求包含图像内容时自动激活。
|
||||
|
||||
### 强制使用 Image Agent
|
||||
|
||||
如果您的模型不支持工具调用,可以在配置中设置 `config.forceUseImageAgent` 为 `true`:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"image": "gemini,gemini-2.5-pro"
|
||||
},
|
||||
"forceUseImageAgent": true
|
||||
}
|
||||
```
|
||||
|
||||
## Agent 工具调用流程
|
||||
|
||||
1. **检测阶段**:在 `preHandler` 钩子中检测并标记 agents
|
||||
2. **准备阶段**:将 agent 工具添加到请求中
|
||||
3. **拦截阶段**:在 `onSend` 钩子中拦截工具调用事件
|
||||
4. **执行阶段**:执行 agent 工具并发起新的 LLM 请求
|
||||
5. **返回阶段**:将结果流式返回
|
||||
|
||||
## Agent 类型定义
|
||||
|
||||
```typescript
|
||||
interface IAgent {
|
||||
name: string;
|
||||
shouldHandle: (req: any, config: any) => boolean;
|
||||
reqHandler: (req: any, config: any) => void;
|
||||
tools: Map<string, ITool>;
|
||||
}
|
||||
|
||||
interface ITool {
|
||||
name: string;
|
||||
description: string;
|
||||
input_schema: object;
|
||||
handler: (args: any, context: any) => Promise<any>;
|
||||
}
|
||||
```
|
||||
|
||||
## 创建自定义 Agent
|
||||
|
||||
自定义 Agent 支持正在开发中!
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 图像分析请求
|
||||
|
||||
当您发送包含图像的请求时:
|
||||
|
||||
```
|
||||
请分析这张图片:/path/to/image.png
|
||||
```
|
||||
|
||||
Image Agent 将:
|
||||
1. 检测到图像路径
|
||||
2. 添加图像分析工具
|
||||
3. 调用配置的图像处理模型
|
||||
4. 返回分析结果
|
||||
|
||||
### 路由到支持图像的模型
|
||||
|
||||
在配置中指定用于图像任务的模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"image": "gemini,gemini-2.5-pro"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- [预设](/zh/docs/advanced/presets) - 使用预定义配置
|
||||
- [自定义路由器](/zh/docs/advanced/custom-router) - 编写自定义路由逻辑
|
||||
@@ -0,0 +1,149 @@
|
||||
---
|
||||
id: advanced/custom-router
|
||||
title: 自定义路由器
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# 自定义路由器
|
||||
|
||||
使用 JavaScript 编写自己的路由逻辑。
|
||||
|
||||
## 创建自定义路由器
|
||||
|
||||
创建一个导出路由函数的 JavaScript 文件:
|
||||
|
||||
```javascript
|
||||
// custom-router.js
|
||||
module.exports = async function(req, config) {
|
||||
// 获取用户消息
|
||||
const userMessage = req.body.messages.find(m => m.role === 'user')?.content;
|
||||
|
||||
// 自定义逻辑
|
||||
if (userMessage && userMessage.includes('解释代码')) {
|
||||
return 'openrouter,anthropic/claude-3.5-sonnet';
|
||||
}
|
||||
|
||||
// 返回 null 以使用默认路由
|
||||
return null;
|
||||
};
|
||||
```
|
||||
|
||||
## 参数说明
|
||||
|
||||
路由函数接收以下参数:
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| `req` | object | 来自 Claude Code 的请求对象,包含请求体 |
|
||||
| `config` | object | 应用程序的配置对象 |
|
||||
|
||||
## 配置
|
||||
|
||||
在 `config.json` 中设置 `CUSTOM_ROUTER_PATH` 以使用您的自定义路由器:
|
||||
|
||||
```json
|
||||
{
|
||||
"CUSTOM_ROUTER_PATH": "/path/to/custom-router.js"
|
||||
}
|
||||
```
|
||||
|
||||
## 返回格式
|
||||
|
||||
路由函数应返回以下格式的字符串:
|
||||
|
||||
```
|
||||
{provider-name},{model-name}
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```
|
||||
deepseek,deepseek-chat
|
||||
```
|
||||
|
||||
如果返回 `null`,则回退到默认路由配置。
|
||||
|
||||
## 错误处理
|
||||
|
||||
如果路由函数抛出错误或返回无效格式,路由器将回退到默认路由配置。
|
||||
|
||||
## 示例:基于时间的路由
|
||||
|
||||
```javascript
|
||||
module.exports = async function(req, config) {
|
||||
const hour = new Date().getHours();
|
||||
|
||||
// 工作时间使用更快的模型
|
||||
if (hour >= 9 && hour <= 18) {
|
||||
return 'groq,llama-3.3-70b-versatile';
|
||||
}
|
||||
|
||||
// 非工作时间使用更强大的模型
|
||||
return 'deepseek,deepseek-chat';
|
||||
};
|
||||
```
|
||||
|
||||
## 示例:成本优化
|
||||
|
||||
```javascript
|
||||
module.exports = async function(req, config) {
|
||||
const userMessage = req.body.messages.find(m => m.role === 'user')?.content;
|
||||
|
||||
// 简单任务使用较便宜的模型
|
||||
if (userMessage && userMessage.length < 100) {
|
||||
return 'groq,llama-3.3-70b-versatile';
|
||||
}
|
||||
|
||||
// 复杂任务使用默认模型
|
||||
return null;
|
||||
};
|
||||
```
|
||||
|
||||
## 示例:任务类型路由
|
||||
|
||||
```javascript
|
||||
module.exports = async function(req, config) {
|
||||
const userMessage = req.body.messages.find(m => m.role === 'user')?.content;
|
||||
|
||||
if (!userMessage) return null;
|
||||
|
||||
// 代码相关任务
|
||||
if (userMessage.includes('代码') || userMessage.includes('code')) {
|
||||
return 'deepseek,deepseek-coder';
|
||||
}
|
||||
|
||||
// 解释任务
|
||||
if (userMessage.includes('解释') || userMessage.includes('explain')) {
|
||||
return 'openrouter,anthropic/claude-3.5-sonnet';
|
||||
}
|
||||
|
||||
// 默认
|
||||
return null;
|
||||
};
|
||||
```
|
||||
|
||||
## 测试您的路由器
|
||||
|
||||
通过检查日志来测试您的自定义路由器:
|
||||
|
||||
```bash
|
||||
tail -f ~/.claude-code-router/claude-code-router.log
|
||||
```
|
||||
|
||||
查找路由决策以查看正在选择哪个模型。
|
||||
|
||||
## 子代理路由
|
||||
|
||||
对于子代理内的路由,您必须在子代理提示词的**开头**包含 `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` 来指定特定的提供商和模型。
|
||||
|
||||
**示例:**
|
||||
|
||||
```
|
||||
<CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
|
||||
请帮我分析这段代码是否存在潜在的优化空间...
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- [Agent](/zh/docs/advanced/agents) - 使用 Agent 扩展功能
|
||||
- [预设](/zh/docs/advanced/presets) - 使用预定义配置
|
||||
@@ -0,0 +1,174 @@
|
||||
---
|
||||
id: advanced/presets
|
||||
title: 预设配置
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# 预设配置
|
||||
|
||||
使用预定义配置进行快速设置。
|
||||
|
||||
## 什么是预设?
|
||||
|
||||
预设是预配置的设置,包括针对特定用例优化的提供商配置、路由规则和转换器。
|
||||
|
||||
## 可用预设
|
||||
|
||||
### Development(开发)
|
||||
|
||||
针对软件开发任务优化:
|
||||
- 快速响应时间
|
||||
- 适合代码生成
|
||||
- 成本效益高
|
||||
|
||||
配置特点:
|
||||
- 使用轻量级模型处理后台任务
|
||||
- 为代码任务选择专用模型
|
||||
- 优化的超时设置
|
||||
|
||||
### Research(研究)
|
||||
|
||||
针对研究和分析优化:
|
||||
- 支持长上下文
|
||||
- 高质量响应
|
||||
- 更强大的模型
|
||||
|
||||
配置特点:
|
||||
- 使用具有大上下文窗口的模型
|
||||
- 为分析任务选择高级模型
|
||||
- 较长的超时时间
|
||||
|
||||
### Balanced(平衡)
|
||||
|
||||
在速度和质量之间取得平衡:
|
||||
- 良好的通用性能
|
||||
- 合理的成本
|
||||
- 广泛的模型支持
|
||||
|
||||
配置特点:
|
||||
- 混合使用快速和高质量的模型
|
||||
- 适合大多数日常任务
|
||||
- 平衡的成本效益
|
||||
|
||||
## 使用预设
|
||||
|
||||
使用 CLI 应用预设:
|
||||
|
||||
```bash
|
||||
ccr preset apply development
|
||||
```
|
||||
|
||||
列出可用预设:
|
||||
|
||||
```bash
|
||||
ccr preset list
|
||||
```
|
||||
|
||||
## 创建自定义预设
|
||||
|
||||
您可以通过保存配置并稍后重新加载来创建自定义预设:
|
||||
|
||||
```bash
|
||||
# 将当前配置保存为预设
|
||||
ccr preset save my-preset
|
||||
|
||||
# 加载已保存的预设
|
||||
ccr preset apply my-preset
|
||||
```
|
||||
|
||||
## 预设管理
|
||||
|
||||
### 列出所有预设
|
||||
|
||||
```bash
|
||||
ccr preset list
|
||||
```
|
||||
|
||||
输出示例:
|
||||
|
||||
```
|
||||
可用预设:
|
||||
development - 开发优化配置
|
||||
research - 研究优化配置
|
||||
balanced - 平衡配置
|
||||
my-preset - 自定义预设
|
||||
```
|
||||
|
||||
### 应用预设
|
||||
|
||||
```bash
|
||||
ccr preset apply <预设名称>
|
||||
```
|
||||
|
||||
应用预设后,服务器将自动重启以加载新配置。
|
||||
|
||||
### 删除预设
|
||||
|
||||
```bash
|
||||
ccr preset delete <预设名称>
|
||||
```
|
||||
|
||||
## 预设文件位置
|
||||
|
||||
预设保存在:
|
||||
|
||||
```
|
||||
~/.claude-code-router/presets/
|
||||
```
|
||||
|
||||
每个预设都是一个 JSON 文件,包含完整的配置。
|
||||
|
||||
## 预设文件示例
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "development",
|
||||
"description": "针对软件开发优化的配置",
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "$DEEPSEEK_API_KEY",
|
||||
"models": ["deepseek-chat", "deepseek-coder"]
|
||||
},
|
||||
{
|
||||
"name": "groq",
|
||||
"api_base_url": "https://api.groq.com/openai/v1/chat/completions",
|
||||
"api_key": "$GROQ_API_KEY",
|
||||
"models": ["llama-3.3-70b-versatile"]
|
||||
}
|
||||
],
|
||||
"Router": {
|
||||
"default": "deepseek,deepseek-chat",
|
||||
"background": "groq,llama-3.3-70b-versatile",
|
||||
"think": "deepseek,deepseek-chat"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 导出和导入预设
|
||||
|
||||
### 导出当前配置
|
||||
|
||||
```bash
|
||||
ccr config show > my-config.json
|
||||
```
|
||||
|
||||
### 导入配置
|
||||
|
||||
```bash
|
||||
ccr config edit
|
||||
# 然后粘贴导入的配置
|
||||
```
|
||||
|
||||
## 最佳实践
|
||||
|
||||
1. **为不同项目创建预设**:为不同的工作流程创建专门的预设
|
||||
2. **版本控制**:将常用预设保存在版本控制中
|
||||
3. **文档化**:为自定义预设添加描述
|
||||
4. **测试**:在应用预设后验证配置
|
||||
|
||||
## 下一步
|
||||
|
||||
- [CLI 参考](/zh/docs/cli/start) - 完整的 CLI 命令参考
|
||||
- [配置](/zh/docs/config/basic) - 详细配置指南
|
||||
128
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/model.md
Normal file
128
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/model.md
Normal file
@@ -0,0 +1,128 @@
|
||||
---
|
||||
id: cli/model
|
||||
title: ccr model
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# ccr model
|
||||
|
||||
交互式模型选择和配置。
|
||||
|
||||
## 用法
|
||||
|
||||
```bash
|
||||
ccr model [命令]
|
||||
```
|
||||
|
||||
## 命令
|
||||
|
||||
### 选择模型
|
||||
|
||||
交互式选择模型:
|
||||
|
||||
```bash
|
||||
ccr model
|
||||
```
|
||||
|
||||
这将显示一个包含可用提供商和模型的交互式菜单。
|
||||
|
||||
### 设置默认模型
|
||||
|
||||
直接设置默认模型:
|
||||
|
||||
```bash
|
||||
ccr model set <provider>,<model>
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
ccr model set deepseek,deepseek-chat
|
||||
```
|
||||
|
||||
### 列出模型
|
||||
|
||||
列出所有配置的模型:
|
||||
|
||||
```bash
|
||||
ccr model list
|
||||
```
|
||||
|
||||
### 添加模型
|
||||
|
||||
添加新模型到配置:
|
||||
|
||||
```bash
|
||||
ccr model add <provider>,<model>
|
||||
```
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
ccr model add groq,llama-3.3-70b-versatile
|
||||
```
|
||||
|
||||
### 删除模型
|
||||
|
||||
从配置中删除模型:
|
||||
|
||||
```bash
|
||||
ccr model remove <provider>,<model>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 交互式选择
|
||||
|
||||
```bash
|
||||
$ ccr model
|
||||
|
||||
? 选择一个提供商: deepseek
|
||||
? 选择一个模型: deepseek-chat
|
||||
|
||||
默认模型设置为: deepseek,deepseek-chat
|
||||
```
|
||||
|
||||
### 直接配置
|
||||
|
||||
```bash
|
||||
ccr model set deepseek,deepseek-chat
|
||||
```
|
||||
|
||||
### 查看当前配置
|
||||
|
||||
```bash
|
||||
ccr model list
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```
|
||||
已配置的模型:
|
||||
deepseek,deepseek-chat (默认)
|
||||
groq,llama-3.3-70b-versatile
|
||||
gemini,gemini-2.5-pro
|
||||
```
|
||||
|
||||
## 交互式功能
|
||||
|
||||
`ccr model` 命令提供以下功能:
|
||||
|
||||
1. **查看当前配置**:查看所有已配置的模型和路由器设置
|
||||
2. **切换模型**:快速更改每个路由器类型使用的模型
|
||||
3. **添加新模型**:向现有提供商添加模型
|
||||
4. **创建新提供商**:设置完整的提供商配置,包括:
|
||||
- 提供商名称和 API 端点
|
||||
- API 密钥
|
||||
- 可用模型
|
||||
- 转换器配置,支持:
|
||||
- 多个转换器(openrouter、deepseek、gemini 等)
|
||||
- 转换器选项(例如,带自定义限制的 maxtoken)
|
||||
- 提供商特定路由(例如,OpenRouter 提供商偏好)
|
||||
|
||||
CLI 工具会验证所有输入并提供有用的提示来引导您完成配置过程,使管理复杂设置变得容易,无需手动编辑 JSON 文件。
|
||||
|
||||
## 相关命令
|
||||
|
||||
- [ccr start](/zh/docs/cli/start) - 启动服务器
|
||||
- [ccr config](/zh/docs/cli/other-commands#ccr-config) - 编辑配置
|
||||
@@ -0,0 +1,203 @@
|
||||
---
|
||||
id: cli/other-commands
|
||||
title: 其他命令
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
# 其他命令
|
||||
|
||||
管理 Claude Code Router 的其他 CLI 命令。
|
||||
|
||||
## ccr stop
|
||||
|
||||
停止运行中的服务器。
|
||||
|
||||
```bash
|
||||
ccr stop
|
||||
```
|
||||
|
||||
## ccr restart
|
||||
|
||||
重启服务器。
|
||||
|
||||
```bash
|
||||
ccr restart
|
||||
```
|
||||
|
||||
## ccr code
|
||||
|
||||
通过路由器执行 claude 命令。
|
||||
|
||||
```bash
|
||||
ccr code [参数...]
|
||||
```
|
||||
|
||||
## ccr activate
|
||||
|
||||
输出 shell 环境变量以供集成使用。
|
||||
|
||||
```bash
|
||||
ccr activate
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_URL="http://localhost:3456/v1"
|
||||
export ANTHROPIC_API_KEY="sk-xxxxx"
|
||||
```
|
||||
|
||||
在 shell 中使用:
|
||||
|
||||
```bash
|
||||
eval "$(ccr activate)"
|
||||
```
|
||||
|
||||
`activate` 命令设置以下环境变量:
|
||||
|
||||
- `ANTHROPIC_AUTH_TOKEN`: 来自配置的 API 密钥
|
||||
- `ANTHROPIC_BASE_URL`: 本地路由器端点(默认:`http://127.0.0.1:3456`)
|
||||
- `NO_PROXY`: 设置为 `127.0.0.1` 以防止代理干扰
|
||||
- `DISABLE_TELEMETRY`: 禁用遥测
|
||||
- `DISABLE_COST_WARNINGS`: 禁用成本警告
|
||||
- `API_TIMEOUT_MS`: 来自配置的 API 超时时间
|
||||
|
||||
## ccr ui
|
||||
|
||||
在浏览器中打开 Web UI。
|
||||
|
||||
```bash
|
||||
ccr ui
|
||||
```
|
||||
|
||||
## ccr statusline
|
||||
|
||||
集成状态栏(从 stdin 读取 JSON)。
|
||||
|
||||
```bash
|
||||
echo '{"status":"running"}' | ccr statusline
|
||||
```
|
||||
|
||||
## ccr config
|
||||
|
||||
配置管理命令。
|
||||
|
||||
### 编辑配置
|
||||
|
||||
```bash
|
||||
ccr config edit
|
||||
```
|
||||
|
||||
在默认编辑器中打开配置文件。
|
||||
|
||||
### 验证配置
|
||||
|
||||
```bash
|
||||
ccr config validate
|
||||
```
|
||||
|
||||
验证当前配置文件。
|
||||
|
||||
### 显示配置
|
||||
|
||||
```bash
|
||||
ccr config show
|
||||
```
|
||||
|
||||
显示当前配置(敏感值已隐藏)。
|
||||
|
||||
## ccr preset
|
||||
|
||||
预设管理命令。
|
||||
|
||||
### 列出预设
|
||||
|
||||
```bash
|
||||
ccr preset list
|
||||
```
|
||||
|
||||
### 应用预设
|
||||
|
||||
```bash
|
||||
ccr preset apply <名称>
|
||||
```
|
||||
|
||||
### 保存预设
|
||||
|
||||
```bash
|
||||
ccr preset save <名称>
|
||||
```
|
||||
|
||||
保存当前配置为预设。
|
||||
|
||||
## ccr log
|
||||
|
||||
查看服务器日志。
|
||||
|
||||
```bash
|
||||
ccr log [选项]
|
||||
```
|
||||
|
||||
选项:
|
||||
- `-f, --follow`: 跟踪日志输出(类似 `tail -f`)
|
||||
- `-n <行数>`: 显示的行数
|
||||
|
||||
## 全局选项
|
||||
|
||||
这些选项可用于任何命令:
|
||||
|
||||
| 选项 | 说明 |
|
||||
|------|------|
|
||||
| `-h, --help` | 显示帮助 |
|
||||
| `-v, --version` | 显示版本号 |
|
||||
| `--config <路径>` | 配置文件路径 |
|
||||
| `--verbose` | 启用详细输出 |
|
||||
|
||||
## 示例
|
||||
|
||||
### 停止服务器
|
||||
|
||||
```bash
|
||||
ccr stop
|
||||
```
|
||||
|
||||
### 使用自定义配置重启
|
||||
|
||||
```bash
|
||||
ccr restart --config /path/to/config.json
|
||||
```
|
||||
|
||||
### 查看并设置环境变量
|
||||
|
||||
```bash
|
||||
eval "$(ccr activate)"
|
||||
```
|
||||
|
||||
### 打开 Web UI
|
||||
|
||||
```bash
|
||||
ccr ui
|
||||
```
|
||||
|
||||
### 跟踪日志
|
||||
|
||||
```bash
|
||||
ccr log -f
|
||||
```
|
||||
|
||||
### 列出可用预设
|
||||
|
||||
```bash
|
||||
ccr preset list
|
||||
```
|
||||
|
||||
### 应用预设
|
||||
|
||||
```bash
|
||||
ccr preset apply development
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [入门](/zh/docs/intro) - Claude Code Router 简介
|
||||
- [配置](/zh/docs/config/basic) - 配置指南
|
||||
83
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/start.md
Normal file
83
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/start.md
Normal file
@@ -0,0 +1,83 @@
|
||||
---
|
||||
id: cli/start
|
||||
title: ccr start
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# ccr start
|
||||
|
||||
启动 Claude Code Router 服务器。
|
||||
|
||||
## 用法
|
||||
|
||||
```bash
|
||||
ccr start [选项]
|
||||
```
|
||||
|
||||
## 选项
|
||||
|
||||
| 选项 | 别名 | 说明 |
|
||||
|------|------|------|
|
||||
| `--port <number>` | `-p` | 监听端口号(默认:3456) |
|
||||
| `--config <path>` | `-c` | 配置文件路径 |
|
||||
| `--daemon` | `-d` | 作为守护进程运行(后台进程) |
|
||||
| `--log-level <level>` | `-l` | 日志级别(fatal/error/warn/info/debug/trace) |
|
||||
|
||||
## 示例
|
||||
|
||||
### 使用默认设置启动
|
||||
|
||||
```bash
|
||||
ccr start
|
||||
```
|
||||
|
||||
### 在自定义端口启动
|
||||
|
||||
```bash
|
||||
ccr start --port 3000
|
||||
```
|
||||
|
||||
### 使用自定义配置启动
|
||||
|
||||
```bash
|
||||
ccr start --config /path/to/config.json
|
||||
```
|
||||
|
||||
### 作为守护进程启动
|
||||
|
||||
```bash
|
||||
ccr start --daemon
|
||||
```
|
||||
|
||||
### 启用调试日志
|
||||
|
||||
```bash
|
||||
ccr start --log-level debug
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
您也可以使用环境变量配置服务器:
|
||||
|
||||
| 变量 | 说明 |
|
||||
|------|------|
|
||||
| `PORT` | 监听端口号 |
|
||||
| `CONFIG_PATH` | 配置文件路径 |
|
||||
| `LOG_LEVEL` | 日志级别 |
|
||||
| `CUSTOM_ROUTER_PATH` | 自定义路由器函数路径 |
|
||||
| `HOST` | 绑定主机地址(默认:0.0.0.0) |
|
||||
|
||||
## 输出
|
||||
|
||||
启动成功后,您将看到:
|
||||
|
||||
```
|
||||
Claude Code Router is running on http://localhost:3456
|
||||
API endpoint: http://localhost:3456/v1
|
||||
```
|
||||
|
||||
## 相关命令
|
||||
|
||||
- [ccr stop](/zh/docs/cli/other-commands#ccr-stop) - 停止服务器
|
||||
- [ccr restart](/zh/docs/cli/other-commands#ccr-restart) - 重启服务器
|
||||
- [ccr status](/zh/docs/cli/other-commands#ccr-status) - 检查服务器状态
|
||||
64
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/status.md
Normal file
64
docs/i18n/zh-CN/docusaurus-plugin-content-docs/cli/status.md
Normal file
@@ -0,0 +1,64 @@
|
||||
---
|
||||
id: cli/status
|
||||
title: ccr status
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# ccr status
|
||||
|
||||
显示 Claude Code Router 服务器的当前状态。
|
||||
|
||||
## 用法
|
||||
|
||||
```bash
|
||||
ccr status
|
||||
```
|
||||
|
||||
## 输出
|
||||
|
||||
### 运行中的服务器
|
||||
|
||||
当服务器正在运行时:
|
||||
|
||||
```
|
||||
Claude Code Router 状态: 运行中
|
||||
版本: 2.0.0
|
||||
PID: 12345
|
||||
端口: 3456
|
||||
运行时间: 2小时34分钟
|
||||
配置: /home/user/.claude-code-router/config.json
|
||||
```
|
||||
|
||||
### 已停止的服务器
|
||||
|
||||
当服务器未运行时:
|
||||
|
||||
```
|
||||
Claude Code Router 状态: 已停止
|
||||
```
|
||||
|
||||
## 退出代码
|
||||
|
||||
| 代码 | 说明 |
|
||||
|------|------|
|
||||
| 0 | 服务器正在运行 |
|
||||
| 1 | 服务器已停止 |
|
||||
| 2 | 检查状态时出错 |
|
||||
|
||||
## 示例
|
||||
|
||||
```bash
|
||||
$ ccr status
|
||||
|
||||
Claude Code Router 状态: 运行中
|
||||
版本: 2.0.0
|
||||
PID: 12345
|
||||
端口: 3456
|
||||
运行时间: 2小时34分钟
|
||||
```
|
||||
|
||||
## 相关命令
|
||||
|
||||
- [ccr start](/zh/docs/cli/start) - 启动服务器
|
||||
- [ccr stop](/zh/docs/cli/other-commands#ccr-stop) - 停止服务器
|
||||
- [ccr restart](/zh/docs/cli/other-commands#ccr-restart) - 重启服务器
|
||||
161
docs/i18n/zh-CN/docusaurus-plugin-content-docs/config/basic.md
Normal file
161
docs/i18n/zh-CN/docusaurus-plugin-content-docs/config/basic.md
Normal file
@@ -0,0 +1,161 @@
|
||||
---
|
||||
id: config/basic
|
||||
title: 基础配置
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# 基础配置
|
||||
|
||||
学习如何配置 Claude Code Router 以满足您的需求。
|
||||
|
||||
## 配置文件位置
|
||||
|
||||
配置文件位于:
|
||||
|
||||
```
|
||||
~/.claude-code-router/config.json
|
||||
```
|
||||
|
||||
## 配置结构
|
||||
|
||||
### Providers(提供商)
|
||||
|
||||
配置 LLM 提供商以将请求路由到:
|
||||
|
||||
```json
|
||||
{
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["deepseek-chat", "deepseek-coder"]
|
||||
},
|
||||
{
|
||||
"name": "groq",
|
||||
"api_base_url": "https://api.groq.com/openai/v1/chat/completions",
|
||||
"api_key": "your-groq-api-key",
|
||||
"models": ["llama-3.3-70b-versatile"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Router(路由器)
|
||||
|
||||
配置默认使用的模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"default": "deepseek,deepseek-chat"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
格式:`{provider-name},{model-name}`
|
||||
|
||||
### Transformers(转换器)
|
||||
|
||||
对请求/响应应用转换:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformers": [
|
||||
{
|
||||
"path": "/path/to/custom-transformer.js",
|
||||
"options": {
|
||||
"key": "value"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 环境变量
|
||||
|
||||
在配置中使用环境变量:
|
||||
|
||||
```json
|
||||
{
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "$DEEPSEEK_API_KEY"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
同时支持 `$VAR_NAME` 和 `${VAR_NAME}` 语法。
|
||||
|
||||
## 完整示例
|
||||
|
||||
```json
|
||||
{
|
||||
"PORT": 8080,
|
||||
"APIKEY": "your-secret-key",
|
||||
"PROXY_URL": "http://127.0.0.1:7890",
|
||||
"LOG": true,
|
||||
"LOG_LEVEL": "debug",
|
||||
"API_TIMEOUT_MS": 600000,
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "$DEEPSEEK_API_KEY",
|
||||
"models": ["deepseek-chat", "deepseek-coder"],
|
||||
"transformer": {
|
||||
"use": ["deepseek"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "groq",
|
||||
"api_base_url": "https://api.groq.com/openai/v1/chat/completions",
|
||||
"api_key": "$GROQ_API_KEY",
|
||||
"models": ["llama-3.3-70b-versatile"]
|
||||
}
|
||||
],
|
||||
"Router": {
|
||||
"default": "deepseek,deepseek-chat",
|
||||
"longContextThreshold": 100000,
|
||||
"background": "groq,llama-3.3-70b-versatile"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 编辑配置
|
||||
|
||||
使用 CLI 编辑配置:
|
||||
|
||||
```bash
|
||||
ccr config edit
|
||||
```
|
||||
|
||||
这将在您的默认编辑器中打开配置文件。
|
||||
|
||||
## 重新加载配置
|
||||
|
||||
编辑配置后,重启路由器:
|
||||
|
||||
```bash
|
||||
ccr restart
|
||||
```
|
||||
|
||||
## 配置选项说明
|
||||
|
||||
- **PORT**: 服务器端口号(默认:3456)
|
||||
- **APIKEY**: API 密钥,用于身份验证
|
||||
- **HOST**: 服务器监听地址(默认:127.0.0.1,如果配置了 Providers 且没有设置 APIKEY,则强制为 127.0.0.1)
|
||||
- **PROXY_URL**: 代理服务器地址
|
||||
- **LOG**: 是否启用日志(默认:true)
|
||||
- **LOG_LEVEL**: 日志级别(fatal/error/warn/info/debug/trace)
|
||||
- **API_TIMEOUT_MS**: API 请求超时时间(毫秒)
|
||||
- **NON_INTERACTIVE_MODE**: 非交互模式(用于 CI/CD 环境)
|
||||
|
||||
## 下一步
|
||||
|
||||
- [提供商配置](/zh/docs/config/providers) - 详细的提供商配置
|
||||
- [路由配置](/zh/docs/config/routing) - 配置路由规则
|
||||
- [转换器](/zh/docs/config/transformers) - 应用转换
|
||||
@@ -0,0 +1,213 @@
|
||||
---
|
||||
id: config/providers
|
||||
title: 提供商配置
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# 提供商配置
|
||||
|
||||
配置 LLM 提供商的详细指南。
|
||||
|
||||
## 支持的提供商
|
||||
|
||||
### DeepSeek
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["deepseek-chat", "deepseek-coder", "deepseek-reasoner"],
|
||||
"transformer": {
|
||||
"use": ["deepseek"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Groq
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "groq",
|
||||
"api_base_url": "https://api.groq.com/openai/v1/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["llama-3.3-70b-versatile"]
|
||||
}
|
||||
```
|
||||
|
||||
### Gemini
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "gemini",
|
||||
"api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["gemini-2.5-flash", "gemini-2.5-pro"],
|
||||
"transformer": {
|
||||
"use": ["gemini"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### OpenRouter
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "openrouter",
|
||||
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": [
|
||||
"anthropic/claude-3.5-sonnet",
|
||||
"google/gemini-2.5-pro-preview"
|
||||
],
|
||||
"transformer": {
|
||||
"use": ["openrouter"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Ollama(本地模型)
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "ollama",
|
||||
"api_base_url": "http://localhost:11434/v1/chat/completions",
|
||||
"api_key": "ollama",
|
||||
"models": ["qwen2.5-coder:latest"]
|
||||
}
|
||||
```
|
||||
|
||||
### 火山引擎
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "volcengine",
|
||||
"api_base_url": "https://ark.cn-beijing.volces.com/api/v3/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["deepseek-v3-250324", "deepseek-r1-250528"],
|
||||
"transformer": {
|
||||
"use": ["deepseek"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ModelScope
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "modelscope",
|
||||
"api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions",
|
||||
"api_key": "",
|
||||
"models": [
|
||||
"Qwen/Qwen3-Coder-480B-A35B-Instruct",
|
||||
"Qwen/Qwen3-235B-A22B-Thinking-2507"
|
||||
],
|
||||
"transformer": {
|
||||
"use": [
|
||||
["maxtoken", { "max_tokens": 65536 }],
|
||||
"enhancetool"
|
||||
],
|
||||
"Qwen/Qwen3-235B-A22B-Thinking-2507": {
|
||||
"use": ["reasoning"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### DashScope(阿里云)
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dashscope",
|
||||
"api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"models": ["qwen3-coder-plus"],
|
||||
"transformer": {
|
||||
"use": [
|
||||
["maxtoken", { "max_tokens": 65536 }],
|
||||
"enhancetool"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 提供商配置选项
|
||||
|
||||
| 字段 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| `name` | string | 是 | 提供商的唯一标识符 |
|
||||
| `api_base_url` | string | 是 | API 基础 URL |
|
||||
| `api_key` | string | 是 | API 认证密钥 |
|
||||
| `models` | string[] | 否 | 可用模型列表 |
|
||||
| `transformer` | object | 否 | 应用的转换器配置 |
|
||||
|
||||
## 模型选择
|
||||
|
||||
在路由中选择模型时,使用以下格式:
|
||||
|
||||
```
|
||||
{provider-name},{model-name}
|
||||
```
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
deepseek,deepseek-chat
|
||||
```
|
||||
|
||||
## 使用环境变量
|
||||
|
||||
您可以在配置中使用环境变量来保护 API 密钥:
|
||||
|
||||
```json
|
||||
{
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "$DEEPSEEK_API_KEY",
|
||||
"models": ["deepseek-chat"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
支持 `$VAR_NAME` 和 `${VAR_NAME}` 两种语法。
|
||||
|
||||
## 转换器配置
|
||||
|
||||
转换器用于适配不同提供商的 API 差异。您可以在提供商级别或模型级别配置转换器:
|
||||
|
||||
### 提供商级别转换器
|
||||
|
||||
应用于提供商的所有模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "openrouter",
|
||||
"transformer": {
|
||||
"use": ["openrouter"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 模型级别转换器
|
||||
|
||||
应用于特定模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "deepseek",
|
||||
"transformer": {
|
||||
"use": ["deepseek"],
|
||||
"deepseek-chat": {
|
||||
"use": ["tooluse"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- [路由配置](/zh/docs/config/routing) - 配置请求如何路由
|
||||
- [转换器](/zh/docs/config/transformers) - 对请求应用转换
|
||||
165
docs/i18n/zh-CN/docusaurus-plugin-content-docs/config/routing.md
Normal file
165
docs/i18n/zh-CN/docusaurus-plugin-content-docs/config/routing.md
Normal file
@@ -0,0 +1,165 @@
|
||||
---
|
||||
id: config/routing
|
||||
title: 路由配置
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# 路由配置
|
||||
|
||||
配置如何将请求路由到不同的模型。
|
||||
|
||||
## 默认路由
|
||||
|
||||
为所有请求设置默认模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"default": "deepseek,deepseek-chat"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 内置场景
|
||||
|
||||
### 后台任务
|
||||
|
||||
将后台任务路由到轻量级模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"background": "groq,llama-3.3-70b-versatile"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 思考模式(计划模式)
|
||||
|
||||
将思考密集型任务路由到更强大的模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"think": "deepseek,deepseek-reasoner"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 长上下文
|
||||
|
||||
路由长上下文请求:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"longContextThreshold": 100000,
|
||||
"longContext": "gemini,gemini-2.5-pro"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 网络搜索
|
||||
|
||||
路由网络搜索任务:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"webSearch": "gemini,gemini-2.5-flash"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 图像任务
|
||||
|
||||
路由图像相关任务:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"image": "gemini,gemini-2.5-pro"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 项目级路由
|
||||
|
||||
在 `~/.claude/projects/<project-id>/claude-code-router.json` 中为每个项目配置路由:
|
||||
|
||||
```json
|
||||
{
|
||||
"Router": {
|
||||
"default": "groq,llama-3.3-70b-versatile"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
项目级配置优先于全局配置。
|
||||
|
||||
## 自定义路由器
|
||||
|
||||
创建自定义 JavaScript 路由器函数:
|
||||
|
||||
1. 创建路由器文件(例如 `custom-router.js`):
|
||||
|
||||
```javascript
|
||||
module.exports = async function(req, config) {
|
||||
// 分析请求上下文
|
||||
const userMessage = req.body.messages.find(m => m.role === 'user')?.content;
|
||||
|
||||
// 自定义路由逻辑
|
||||
if (userMessage && userMessage.includes('解释代码')) {
|
||||
return 'openrouter,anthropic/claude-3.5-sonnet';
|
||||
}
|
||||
|
||||
// 返回 null 以使用默认路由
|
||||
return null;
|
||||
};
|
||||
```
|
||||
|
||||
2. 在 `config.json` 中设置 `CUSTOM_ROUTER_PATH`:
|
||||
|
||||
```json
|
||||
{
|
||||
"CUSTOM_ROUTER_PATH": "/path/to/custom-router.js"
|
||||
}
|
||||
```
|
||||
|
||||
## Token 计数
|
||||
|
||||
路由器使用 `tiktoken` (cl100k_base) 来估算请求 token 数量。这用于:
|
||||
|
||||
- 确定请求是否超过 `longContextThreshold`
|
||||
- 基于 token 数量的自定义路由逻辑
|
||||
|
||||
## 子代理路由
|
||||
|
||||
使用特殊标签为子代理指定模型:
|
||||
|
||||
```
|
||||
<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>
|
||||
请帮我分析这段代码...
|
||||
```
|
||||
|
||||
## 动态模型切换
|
||||
|
||||
在 Claude Code 中使用 `/model` 命令动态切换模型:
|
||||
|
||||
```
|
||||
/model provider_name,model_name
|
||||
```
|
||||
|
||||
示例:`/model openrouter,anthropic/claude-3.5-sonnet`
|
||||
|
||||
## 路由优先级
|
||||
|
||||
1. 项目级配置
|
||||
2. 自定义路由器
|
||||
3. 内置场景路由
|
||||
4. 默认路由
|
||||
|
||||
## 下一步
|
||||
|
||||
- [转换器](/zh/docs/config/transformers) - 对请求应用转换
|
||||
- [自定义路由器](/zh/docs/advanced/custom-router) - 高级自定义路由
|
||||
@@ -0,0 +1,283 @@
|
||||
---
|
||||
id: config/transformers
|
||||
title: 转换器
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
# 转换器
|
||||
|
||||
转换器用于适配不同提供商之间的 API 差异。
|
||||
|
||||
## 内置转换器
|
||||
|
||||
### anthropic
|
||||
|
||||
将请求转换为兼容 Anthropic 风格的 API:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["anthropic"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果只使用这一个转换器,它将直接透传请求和响应(您可以用来接入其他支持 Anthropic 端点的服务商)。
|
||||
|
||||
### deepseek
|
||||
|
||||
专门用于 DeepSeek API 的转换器:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["deepseek"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### gemini
|
||||
|
||||
用于 Google Gemini API 的转换器:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["gemini"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### groq
|
||||
|
||||
用于 Groq API 的转换器:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["groq"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### openrouter
|
||||
|
||||
用于 OpenRouter API 的转换器:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["openrouter"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
OpenRouter 转换器还支持 `provider` 路由参数,以指定 OpenRouter 应使用哪些底层提供商:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["openrouter"],
|
||||
"moonshotai/kimi-k2": {
|
||||
"use": [
|
||||
["openrouter", {
|
||||
"provider": {
|
||||
"only": ["moonshotai/fp8"]
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### maxtoken
|
||||
|
||||
设置特定的 `max_tokens` 值:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": [
|
||||
["maxtoken", { "max_tokens": 65536 }]
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### tooluse
|
||||
|
||||
通过 `tool_choice` 参数优化某些模型的工具使用:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["tooluse"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### reasoning
|
||||
|
||||
用于处理 `reasoning_content` 字段:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["reasoning"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### sampling
|
||||
|
||||
用于处理采样信息字段,如 `temperature`、`top_p`、`top_k` 和 `repetition_penalty`:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["sampling"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### enhancetool
|
||||
|
||||
对 LLM 返回的工具调用参数增加一层容错处理(注意:这会导致不再流式返回工具调用信息):
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["enhancetool"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### cleancache
|
||||
|
||||
清除请求中的 `cache_control` 字段:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["cleancache"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### vertex-gemini
|
||||
|
||||
处理使用 Vertex 鉴权的 Gemini API:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": ["vertex-gemini"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 应用转换器
|
||||
|
||||
### 全局应用
|
||||
|
||||
应用于提供商的所有请求:
|
||||
|
||||
```json
|
||||
{
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "your-api-key",
|
||||
"transformer": {
|
||||
"use": ["deepseek"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 模型特定应用
|
||||
|
||||
应用于特定模型:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "deepseek",
|
||||
"transformer": {
|
||||
"use": ["deepseek"],
|
||||
"deepseek-chat": {
|
||||
"use": ["tooluse"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 传递选项
|
||||
|
||||
某些转换器接受选项:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformer": {
|
||||
"use": [
|
||||
["maxtoken", { "max_tokens": 8192 }]
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 自定义转换器
|
||||
|
||||
创建自定义转换器插件:
|
||||
|
||||
1. 创建转换器文件:
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
name: 'my-transformer',
|
||||
transformRequest: async (req, config) => {
|
||||
// 修改请求
|
||||
return req;
|
||||
},
|
||||
transformResponse: async (res, config) => {
|
||||
// 修改响应
|
||||
return res;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
2. 在配置中加载:
|
||||
|
||||
```json
|
||||
{
|
||||
"transformers": [
|
||||
{
|
||||
"path": "/path/to/transformer.js",
|
||||
"options": {
|
||||
"key": "value"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 实验性转换器
|
||||
|
||||
### gemini-cli(实验性)
|
||||
|
||||
通过 Gemini CLI 对 Gemini 的非官方支持。
|
||||
|
||||
### qwen-cli(实验性)
|
||||
|
||||
通过 Qwen CLI 对 qwen3-coder-plus 的非官方支持。
|
||||
|
||||
### rovo-cli(实验性)
|
||||
|
||||
通过 Atlassian Rovo Dev CLI 对 GPT-5 的非官方支持。
|
||||
|
||||
## 下一步
|
||||
|
||||
- [高级主题](/zh/docs/advanced/custom-router) - 高级路由自定义
|
||||
- [Agent](/zh/docs/advanced/agents) - 使用 Agent 扩展功能
|
||||
54
docs/i18n/zh-CN/docusaurus-plugin-content-docs/current.json
Normal file
54
docs/i18n/zh-CN/docusaurus-plugin-content-docs/current.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"version.label": {
|
||||
"message": "Next",
|
||||
"description": "The label for version current"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Getting Started": {
|
||||
"message": "Getting Started",
|
||||
"description": "The label for category 'Getting Started' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Getting Started.link.generated-index.title": {
|
||||
"message": "Getting Started",
|
||||
"description": "The generated-index page title for category 'Getting Started' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Getting Started.link.generated-index.description": {
|
||||
"message": "Learn the basics of Claude Code Router",
|
||||
"description": "The generated-index page description for category 'Getting Started' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Configuration": {
|
||||
"message": "Configuration",
|
||||
"description": "The label for category 'Configuration' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Configuration.link.generated-index.title": {
|
||||
"message": "Configuration",
|
||||
"description": "The generated-index page title for category 'Configuration' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Configuration.link.generated-index.description": {
|
||||
"message": "Configure Claude Code Router to suit your needs",
|
||||
"description": "The generated-index page description for category 'Configuration' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Advanced": {
|
||||
"message": "Advanced",
|
||||
"description": "The label for category 'Advanced' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Advanced.link.generated-index.title": {
|
||||
"message": "Advanced Topics",
|
||||
"description": "The generated-index page title for category 'Advanced' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.Advanced.link.generated-index.description": {
|
||||
"message": "Advanced features and customization",
|
||||
"description": "The generated-index page description for category 'Advanced' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.CLI Reference": {
|
||||
"message": "CLI Reference",
|
||||
"description": "The label for category 'CLI Reference' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.CLI Reference.link.generated-index.title": {
|
||||
"message": "CLI Commands",
|
||||
"description": "The generated-index page title for category 'CLI Reference' in sidebar 'tutorialSidebar'"
|
||||
},
|
||||
"sidebar.tutorialSidebar.category.CLI Reference.link.generated-index.description": {
|
||||
"message": "Complete reference for all CLI commands",
|
||||
"description": "The generated-index page description for category 'CLI Reference' in sidebar 'tutorialSidebar'"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
id: installation
|
||||
title: 安装
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# 安装
|
||||
|
||||
使用您喜欢的包管理器全局安装 Claude Code Router。
|
||||
|
||||
## 前置要求
|
||||
|
||||
- **Node.js**: >= 18.0.0
|
||||
- **pnpm**: >= 8.0.0(如果使用 pnpm)
|
||||
- 来自您偏好的 LLM 提供商的 API 密钥
|
||||
|
||||
## 通过 npm 安装
|
||||
|
||||
```bash
|
||||
npm install -g @musistudio/claude-code-router-cli
|
||||
```
|
||||
|
||||
## 通过 pnpm 安装
|
||||
|
||||
```bash
|
||||
pnpm add -g @musistudio/claude-code-router-cli
|
||||
```
|
||||
|
||||
## 通过 Yarn 安装
|
||||
|
||||
```bash
|
||||
yarn global add @musistudio/claude-code-router-cli
|
||||
```
|
||||
|
||||
## 验证安装
|
||||
|
||||
安装完成后,验证 `ccr` 命令是否可用:
|
||||
|
||||
```bash
|
||||
ccr --version
|
||||
```
|
||||
|
||||
您应该看到版本号显示。
|
||||
|
||||
## 下一步
|
||||
|
||||
安装完成后,前往 [快速开始](/zh/docs/quick-start) 了解如何配置和使用路由器。
|
||||
71
docs/i18n/zh-CN/docusaurus-plugin-content-docs/intro.md
Normal file
71
docs/i18n/zh-CN/docusaurus-plugin-content-docs/intro.md
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
id: intro
|
||||
title: 欢迎使用 Claude Code Router
|
||||
sidebar_position: 1
|
||||
slug: /
|
||||
---
|
||||
|
||||
# 欢迎使用 Claude Code Router
|
||||
|
||||
[](https://www.npmjs.com/package/@musistudio/claude-code-router-cli)
|
||||

|
||||

|
||||
|
||||
**Claude Code Router** 是一个强大的工具,允许你在没有 Anthropic 账户的情况下使用 [Claude Code](https://claude.ai/code),并将请求路由到其他 LLM 提供商。
|
||||
|
||||
## 特性
|
||||
|
||||
- **多提供商支持**: 路由到 DeepSeek、Gemini、Groq、OpenRouter 等
|
||||
- **智能路由**: 内置不同任务类型的场景(后台、思考、网络搜索、图像)
|
||||
- **项目级配置**: 每个项目自定义路由
|
||||
- **自定义路由函数**: 编写 JavaScript 定义自己的路由逻辑
|
||||
- **转换器系统**: 无缝适配不同提供商之间的 API 差异
|
||||
- **代理系统**: 可扩展的插件架构,实现自定义功能
|
||||
- **Web UI**: 内置管理界面,方便配置
|
||||
- **CLI 集成**: 与现有的 Claude Code 工作流无缝集成
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 安装
|
||||
|
||||
```bash
|
||||
npm install -g @musistudio/claude-code-router-cli
|
||||
# 或
|
||||
pnpm add -g @musistudio/claude-code-router-cli
|
||||
# 或
|
||||
yarn global add @musistudio/claude-code-router-cli
|
||||
```
|
||||
|
||||
### 基本使用
|
||||
|
||||
```bash
|
||||
# 启动路由器服务器
|
||||
ccr start
|
||||
|
||||
# 配置 Claude Code 使用路由器
|
||||
export ANTHROPIC_API_URL="http://localhost:8080/v1"
|
||||
export ANTHROPIC_API_KEY="your-api-key"
|
||||
|
||||
# 现在可以正常使用 Claude Code!
|
||||
claude code
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- [安装指南](/docs/installation) - 详细安装说明
|
||||
- [快速开始](/docs/quick-start) - 5 分钟入门
|
||||
- [配置](/docs/config/basic) - 了解如何配置路由器
|
||||
- [CLI 参考](/docs/cli/start) - 完整的 CLI 命令参考
|
||||
|
||||
## 架构
|
||||
|
||||
Claude Code Router 由四个主要组件组成:
|
||||
|
||||
- **CLI** (`@musistudio/claude-code-router-cli`): 提供 `ccr` 命令的命令行工具
|
||||
- **Server** (`@musistudio/claude-code-router-server`): 处理 API 路由和转换的核心服务器
|
||||
- **Shared** (`@musistudio/claude-code-router-shared`): 共享常量和工具
|
||||
- **UI** (`@musistudio/claude-code-router-ui`): Web 管理界面(React + Vite)
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT © [musistudio](https://github.com/musistudio)
|
||||
@@ -0,0 +1,83 @@
|
||||
---
|
||||
id: quick-start
|
||||
title: 快速开始
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# 快速开始
|
||||
|
||||
5 分钟内启动并运行 Claude Code Router。
|
||||
|
||||
## 1. 启动路由器
|
||||
|
||||
```bash
|
||||
ccr start
|
||||
```
|
||||
|
||||
路由器默认将在 `http://localhost:8080` 上启动。
|
||||
|
||||
## 2. 配置环境变量
|
||||
|
||||
在您的 shell 中设置以下环境变量:
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_API_URL="http://localhost:8080/v1"
|
||||
export ANTHROPIC_API_KEY="your-provider-api-key"
|
||||
```
|
||||
|
||||
或者使用 `ccr activate` 命令获取环境变量:
|
||||
|
||||
```bash
|
||||
eval "$(ccr activate)"
|
||||
```
|
||||
|
||||
## 3. 使用 Claude Code
|
||||
|
||||
现在您可以正常使用 Claude Code:
|
||||
|
||||
```bash
|
||||
claude code
|
||||
```
|
||||
|
||||
您的请求将通过 Claude Code Router 路由到您配置的提供商。
|
||||
|
||||
## 4. 配置提供商(可选)
|
||||
|
||||
要配置多个提供商或自定义路由,使用:
|
||||
|
||||
```bash
|
||||
ccr model
|
||||
```
|
||||
|
||||
这将打开一个交互式菜单来选择和配置模型。
|
||||
|
||||
或者直接编辑配置文件:
|
||||
|
||||
```bash
|
||||
# 在默认编辑器中打开配置
|
||||
ccr config edit
|
||||
```
|
||||
|
||||
配置文件示例 (`~/.claude-code-router/config.json`):
|
||||
|
||||
```json
|
||||
{
|
||||
"Providers": [
|
||||
{
|
||||
"name": "deepseek",
|
||||
"api_base_url": "https://api.deepseek.com/chat/completions",
|
||||
"api_key": "your-deepseek-api-key",
|
||||
"models": ["deepseek-chat", "deepseek-coder"]
|
||||
}
|
||||
],
|
||||
"Router": {
|
||||
"default": "deepseek,deepseek-chat"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
- [基础配置](/zh/docs/config/basic) - 了解配置选项
|
||||
- [路由配置](/zh/docs/config/routing) - 配置智能路由规则
|
||||
- [CLI 命令](/zh/docs/cli/start) - 探索所有 CLI 命令
|
||||
50
docs/i18n/zh-CN/docusaurus-theme-classic/footer.json
Normal file
50
docs/i18n/zh-CN/docusaurus-theme-classic/footer.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"link.title.Documentation": {
|
||||
"message": "文档",
|
||||
"description": "The title of the footer links column with title=Documentation in the footer"
|
||||
},
|
||||
"link.title.Community": {
|
||||
"message": "社区",
|
||||
"description": "The title of the footer links column with title=Community in the footer"
|
||||
},
|
||||
"link.title.Resources": {
|
||||
"message": "资源",
|
||||
"description": "The title of the footer links column with title=Resources in the footer"
|
||||
},
|
||||
"link.item.label.Introduction": {
|
||||
"message": "简介",
|
||||
"description": "The label of footer link with label=Introduction linking to /docs/intro"
|
||||
},
|
||||
"link.item.label.Installation": {
|
||||
"message": "安装",
|
||||
"description": "The label of footer link with label=Installation linking to /docs/cli/installation"
|
||||
},
|
||||
"link.item.label.Quick Start": {
|
||||
"message": "快速开始",
|
||||
"description": "The label of footer link with label=Quick Start linking to /docs/cli/quick-start"
|
||||
},
|
||||
"link.item.label.GitHub": {
|
||||
"message": "GitHub",
|
||||
"description": "The label of footer link with label=GitHub linking to https://github.com/musistudio/claude-code-router"
|
||||
},
|
||||
"link.item.label.Issues": {
|
||||
"message": "问题反馈",
|
||||
"description": "The label of footer link with label=Issues linking to https://github.com/musistudio/claude-code-router/issues"
|
||||
},
|
||||
"link.item.label.Releases": {
|
||||
"message": "发布版本",
|
||||
"description": "The label of footer link with label=Releases linking to https://github.com/musistudio/claude-code-router/releases"
|
||||
},
|
||||
"link.item.label.Blog": {
|
||||
"message": "博客",
|
||||
"description": "The label of footer link with label=Blog linking to /blog"
|
||||
},
|
||||
"link.item.label.NPM Package": {
|
||||
"message": "NPM 包",
|
||||
"description": "The label of footer link with label=NPM Package linking to https://www.npmjs.com/package/@musistudio/claude-code-router-cli"
|
||||
},
|
||||
"copyright": {
|
||||
"message": "Copyright © 2025 Claude Code Router. 保留所有权利。",
|
||||
"description": "The footer copyright"
|
||||
}
|
||||
}
|
||||
22
docs/i18n/zh-CN/docusaurus-theme-classic/navbar.json
Normal file
22
docs/i18n/zh-CN/docusaurus-theme-classic/navbar.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"title": {
|
||||
"message": "Claude Code Router",
|
||||
"description": "The title in the navbar"
|
||||
},
|
||||
"logo.alt": {
|
||||
"message": "Claude Code Router Logo",
|
||||
"description": "The alt text of navbar logo"
|
||||
},
|
||||
"item.label.Documentation": {
|
||||
"message": "Documentation",
|
||||
"description": "Navbar item with label Documentation"
|
||||
},
|
||||
"item.label.Blog": {
|
||||
"message": "Blog",
|
||||
"description": "Navbar item with label Blog"
|
||||
},
|
||||
"item.label.GitHub": {
|
||||
"message": "GitHub",
|
||||
"description": "Navbar item with label GitHub"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user