Skip to content

Conversation

lgd-matlab
Copy link

Overview

This PR adds a custom prompt enhancement feature and converts Chinese UI text to English in the Advanced Settings section.

Features Added

  • Custom Prompt Enhancement: Users can now define custom instruction templates to optimize their prompts
  • 🔧 Flexible Placeholder Support: Supports multiple placeholder formats including {prompt}, {history}, {context}, {{prompt}}, {{history}}, {{context}}
  • 🤖 AI-Powered Optimization: Uses the same AI model as the current chat to enhance prompts
  • 📝 Context Integration: Incorporates conversation history and additional context into prompt optimization

Technical Implementation

  • New File: src/promptEnhancer.ts - Core prompt enhancement logic
  • Enhanced Settings: Updated Advanced Settings UI with English text
  • Template System: Supports custom instruction templates with variable substitution
  • Error Handling: Comprehensive error handling and result validation
  • Type Safety: Full TypeScript support with proper interfaces

Changes Made

Core Files

  • src/promptEnhancer.ts - New prompt enhancement engine
  • src/settings/v2/components/AdvancedSettings.tsx - UI localization to English
  • src/settings/model.ts - Settings model updates
  • src/constants.ts - Added necessary constants
  • src/components/Chat.tsx - Integration with chat functionality
  • src/components/chat-components/ChatInput.tsx - Input handling updates

Key Features

  1. Prompt Type Detection: Automatically detects prompt types (content generation, analysis, Q&A, format conversion)
  2. Multi-format Placeholder Support:
    • {prompt} / {original_prompt} - Original user prompt
    • {history} / {chat_history} - Conversation history
    • {context} / {added_context} - Additional context
    • Double brace variants: {{prompt}}, {{history}}, {{context}}
  3. Smart Result Cleaning: Removes AI response prefixes and validates output
  4. Fallback Mechanism: Returns original prompt if enhancement fails

Code Quality

  • ✅ Passes ESLint checks
  • ✅ TypeScript strict mode compliant
  • ✅ Comprehensive error handling
  • ✅ Detailed logging for debugging
  • ✅ Clean code architecture with separation of concerns

Usage Example

Users can now set custom enhancement templates like:
You are an expert prompt engineer. Enhance the following prompt:

Original: {prompt}
Context: {context}
History: {history}

Make it more specific and actionable.

Testing

  • Code passes all lint checks
  • TypeScript compilation successful
  • UI text properly localized to English
  • Placeholder substitution working correctly
  • Error handling tested

Breaking Changes

None - This is a purely additive feature that doesn't affect existing functionality.

Screenshots

(Add screenshots of the English UI if available)


This enhancement significantly improves the user experience by providing intelligent prompt optimization while maintaining a clean, English-language interface.

lgd-matlab and others added 3 commits June 18, 2025 10:49
- Add custom prompt enhancement instruction functionality
- Implement prompt optimization with template support
- Convert Chinese UI text to English in Advanced Settings
- Support placeholders for prompt, history, and context
- Add promptEnhancer.ts for prompt processing logic
- Fix lint errors: remove unused import and use const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant