fix: optimize default AI prompt to reduce thinking process output#175
Conversation
Based on #174 feedback, the default prompt was causing AI models to return thinking/reasoning content instead of pure JSON. Key changes: - Add explicit "only output valid JSON" instruction in system prompt and user prompt to suppress thinking process output - Restructure prompt into clear Requirements/输出格式 sections - Add platform detection hints (Dockerfile→docker, CLI→cli, etc.) - Constrain platforms to explicit enum with [] fallback - Provide concrete JSON example instead of generic placeholder values Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughService and UI prompts were tightened to force strictly valid JSON output with a fixed schema ( ChangesAI Prompt Constraint Enforcement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Previously categories were silently appended to repo info at the end
of the prompt, which some models could overlook. Now categories are
placed as a dedicated line right next to the tags requirement, with
an explicit cross-reference ("请优先从上方的可用分类中选择") so
models clearly see the connection between available categories and
the tags field they need to fill.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e platforms enum
1. AIConfigPanel default prompt now includes {CATEGORIES_INFO} placeholder
next to the tags requirement, so users can see and use it in custom
prompts. Previously the placeholder was undocumented in the UI.
2. parseAIResponse now filters platforms against a VALID_PLATFORMS enum
(mac/windows/linux/ios/android/docker/web/cli) with case-insensitive
matching. Invalid values like "mobile" are silently dropped instead of
passing through to the UI.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/aiService.ts (1)
381-404: 💤 Low valueConsider simplifying category reference to avoid redundancy.
When
customCategoriesis provided, the prompt mentions categories twice:
- Line 389: "请优先从上方的可用分类中选择" (prioritize from categories above)
- Line 389 (via
categoriesLine): "\n可用分类(tags 请优先从中选择):..." (available categories list)While this redundancy may help reinforce the instruction for AI models, you could simplify by removing the inline reference and relying solely on the
categoriesLine, or vice versa.Same pattern exists in the English version (lines 406-408, 414).
♻️ Suggested simplification (if desired)
Option 1: Remove inline reference, keep categoriesLine:
- return ` -请分析以下GitHub仓库信息,并只输出合法JSON对象。不要输出思考过程、Markdown、代码块标记、解释或任何额外文本。 - -要求: -- summary:中文概述,说明仓库的主要功能和用途,不超过50字。 -- tags:3-5个中文应用类型标签${customCategories && customCategories.length > 0 ? ',请优先从上方的可用分类中选择' : ',类似应用商店的分类,如:开发工具、Web应用、移动应用、数据库、AI工具等'}。${categoriesLine} + return ` +请分析以下GitHub仓库信息,并只输出合法JSON对象。不要输出思考过程、Markdown、代码块标记、解释或任何额外文本。 + +要求: +- summary:中文概述,说明仓库的主要功能和用途,不超过50字。 +- tags:3-5个中文应用类型标签${customCategories && customCategories.length > 0 ? '' : ',类似应用商店的分类,如:开发工具、Web应用、移动应用、数据库、AI工具等'}。${categoriesLine}Apply similar change to English version.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/aiService.ts` around lines 381 - 404, The prompt template duplicates the available-category guidance when customCategories is present by both injecting the inline phrase "请优先从上方的可用分类中选择" inside the tags sentence and also appending categoriesLine; update the prompt construction in src/services/aiService.ts to remove the redundant inline reference and rely only on categoriesLine (or conversely remove categoriesLine and keep the inline phrase) so that the returned template string uses a single category reference; adjust the same pattern in the English counterpart to ensure consistency; look for usages of customCategories, categoriesLine and the template-returning function to make the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/services/aiService.ts`:
- Around line 381-404: The prompt template duplicates the available-category
guidance when customCategories is present by both injecting the inline phrase
"请优先从上方的可用分类中选择" inside the tags sentence and also appending categoriesLine;
update the prompt construction in src/services/aiService.ts to remove the
redundant inline reference and rely only on categoriesLine (or conversely remove
categoriesLine and keep the inline phrase) so that the returned template string
uses a single category reference; adjust the same pattern in the English
counterpart to ensure consistency; look for usages of customCategories,
categoriesLine and the template-returning function to make the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6f0e36c2-2aec-48ec-8394-0ab9035b50cd
📒 Files selected for processing (2)
src/components/settings/AIConfigPanel.tsxsrc/services/aiService.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/aiService.ts`:
- Around line 450-452: The platforms array currently filters case-insensitively
using AIService.VALID_PLATFORMS but returns the original-cased values from
parsed.platforms; change the mapping so you canonicalize each accepted platform
(e.g., v.toLowerCase() or a canonicalizer that matches
AIService.VALID_PLATFORMS) after the filter and before slice/return—operate on
parsed.platforms, use the same validator
(AIService.VALID_PLATFORMS.includes(v.toLowerCase())) and then map to the
canonical form (v.toLowerCase() or lookup) to ensure returned platform values
conform to the enum.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ba9cba2d-b40e-4c27-9269-0a81cc540ce0
📒 Files selected for processing (2)
src/components/settings/AIConfigPanel.tsxsrc/services/aiService.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/settings/AIConfigPanel.tsx
Filter now normalizes each platform to lowercase before validation and uses Set to deduplicate, ensuring the returned values always match the VALID_PLATFORMS enum exactly. Previously, values like "WEB" could pass validation but retain non-canonical casing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
[]Closes #174
Test plan
{REPO_INFO}、{CATEGORIES_INFO}占位符🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Enhancements