Environment Variables Setup
API Key Configuration
Using OpenRouter API
DeenPAL is configured to use DeepSeek via the OpenRouter API by default:chains.py
- Sign up at OpenRouter
- Get your API key from the dashboard
- Add it to your
.envfile asOPENAI_API_KEY
The
deepseek-chat-v3-0324:free model is used, which provides free access through OpenRouter.Alternative LLM Configurations
You can modifychains.py to use different LLM providers:
Retriever Parameters
The retrieval system can be customized inchains.py to adjust how Hadiths are retrieved:
Current Configuration
chains.py
Parameter Explanations
Search Type: MMR (Maximal Marginal Relevance)
Why MMR?MMR provides diverse, relevant results instead of similar redundant ones. The project author tested both similarity-based and MMR retrieval, finding that MMR:
- Increases diversity in retrieved Hadiths
- Maintains relevance to the query
- Helps the LLM provide different but related Hadiths
- Avoids redundant responses
k Parameter (Number of Results)
- Default:
4 - Purpose: Number of diverse results returned to the LLM
- Range: 1-10 recommended
- Lower k (1-3): Faster responses, more focused answers
- Higher k (5-10): More comprehensive answers, broader context
fetch_k Parameter (Candidate Pool)
- Default:
10 - Purpose: Number of candidates fetched before MMR selection
- Range: Should be ≥ k
- Lower fetch_k: Faster retrieval, less diversity
- Higher fetch_k: More diversity options, slower retrieval
Alternative Search Types
You can also use similarity-based search:Custom Prompts
To customize how the chatbot responds, modify the prompts inprompts.py:
Default QA System Prompt
prompts.py
Customizing the Prompt
Create or modifyprompts.py to adjust the chatbot’s behavior:
prompts.py
The
{context} placeholder is automatically filled with retrieved Hadiths, and {input} contains the user’s question.Configuration Best Practices
Security
- Never hardcode API keys in source files
- Use
.envfor all sensitive configuration - Add
.envto.gitignore - Rotate API keys periodically
Performance Tuning
For faster responses:Verifying Configuration
Test your configuration by running a simple query:Common Configuration Issues
API Key Not Found:.env exists and contains the correct key.
Invalid API Key:
Next Steps
With configuration complete, you’re ready to:- Run the chatbot
- Test queries and evaluate responses
- Fine-tune retrieval parameters based on results
