Skip to content

valiyyaddin/E-custom-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

E-Custom Chatbot πŸ€–

An intelligent Telegram chatbot for answering customs-related questions in Azerbaijani. The bot uses OpenAI embeddings for semantic search and supports both text and voice messages with multiple speech-to-text engines.

Features ✨

  • Text Message Support: Ask questions via text and receive categorized answers
  • Voice Message Support: Send voice messages in Azerbaijani
  • Multi-Engine Speech Recognition:
    • ElevenLabs Speech-to-Text (primary)
    • OpenAI Whisper (fallback)
    • Google Speech Recognition (secondary fallback)
  • Smart Category Classification: Automatically categorizes questions using semantic similarity
  • Semantic Search: Uses OpenAI embeddings and FAISS for fast, accurate answer retrieval
  • Context Awareness: Remembers last category for better follow-up question handling

Technology Stack πŸ› οΈ

  • Python 3.x
  • OpenAI API: Text embeddings (text-embedding-3-large)
  • FAISS: Vector similarity search
  • Telegram Bot API: User interface
  • ElevenLabs API: Azerbaijani speech-to-text
  • Pandas & NumPy: Data processing
  • scikit-learn: Cosine similarity calculations

Installation πŸ“¦

1. Clone the Repository

git clone https://github.com/valiyyaddin/E-custom-chatbot.git
cd E-custom-chatbot

2. Install Dependencies

pip install -r requirements.txt

3. Set Up Environment Variables

Create a .env file in the root directory:

TELEGRAM_TOKEN=your_telegram_bot_token
ELEVEN_API_KEY=your_elevenlabs_api_key
API_KEY=your_openai_api_key

4. Prepare Data

Place your customs FAQ CSV file in the project directory. The CSV should have the following columns:

  • Sual: Questions
  • Cavab: Answers
  • Kateqoriya: Categories

Update the CSV_PATH in main.py to point to your CSV file.

Usage πŸš€

Start the Bot

python main.py

Interact with the Bot

  1. Open Telegram and search for your bot
  2. Send /start to begin
  3. Ask questions in text or send voice messages
  4. Receive categorized answers instantly

Example Interactions

Text Message:

User: GΓΆmrΓΌk rΓΌsumu necΙ™ ΓΆdΙ™nilir?
Bot: πŸ“‚ Kateqoriya: Γ–dΙ™niş
     πŸ’¬ Cavab: [Detailed answer about customs payment]

Voice Message:

User: [Sends voice message]
Bot: 🎀 Sual: GΓΆmrΓΌk rΓΌsumu necΙ™ ΓΆdΙ™nilir?
     πŸ“‚ Kateqoriya: Γ–dΙ™niş
     πŸ’¬ Cavab: [Detailed answer]

Configuration βš™οΈ

Similarity Thresholds

Adjust these in main.py:

CATEGORY_THRESHOLD = 0.56  # Strictness for category classification
RETRIEVAL_THRESHOLD = 0.37  # Leniency for answer retrieval

File Paths

CSV_PATH = 'path/to/your/customs_faq.csv'
EMBEDDINGS_FILE = 'embeddings_save.pkl'  # Cached embeddings
CATEGORY_FILE = 'cat.txt'  # Last category cache

Architecture πŸ—οΈ

Core Components

  1. Embedding System:

    • Generates OpenAI embeddings for all questions
    • Caches embeddings for performance
    • Uses FAISS index for fast similarity search
  2. Question Processing Pipeline:

    User Question β†’ Clean Text β†’ Generate Embedding β†’ 
    Classify Category β†’ Search Similar Questions β†’ 
    Return Best Answer
    
  3. Speech Recognition Chain:

    Voice Message β†’ ElevenLabs STT β†’ 
    [If fails] β†’ Whisper STT β†’ 
    [If fails] β†’ Google SR β†’ Text
    
  4. Category Memory:

    • Saves last successfully classified category
    • Uses for context in ambiguous questions
    • Falls back to full search if needed

Project Structure πŸ“

E-custom-chatbot/
β”œβ”€β”€ main.py                           # Main bot application
β”œβ”€β”€ requirements.txt                  # Python dependencies
β”œβ”€β”€ customs_faq - customs_faq.csv.csv # FAQ dataset
β”œβ”€β”€ .gitignore                       # Git ignore rules
β”œβ”€β”€ .env                             # Environment variables (create this)
β”œβ”€β”€ embeddings_save.pkl              # Cached embeddings (auto-generated)
β”œβ”€β”€ cat.txt                          # Last category cache (auto-generated)
β”œβ”€β”€ config/                          # Configuration files
└── services/                        # Additional services
    β”œβ”€β”€ vosk.py                      # Vosk STT service
    β”œβ”€β”€ whisper.py                   # Whisper STT service
    └── filesUtils.py                # File utilities

API Keys Required πŸ”‘

  1. Telegram Bot Token: Get from @BotFather
  2. OpenAI API Key: Get from OpenAI Platform
  3. ElevenLabs API Key: Get from ElevenLabs

Performance Optimization πŸ’‘

  • Embeddings are cached in embeddings_save.pkl to avoid regeneration
  • FAISS index enables fast similarity search (O(log n))
  • Category memory reduces search space for follow-up questions
  • Multiple STT engines ensure high transcription success rate

Error Handling πŸ›‘οΈ

The bot includes comprehensive error handling:

  • Graceful fallbacks for STT failures
  • Category classification fallbacks
  • User-friendly error messages in Azerbaijani
  • Detailed logging for debugging

Limitations ⚠️

  • CSV file path is currently hardcoded
  • Embeddings regeneration required for data updates
  • Voice messages require adequate audio quality
  • Azerbaijani language optimization for speech recognition

Future Enhancements πŸš€

  • Support for multiple languages
  • Admin panel for FAQ management
  • Analytics dashboard
  • Conversation history
  • Feedback system
  • Docker containerization
  • Database integration (replace CSV)

Contributing 🀝

Contributions are welcome! Please feel free to submit issues or pull requests.

License πŸ“„

This project is open source and available under the MIT License.

Support πŸ’¬

For questions or support, please open an issue in the GitHub repository.

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages