UNPKG

@agentdao/core

Version:

Core functionality, skills, and ready-made UI components for AgentDAO - Web3 subscriptions, content generation, social media, help support, live chat, RSS fetching, web search, and agent pricing integration

107 lines (106 loc) • 5.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testSearchFunctionality = testSearchFunctionality; exports.checkAvailableSearchProviders = checkAvailableSearchProviders; const search_utils_1 = require("./search-utils"); const env_config_1 = require("./config/env-config"); /** * Test the new search functionality * This demonstrates how to use the search providers with proper API key validation */ async function testSearchFunctionality() { console.log('šŸ” Testing Search Functionality\n'); const testQuery = 'AI agents development'; // Test different search providers const providers = ['google', 'bing', 'openai']; for (const provider of providers) { console.log(`\nšŸ“” Testing ${provider.toUpperCase()} search...`); try { const options = { provider, maxResults: 3 }; const results = await search_utils_1.SearchProviders.searchWeb(testQuery, options); console.log(`āœ… ${provider.toUpperCase()} search successful! Found ${results.length} results:`); results.forEach((result, index) => { console.log(` ${index + 1}. ${result.title}`); console.log(` ${result.url}`); console.log(` ${result.snippet.substring(0, 100)}...`); }); } catch (error) { if (error instanceof Error) { console.log(`āŒ ${provider.toUpperCase()} search failed: ${error.message}`); // Provide helpful setup instructions if (provider === 'google' && !(0, env_config_1.hasApiKey)('google', 'apiKey')) { console.log(' šŸ’” To use Google Search, add to your .env file:'); console.log(' GOOGLE_SEARCH_API_KEY=your-api-key'); console.log(' GOOGLE_SEARCH_ENGINE_ID=your-search-engine-id'); } else if (provider === 'bing' && !(0, env_config_1.hasApiKey)('bing', 'apiKey')) { console.log(' šŸ’” To use Bing Search, add to your .env file:'); console.log(' BING_SEARCH_API_KEY=your-api-key'); } } } } // Test news search console.log('\nšŸ“° Testing News Search...'); try { const newsResults = await search_utils_1.SearchProviders.searchNews('artificial intelligence', { maxResults: 2 }); console.log(`āœ… News search successful! Found ${newsResults.length} articles:`); newsResults.forEach((article, index) => { console.log(` ${index + 1}. ${article.title} (${article.source})`); }); } catch (error) { if (error instanceof Error) { console.log(`āŒ News search failed: ${error.message}`); if (!(0, env_config_1.hasApiKey)('newsapi', 'apiKey')) { console.log(' šŸ’” To use News API, add to your .env file:'); console.log(' NEWS_API_KEY=your-api-key'); } } } // Test image search console.log('\nšŸ–¼ļø Testing Image Search...'); try { const imageResults = await search_utils_1.SearchProviders.searchImages('AI technology', { maxResults: 2 }); console.log(`āœ… Image search successful! Found ${imageResults.length} images:`); imageResults.forEach((image, index) => { console.log(` ${index + 1}. ${image.title}`); console.log(` ${image.url}`); }); } catch (error) { if (error instanceof Error) { console.log(`āŒ Image search failed: ${error.message}`); if (!(0, env_config_1.hasApiKey)('unsplash', 'accessKey')) { console.log(' šŸ’” To use Unsplash API, add to your .env file:'); console.log(' UNSPLASH_ACCESS_KEY=your-access-key'); } } } console.log('\nšŸŽ‰ Search functionality test completed!'); } /** * Check which search providers are available based on API keys */ function checkAvailableSearchProviders() { console.log('šŸ”‘ Checking Available Search Providers\n'); const providers = [ { name: 'Google Search', hasKey: (0, env_config_1.hasApiKey)('google', 'apiKey'), hasEngineId: (0, env_config_1.hasApiKey)('google', 'searchEngineId') }, { name: 'Bing Search', hasKey: (0, env_config_1.hasApiKey)('bing', 'apiKey') }, { name: 'News API', hasKey: (0, env_config_1.hasApiKey)('newsapi', 'apiKey') }, { name: 'Unsplash Images', hasKey: (0, env_config_1.hasApiKey)('unsplash', 'accessKey') } ]; providers.forEach(provider => { const status = provider.hasKey ? 'āœ…' : 'āŒ'; const details = provider.hasKey ? 'API key configured' : 'API key missing'; const engineStatus = provider.hasEngineId !== undefined ? (provider.hasEngineId ? 'āœ…' : 'āŒ') + ' Search Engine ID' : ''; console.log(`${status} ${provider.name}: ${details} ${engineStatus}`); }); console.log('\nšŸ¤– OpenAI Web Search: āœ… Available with OpenAI API key'); console.log('\nšŸ’” Tip: OpenAI web search is used as fallback when other providers are not configured'); }