Overview
DecipherIt uses a multi-model approach:- OpenAI - Text embeddings for semantic search (via Qdrant)
- Google Gemini - Large language model for content generation (via OpenRouter)
- LemonFox AI - High-quality text-to-speech synthesis
Environment Variables
Backend Configuration
Add these to your backend.env file:
backend/.env
OpenAI Integration
Purpose
OpenAI is used exclusively for generating text embeddings that power semantic search through Qdrant vector database.Configuration
.env file as OPENAI_API_KEYclass QdrantSourceStore:
def __init__(
self,
embedding_model: str = "text-embedding-3-small",
openai_api_key: Optional[str] = None,
):
# Initialize OpenAI client
self.openai_client = AsyncOpenAI(api_key=openai_api_key)
self.embedding_model = embedding_model
Usage in Semantic Search
Embeddings enable intelligent Q&A capabilities:backend/agents/chat_agent.py
Text Chunking Strategy
Content is chunked for optimal retrieval:backend/services/qdrant_service.py
Google Gemini Integration
Purpose
Google Gemini powers all content generation through CrewAI agents for research analysis, summaries, FAQs, and mindmaps.Configuration via OpenRouter
.env file as OPENROUTER_API_KEYfrom crewai import LLM
import os
from dotenv import load_dotenv
load_dotenv()
llm = LLM(
model="openrouter/google/gemini-2.0-flash-001",
base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
temperature=0.01
)
Usage in AI Agents
All CrewAI agents use the configured LLM:backend/agents/topic_research_agent.py
CrewAI Agents Powered by Gemini
LemonFox AI Integration
Purpose
LemonFox AI provides high-quality text-to-speech synthesis for podcast-style audio overviews.Configuration
.env file as LEMONFOX_API_KEYimport os
import httpx
from loguru import logger
class TTSService:
def __init__(self):
self.api_key = os.environ.get("LEMONFOX_API_KEY")
if not self.api_key:
raise ValueError("LEMONFOX_API_KEY environment variable is required")
self.base_url = "https://api.lemonfox.ai/v1/audio/speech"
self.response_format = "mp3"
# Voice mapping for different speakers
self.speaker_voices = {
"Michael": "liam", # Host voice
"Sarah": "jessica" # Guest voice
}
Audio Generation Workflow
# Step 1: Generate transcript using audio overview agent
transcript = await run_audio_overview_agent(notebook_id)
# Transcript format:
# [
# {"name": "Michael", "transcript": "Welcome to..."},
# {"name": "Sarah", "transcript": "Thanks for having me..."}
# ]
async def generate_audio_from_transcript(
self,
transcript: List[Dict[str, Any]],
notebook_id: str
) -> bytes:
# Process segments concurrently (max 5 at a time)
tasks = []
for segment in transcript:
speaker = segment.get("name", "Michael")
text = segment.get("transcript", "")
voice = self.speaker_voices.get(speaker, "jessica")
task = self._generate_audio_with_semaphore(text, voice)
tasks.append(task)
# Execute all TTS requests concurrently
audio_bytes_list = await asyncio.gather(*tasks)
# Combine audio segments with pauses
return await self._combine_audio_segments(audio_bytes_list)
Performance Optimization
The TTS service uses several optimizations:backend/services/tts_service.py
Connection Pooling: Reuses HTTP connections for better performanceRate Limiting: Maximum 5 concurrent requests to avoid overwhelming the APIHTTP/2: Enabled for improved request multiplexing
Cost Optimization
OpenAI Embeddings
- Uses
text-embedding-3-small(most cost-effective) - Only generates embeddings once per content chunk
- Chunks limited to 512 tokens for efficiency
Gemini via OpenRouter
- Uses Gemini 2.0 Flash (fastest, most cost-effective)
- Temperature set to 0.01 for deterministic outputs (fewer retries)
- Rate limiting prevents excessive API calls:
max_rpm=20
LemonFox TTS
- Only generates audio on-demand when user requests
- Concurrent processing reduces total time
- Audio cached in R2 storage (no regeneration needed)
Troubleshooting
OpenAI Errors
If embeddings fail:Gemini/OpenRouter Errors
If content generation fails:- Check OpenRouter API key is valid
- Verify you have credits: openrouter.ai/credits
- Check model availability: openrouter.ai/models
LemonFox TTS Errors
If audio generation fails:- Verify
LEMONFOX_API_KEYis correct - Check API quotas and limits
- Review logs:
logs/audio_overview_*.log
Next Steps
- Learn about Bright Data Integration
- Configure Storage
- Explore AI Agents