Add DeepSeek AI search integration to Codelf
Overview
This PR integrates DeepSeek AI as an additional search source for Codelf, providing users with AI-powered code search capabilities alongside the existing SearchCode.com functionality.
Features Added
🔍 Dual Search Sources
- SearchCode.com (default): Traditional code search across GitHub, Bitbucket, GitLab
- DeepSeek AI (new): AI-powered intelligent code suggestions using OpenAI-compatible API
🔧 Configuration Management
- Secure API key storage using localStorage
- User-friendly modal dialog for API key configuration
- Automatic validation and error handling
🎯 Smart Search Integration
- Seamless switching between search sources via dropdown selector
- Language filter support for both search providers
- Intelligent response parsing and adaptation
- Built-in caching for improved performance
Usage
- Default Experience: No changes to existing functionality - SearchCode.com remains the default
-
Enable DeepSeek:
- Click the search source dropdown
- Select "DeepSeek AI"
- Enter your API key from DeepSeek Platform
- Start searching with AI-powered suggestions
Technical Implementation
Core Changes
// New search source constants
const SEARCH_SOURCES = {
SEARCHCODE: 'searchcode',
DEEPSEEK: 'deepseek'
};
// Enhanced search method supports multiple sources
async requestVariable(val, page, lang, searchSource) {
// Route to appropriate search provider
if (searchSource === SEARCH_SOURCES.DEEPSEEK) {
await this._searchWithDeepSeek(val, q, page, lang, suggestion, isZH, cacheId);
} else {
await this._searchWithSearchCode(val, q, page, lang, suggestion, isZH, cacheId);
}
}
New Components
-
DeepSeekData.js: Complete API integration with response parsing - Enhanced SearchBar: Added search source selector and API key configuration modal
- Updated SearchCodeModel: Multi-provider routing and state management
Response Adaptation
DeepSeek API responses are automatically adapted to match SearchCode.com format:
// DeepSeek response → SearchCode.com format
{
id: `deepseek_${hash}_${index}`,
name: result.name || `${query}_example`,
repo: result.repo || 'https://github.com/example/repo',
language: result.language || 'JavaScript',
lines: result.lines || { 1: `// Example: ${query}` },
// ... other fields for UI compatibility
}
Configuration
Prerequisites
- DeepSeek API key from platform.deepseek.com
Environment
- API key stored securely in browser localStorage
- No server-side configuration required
- Graceful fallback if API key is missing or invalid
Backward Compatibility
✅ Fully backward compatible
- Existing SearchCode.com functionality unchanged
- No breaking changes to existing APIs
- Legacy
SearchcodeModel.jsupdated for consistency - Default behavior preserved for existing users
Testing
Comprehensive test coverage including:
- API key management (set/get/remove)
- Search functionality with mocked responses
- Caching behavior verification
- Error handling for missing API keys
- Response format adaptation
# Run integration test
node test-deepseek.js
✅ All tests passed! DeepSeek integration is working correctly.
Documentation
Updated README.md with:
- DeepSeek configuration instructions
- Feature overview and benefits
- Setup guide with screenshots
- Usage examples and best practices
Files Changed
-
src/constants/Configs.js- Added search source constants and API configuration -
src/models/metadata/DeepSeekData.js- New: Complete DeepSeek API integration -
src/models/SearchCodeModel.js- Enhanced with multi-provider support -
src/components/SearchBar.js- Added search source selector and configuration modal -
src/containers/MainContainer.js- Updated to handle new search functionality -
src/utils/LocalStorage.js- Added removeItem method and proper exports -
__static/app/src/model/SearchcodeModel.js- Legacy compatibility updates -
README.md- Comprehensive documentation for DeepSeek integration
Benefits
🚀 Enhanced User Experience
- More contextual and relevant code suggestions
- Natural language query support
- Complementary results to traditional search
🔧 Developer Friendly
- Simple configuration process
- No impact on existing workflows
- Seamless integration with existing UI
🛡️ Robust Implementation
- Comprehensive error handling
- Secure API key management
- Performance optimized with caching
This integration maintains Codelf's core mission of helping developers solve naming problems while adding the power of modern AI to provide even better suggestions and examples.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.