Intelligent Responses
Relevant source files
The following files were used as context for generating this wiki page:
The Intelligent Responses system is the core communication layer of the GeNCorE bot, designed to provide context-aware, multi-modal, and personalized interactions with users. It leverages Large Language Models (LLMs) via the Groq API, integrates real-time web search for up-to-date information, and supports voice-to-text transcription and image generation.
At its heart, the system utilizes a centralized helper function to manage Telegram message dispatching, ensuring consistent handling of message threads, formatting (Markdown), and link previews across various modules.
Centralized Dispatch Architecture
The primary mechanism for delivering responses is the inteligentna_odpowiedz function. This utility abstracts the Telegram send_message API, providing a uniform interface for all bot commands and automated triggers.
The diagram shows the decision logic for handling Telegram message threads within the response system.
Sources: core/helpers.py:1-17
Core Dispatcher Parameters
| Parameter | Type | Description |
|---|---|---|
bot | Object | The TeleBot instance. |
chat_id | Integer | Unique identifier for the target chat. |
text | String | The content of the response. |
thread_id | Integer/None | Optional ID for specific message threads (topics). |
parse_mode | String | Formatting mode (e.g., 'Markdown'). Defaults to None. |
disable_preview | Boolean | If True, disables web page previews. |
Sources: core/helpers.py:1-5
AI Chat and Contextual Logic
The system maintains a conversation state for each user to provide coherent multi-turn dialogues. Responses are tailored based on user-specific preferences stored in the database, including preferred language and LLM model.
Conversation Flow
- User Preferences: The system retrieves the user's language (EN/PL) and model choice (e.g., Llama, Qwen) from the database or local cache.
- Web Enrichment: If the query contains keywords like "price", "news", or "bitcoin", the system performs a real-time search via Brave Search API to provide "Net Info" context to the LLM.
- History Management: A history of the last 40 messages is maintained per user to ensure context retention.
The sequence diagram illustrates the lifecycle of an AI-driven intelligent response, including database lookups and external API integrations.
Sources: core/commands.py:195-225, core/database.py:46-64, core/integrations.py:8-23
Voice Response Processing
The response system extends to voice messages by converting audio into text before routing it through the standard AI chat or specific command handlers.
- Transcription: Uses the
whisper-large-v3model via Groq. - Routing: If the transcribed text begins with "rysuj" (draw), the system routes the request to the image generation module; otherwise, it proceeds to the AI chat.
- Cleanup: Employs temporary file management to ensure audio files are deleted after processing.
Sources: core/commands.py:164-192, tests/test_commands.py:270-295
Multi-Model Support
Users can customize the "intelligence" of the response by switching between different hosted models. This selection is persisted in the users table.
| Command | Model Name | Description |
|---|---|---|
/llama | llama-3.3-70b-versatile | High-capability versatile model. |
/fast | llama-3.1-8b-instant | Optimized for speed. |
/qwen | qwen-2.5-32b | Alternative high-performance model. |
Sources: core/commands.py:126-138, core/database.py:20-25
Automated Alerts and Monitoring
The system includes a proactive response mechanism through a background price monitor. It continuously checks cryptocurrency prices via the KuCoin API against user-defined thresholds stored in the database.
This flowchart details the logic for background monitoring and proactive response delivery.
Sources: core/bot.py:45-85
Database Schema for Response Personalization
The database tracks user settings that directly influence how the response system behaves.
Sources: core/database.py:14-34
Summary
The Intelligent Responses system in GentelmeN-CorE is a robust framework that combines user preference persistence, multi-modal input handling (voice and text), and external data enrichment (Brave Search and KuCoin). By centralizing response delivery through inteligentna_odpowiedz, the bot maintains a consistent user experience while offering advanced AI capabilities.