Registering New AI Models
Relevant source files
The following files were used as context for generating this wiki page:
The GentelmeN-CorE system utilizes a flexible architecture for integrating and switching between various AI models, primarily leveraging the Groq Cloud API for Large Language Models (LLMs) and Hugging Face for image generation. Registering or switching a model involves updating user preferences in a PostgreSQL database and routing requests through the specialized API clients.
Sources: core/bot.py:16-23, core/commands.py:167-180
Model Selection Architecture
Users interact with different AI models through Telegram commands. The system maps these commands to specific model identifiers supported by the Groq infrastructure. This selection is persisted per user, allowing for a customized chat experience.
Model Mapping Logic
The system maintains a mapping between shorthand commands and the full technical model names used for API requests.
| Command | Technical Model Name | Description |
|---|---|---|
/llama | llama-3.3-70b-versatile | High-performance versatile model (Default) |
/fast | llama-3.1-8b-instant | Optimized for low-latency responses |
/qwen | qwen-2.5-32b | Qwen series model integration |
Sources: core/commands.py:167-175, core/database.py:48-50
Persistence Flow
When a user switches a model, the choice is recorded in the users table. The update_user_db function handles the synchronization between the in-memory cache and the database.
Integration Components
Groq LLM Integration
The groq_client is initialized globally and used within the ai_chat function. It retrieves the user's preferred model from the database before making a completion request.
def ai_chat(m):
# ... logic to get user data ...
user_lang, user_model = get_user_data(user_id)
# ... sys_msg preparation ...
reply = (
_groq_client.chat.completions.create(messages=messages, model=user_model)
.choices[0].message.content
)
Sources: core/commands.py:236-258, core/bot.py:23
Hugging Face Image Models
Image generation is handled separately through the generate_image_hf function. Currently, it is hardcoded to use the FLUX.1-schnell model via the Hugging Face Inference API.
Database Schema for Models
The registration of a user's model preference is managed within the users table, which includes a model_name field.
| Field | Type | Default |
|---|---|---|
user_id | BIGINT | PRIMARY KEY |
model_name | TEXT | 'llama-3.3-70b-versatile' |
Sources: core/database.py:18-24
Audio Transcription Model
The system also includes a fixed registration for audio-to-text processing. Voice messages are transcribed using the whisper-large-v3 model via the Groq API.
transcription = _groq_client.audio.transcriptions.create(
file=(tmp_path, audio_file.read()),
model="whisper-large-v3",
)
Sources: core/commands.py:221-224, tests/test_commands.py:269-272
In summary, registering a new AI model in GentelmeN-CorE requires updating the command mapping in core/commands.py, ensuring the model is supported by the Groq or Hugging Face client, and maintaining the model preference within the PostgreSQL database for persistent user sessions.