Repository navigation
新功能:自定义透传渠道(CustomPass) #1454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
新功能:自定义透传渠道(CustomPass) #1454
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
691a804
feat(custompass): implement custom pass channel for transparent proxying
simplty 466040e
feat(api): Implement Stripe payment gateway and integrate into top-up…
simplty 5671a9d
feat(custompass): enhance two-request flow and add model configuratio…
simplty 67979df
chore: add new-api to .gitignore
simplty b32c5cb
feat(channel): add Vidu channel support and refactor error handling
simplty 85fe4b9
feat(custompass): add custompass channel type and refactor start script
simplty 2d9214f
feat(custompass): enhance billing logic and context propagation
simplty fef8d22
feat(custompass): 为 custompass 添加自定义令牌支持
simplty d0c5e0f
feat(custompass): add detailed billing logic and precharge validation
simplty 7d18926
feat(custompass): streamline request handling
simplty 4d58111
refactor(custompass): standardize billing calculation and logging
simplty 1e9e4cb
feat(custompass): refine billing checks and error handling
simplty aeb9013
Merge branch 'alpha' into feat/custompass
simplty eb7874f
Merge branch 'alpha' into feat/custompass
simplty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Claude Code 数据增强智能助手 | ||
|
|
||
| 这个自定义命令创建了一个智能AI助手,能够在执行任务时自动识别需要数据库支持的部分,先查询相关数据,然后基于数据上下文完成您的任务。**无需任何配置文件,自动发现项目数据库设置!** | ||
|
|
||
| ## 安装 | ||
|
|
||
| 只需要一个文件: | ||
| - **主命令**: `.claude/commands/ask-with-data.md` | ||
|
|
||
| 该命令会自动检测项目中的数据库配置,支持多种配置文件格式和项目类型。 | ||
|
|
||
| ## 使用方法 | ||
|
|
||
| 在Claude Code中使用斜杠命令: | ||
|
|
||
| ``` | ||
| /ask-with-data <您的问题或任务> | ||
| ``` | ||
|
|
||
| ### 示例用法 | ||
|
|
||
| ```bash | ||
| # 基于数据的分析和优化 | ||
| /ask-with-data 帮我基于当前用户数据优化用户注册流程 | ||
|
|
||
| # 创建数据驱动的功能 | ||
| /ask-with-data 创建一个显示最受欢迎API渠道的仪表板 | ||
|
|
||
| # 问题诊断和修复 | ||
| /ask-with-data 修复高使用量用户的计费问题 | ||
|
|
||
| # 数据分析和报告 | ||
| /ask-with-data 分析为什么错误率上升并提出改进建议 | ||
|
|
||
| # 业务洞察 | ||
| /ask-with-data 写一份关于我们顶级客户及其使用模式的报告 | ||
|
|
||
| # 性能优化 | ||
| /ask-with-data 帮我了解哪些模型性能不佳 | ||
|
|
||
| # 代码改进建议 | ||
| /ask-with-data 基于实际使用数据建议如何优化API性能 | ||
| ``` | ||
|
|
||
| ## 功能特性 | ||
|
|
||
| ### 1. 自动配置发现 | ||
| 命令会自动检测项目中的数据库配置: | ||
|
|
||
| - **配置文件**: config.yaml, config.json, .env, application.properties | ||
| - **项目类型**: Go, Spring Boot, Node.js等 | ||
| - **数据库文件**: 自动查找SQLite数据库文件 | ||
|
|
||
| ### 2. 智能任务分析 | ||
| 自动分析您的任务,识别需要数据库支持的部分: | ||
|
|
||
| - **用户相关任务**: 涉及用户注册、管理、分析的任务 | ||
| - **渠道优化**: API渠道性能分析和优化建议 | ||
| - **使用统计分析**: 流量分析、使用模式识别 | ||
| - **错误诊断**: 问题分析、故障排查、性能优化 | ||
| - **业务洞察**: 客户分析、收入优化、趋势预测 | ||
| - **模型性能**: AI模型效果分析和优化建议 | ||
|
|
||
| ### 3. 数据驱动决策 | ||
|
|
||
| 基于实际数据提供: | ||
|
|
||
| - **准确的分析**: 基于真实数据而非假设 | ||
| - **个性化建议**: 针对您项目的具体情况 | ||
| - **可行的解决方案**: 结合代码和数据的实用建议 | ||
| - **量化的洞察**: 具体的数字和趋势分析 | ||
|
|
||
| ### 4. 全栈任务支持 | ||
| - 数据分析 + 代码实现 | ||
| - 问题诊断 + 解决方案 | ||
| - 性能分析 + 优化建议 | ||
| - 业务洞察 + 功能开发 | ||
|
|
||
| ## 扩展和自定义 | ||
|
|
||
| ### 添加新的数据类型支持 | ||
|
|
||
| 直接编辑 `.claude/commands/ask-with-data.md` 文件中的分析逻辑: | ||
|
|
||
| ```bash | ||
| # 添加新的任务类型检测 | ||
| if [[ $QUESTION_LOWER =~ (your|task|keywords) ]]; then \ | ||
| echo "🔍 Detected your custom task type" && QUERIES_TO_RUN="$QUERIES_TO_RUN your_query"; \ | ||
| fi | ||
|
|
||
| # 添加对应的数据查询 | ||
| "your_query") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "YOUR SQL QUERY HERE;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; | ||
| ``` | ||
|
|
||
| ## 故障排除 | ||
|
|
||
| ### 1. 数据库未找到 | ||
| - 确保SQLite数据库文件存在 | ||
| - 检查数据库文件路径 | ||
| - 确认项目结构 | ||
|
|
||
| ### 2. 任务执行失败 | ||
| - 验证数据库表结构 | ||
| - 检查SQL语法 | ||
| - 确认数据库权限 | ||
| - 检查任务描述是否清晰 | ||
|
|
||
| ## 工作流程 | ||
|
|
||
| ``` | ||
| 用户任务 → Claude Code → /ask-with-data 命令 → | ||
| 分析任务需求 → 自动发现数据库 → 查询相关数据 → | ||
| 基于数据上下文执行任务 → 提供完整解决方案 | ||
| ``` | ||
|
|
||
| 该命令设计为智能助手,能够将数据洞察与代码实现完美结合,适用于任何需要数据支持的开发任务。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| --- | ||
| description: Intelligent assistant that queries database when needed and completes tasks with data context | ||
| argument-hint: "<your question or task>" | ||
| allowed-tools: [Bash, Read, Write, Grep, Glob, Edit, MultiEdit] | ||
| --- | ||
|
|
||
| # Data-Enhanced AI Assistant | ||
|
|
||
| This intelligent assistant will: | ||
| 1. Analyze your question or task to identify parts that need database support | ||
| 2. Auto-discover your project's database configuration | ||
| 3. Query relevant database data when needed | ||
| 4. Complete your task using both the database context and codebase knowledge | ||
|
|
||
| ## Usage | ||
| ``` | ||
| /ask-with-data <your question or task> | ||
| ``` | ||
|
|
||
| ## Examples | ||
| ``` | ||
| /ask-with-data Help me optimize the user registration process based on current user data | ||
| /ask-with-data Create a dashboard showing our most popular API channels | ||
| /ask-with-data Fix the billing issues for users with high usage | ||
| /ask-with-data Analyze why error rates increased and suggest improvements | ||
| /ask-with-data Write a report on our top customers and their usage patterns | ||
| /ask-with-data Help me understand which models are underperforming | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| I'll analyze your task and gather any necessary database context to provide you with the best assistance: **$ARGUMENTS** | ||
|
|
||
| Let me first check if your task requires database information, and if so, I'll gather that data before proceeding. | ||
|
|
||
| !echo "🔍 Analyzing question: $ARGUMENTS" && echo "==================================" | ||
|
|
||
| !echo "🔍 Auto-discovering database configuration..." && \ | ||
| DB_TYPE="" && DB_CONNECTION="" && \ | ||
| if [ -f "config.yaml" ] || [ -f "config.yml" ]; then echo "📁 Found YAML config file"; fi && \ | ||
| if [ -f "config.json" ]; then echo "📁 Found JSON config file"; fi && \ | ||
| if [ -f ".env" ]; then echo "📁 Found .env file"; source .env 2>/dev/null; fi && \ | ||
| if [ -f "application.properties" ]; then echo "📁 Found Spring properties file"; fi && \ | ||
| if [ -f "go.mod" ]; then echo "📁 Found Go project"; fi && \ | ||
| if [ -f "data/new-api.db" ]; then DB_TYPE="sqlite"; DB_CONNECTION="./data/new-api.db"; \ | ||
| elif [ -f "database.db" ]; then DB_TYPE="sqlite"; DB_CONNECTION="./database.db"; \ | ||
| elif [ -f "app.db" ]; then DB_TYPE="sqlite"; DB_CONNECTION="./app.db"; \ | ||
| else DB_TYPE="sqlite"; DB_CONNECTION="./data/new-api.db"; fi && \ | ||
| echo "✅ Database type: $DB_TYPE" && echo "✅ Connection: $DB_CONNECTION" | ||
|
|
||
| !echo "" && echo "🤖 Analyzing question for relevant data..." && \ | ||
| QUESTION_LOWER=$(echo "$ARGUMENTS" | tr '[:upper:]' '[:lower:]') && \ | ||
| QUERIES_TO_RUN="" && \ | ||
| if [[ $QUESTION_LOWER =~ (user|account|register|signup|用户|注册|账户) ]]; then \ | ||
| echo "📈 Detected user-related question" && QUERIES_TO_RUN="$QUERIES_TO_RUN users"; \ | ||
| fi && \ | ||
| if [[ $QUESTION_LOWER =~ (channel|provider|api|integration|渠道|接口|集成) ]]; then \ | ||
| echo "🔌 Detected channel-related question" && QUERIES_TO_RUN="$QUERIES_TO_RUN channels"; \ | ||
| fi && \ | ||
| if [[ $QUESTION_LOWER =~ (request|usage|traffic|call|请求|使用|流量|调用) ]]; then \ | ||
| echo "📊 Detected request/usage question" && QUERIES_TO_RUN="$QUERIES_TO_RUN requests"; \ | ||
| fi && \ | ||
| if [[ $QUESTION_LOWER =~ (error|fail|problem|issue|错误|失败|问题) ]]; then \ | ||
| echo "🚨 Detected error-related question" && QUERIES_TO_RUN="$QUERIES_TO_RUN errors"; \ | ||
| fi && \ | ||
| if [[ $QUESTION_LOWER =~ (top|best|most|spending|customer|最多|最佳|消费|客户) ]]; then \ | ||
| echo "🏆 Detected top users question" && QUERIES_TO_RUN="$QUERIES_TO_RUN top_users"; \ | ||
| fi && \ | ||
| if [[ $QUESTION_LOWER =~ (model|gpt|claude|gemini|token|模型|令牌) ]]; then \ | ||
| echo "🤖 Detected model-related question" && QUERIES_TO_RUN="$QUERIES_TO_RUN models"; \ | ||
| fi && \ | ||
| if [ -z "$QUERIES_TO_RUN" ]; then \ | ||
| echo "🔍 No specific keywords detected, running general overview..." && QUERIES_TO_RUN="users channels requests"; \ | ||
| fi | ||
|
|
||
| !echo "" && echo "📋 Running relevant database queries..." && echo "==================================" && \ | ||
| DB_CONNECTION="./data/new-api.db" && \ | ||
| for query_type in $QUERIES_TO_RUN; do \ | ||
| echo "" && echo "📊 Query: $query_type" && echo "----------------------------------------" && \ | ||
| case "$query_type" in \ | ||
| "users") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT COUNT(*) as total_users, COUNT(CASE WHEN created_at > datetime('now', '-30 days') THEN 1 END) as recent_users FROM users;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| "channels") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT type, COUNT(*) as count, AVG(priority) as avg_priority FROM channels GROUP BY type ORDER BY count DESC;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| "requests") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT DATE(created_at) as date, COUNT(*) as requests, SUM(quota) as total_quota FROM logs WHERE created_at > datetime('now', '-7 days') GROUP BY DATE(created_at) ORDER BY date;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| "errors") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT type, COUNT(*) as error_count FROM logs WHERE created_at > datetime('now', '-24 hours') AND (response_time = 0 OR content LIKE '%error%') GROUP BY type ORDER BY error_count DESC;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| "top_users") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT user_id, SUM(quota) as total_usage, COUNT(*) as request_count FROM logs WHERE created_at > datetime('now', '-30 days') GROUP BY user_id ORDER BY total_usage DESC LIMIT 10;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| "models") \ | ||
| if [ -f "$DB_CONNECTION" ]; then \ | ||
| sqlite3 "$DB_CONNECTION" "SELECT model, COUNT(*) as usage_count, AVG(prompt_tokens) as avg_prompt_tokens, AVG(completion_tokens) as avg_completion_tokens FROM logs WHERE created_at > datetime('now', '-7 days') GROUP BY model ORDER BY usage_count DESC;" 2>/dev/null || echo "❌ Query failed"; \ | ||
| else echo "❌ Database not found"; fi ;; \ | ||
| esac; \ | ||
| done | ||
|
|
||
| !echo "" && echo "✅ Database analysis complete!" && echo "🎯 Now analyzing your question with this database context..." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,6 @@ web/dist | |
| one-api | ||
| .DS_Store | ||
| tiktoken_cache | ||
| .eslintcache | ||
| test | ||
| .eslintcache | ||
| new-api | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve database discovery robustness.
The database discovery logic has some limitations:
./data/new-api.dbeven if the file doesn't existConsider enhancing the discovery logic:
📝 Committable suggestion
🤖 Prompt for AI Agents