import React, { useState } from 'react'; import { AIRouterProvider, useAIRouter, generateViralPollRoute, AI_CONFIG_PRESETS, ViralPollResponse, PollGenerationRequest } from '../src'; // Example 1: Basic Setup with OpenAI function App() { const config = AI_CONFIG_PRESETS.development('your-openai-api-key'); return ( ); } // Example 2: Generate Viral Poll from Article function PollGenerator() { const [isLoading, setIsLoading] = useState(false); const [poll, setPoll] = useState(null); const { execute, error } = useAIRouter(generateViralPollRoute); const handleGeneratePoll = async () => { setIsLoading(true); try { const input: PollGenerationRequest = { article_data: { url: 'https://example.com/ai-breakthrough', title: 'OpenAI Announces GPT-5 with 10x Performance Boost', summary: 'New model shows dramatic improvements in reasoning and efficiency', news_site: 'tech-news.com', tags: ['ai', 'openai', 'gpt5'] }, perspective: 'balanced', payment_token: 'FLOW' }; const result = await execute(input); setPoll(result); } catch (err) { console.error('Failed to generate poll:', err); } finally { setIsLoading(false); } }; return ( Viral Poll Generator {isLoading ? 'Generating...' : 'Generate Poll'} {error && ( Error: {error.message} )} {poll && ( {poll.question} 🚀 Serial Optimism: {poll.serial_optimism} 🔄 Contrarian: {poll.contrarian} 💀 Pessimistic: {poll.pessimistic} 🔥 Hot Take: {poll.hottake} Viral Score: {poll.metadata.viral_score.toFixed(2)} Category: {poll.category} Share Text: {poll.metadata.share_text} )} ); } // Example 3: Local LLM with WebLLM function LocalLLMDemo() { const [isInitializing, setIsInitializing] = useState(false); const [result, setResult] = useState(null); const config = AI_CONFIG_PRESETS.localFirst(); // Uses WebLLM only const handleLocalGeneration = async () => { setIsInitializing(true); try { // Create a local-only router const localConfig = { ...config, defaultProvider: { provider: 'web-llm' as const, model: 'Llama-3.2-1B-Instruct-q4f32_1', temperature: 0.7, maxTokens: 500 } }; // This would use the local LLM setResult('Local LLM generation would happen here with WebLLM'); } catch (error) { console.error('Local generation failed:', error); } finally { setIsInitializing(false); } }; return ( Local LLM Demo Run Llama-3 locally in your browser with WebGPU {isInitializing ? 'Initializing Model...' : 'Generate Locally'} {result && ( Local Generation Result: {result} )} ); } export default App;
Viral Score: {poll.metadata.viral_score.toFixed(2)}
Category: {poll.category}
Share Text: {poll.metadata.share_text}
Run Llama-3 locally in your browser with WebGPU
{result}