Code for a Telegram bot π specialiced on Pytorch LLM powered
This project aims to simulate a text mesagge chatbot to chat about Pytorch
In this streamlined architecture, the Chatbot History serves as the central repository of the interaction history, supporting both the retrieval of historical context and the logging of new interactions, including full responses from the LLM. The Chatbot UI, Retriever, Vector Database, Prompt Storage, and LLM all play roles in a fluid conversation loop, providing the user a seamless chat experience.
- LLM Usage: Integration with a Large Language Model (LLM) into the conversation
- Langchaing: It use lanchain framework to back and forth with differents LLMs
- Telegram Chatbot API: It is powered by the Telegram API Interface
- Open Source Vectorial Database: The chatbot specialised experience use a vector database to augment the precision of the answers
- Open Source embeddings: It use embedding from open source models
- User Input: The user types an input message in the Chatbot UI.
- Chatbot UI to Chatbot History: This message is sent to the Chatbot History where it is stored.
- Chatbot History to Retriever: The same message is also sent to the Retriever.
- Retriever: The Retriever processes the input message and augments it with information by querying the Vector Database.
- Augmented Message: The Retriever sends this augmented message to the Prompt Storage.
- Prompt Storage: The Prompt Storage receives the augmented message and add all the LLM paramether to query it definig the augmented prompt.
- Augmented Prompt to LLM: This augmented prompt is then sent to the Large Language Model (LLM).
- LLM to requests History: After the LLM generates a response, the full response body is sent to the requests History.
- requests History to Chatbot History: After the full response body is stored, the response content is sent back to the Chatbot History.
- Response to UI: The Chatbot History then sends the LLM's reply to the Chatbot UI.
- Display to User: The Chatbot UI displays the answer to the user.
+--------+--------+ (11)
| |
| Chatbot UI π¬ |
| |
+--------+--------+
^
|
(2) input|(10) output
v
+--------+-----------+
| | (9) response content
| Chatbot History π +<-------------------------------+
| | |
+--------+-----------+ |
| |
| (3) message |
v ^
+-------------------+ +---------+------------+ (4) +---------+-----------+
| | | | | |
|Vector Database πΎ +---------->| Retriever π | | requests History π΅ |
| | | | | |
+-------------------+ +---------+------------+ +---------+-----------+
| ^
| (5) Augmented message |
v |
+--------+---------+ (6) |
| | |
|Prompt Storage π | |
| | |
+--------+---------+ |
| |
| (7) Augmented prompt with LLM params |
| |
v |
+--------+-----------+ |
| | |
| LLM π§ | (8) Generated response |
| (Large Language +--------------------------------+
| Model) |
| |
+--------------------+
Before you begin, make sure you have the following prerequisites:
- Python 3.9 or later installed
- Docker installed
- Do not forget to set the
.env
file it is not ignored on the repo
Follow these steps to set up and run the project:
-
Clone the Repository:
git clone git@github.com:DLesmes/torchbot.git cd torchbot
-
Set Up Python Virtual Environment with the requirements.txt:
python3 -m venv venv source venv/bin/activate python3 -m pip install -r requirements.txt
-
Run the Server:
python3 main.py
You can also debug it in your preferred IDE.
By default a history.json file will be created simulating a no-SQL database that can be develop for next versions this file its mind to be like this:
{
"<user_id>": [
{
"full_chat": [
{
"reply_id": srt, // reply id
"role": "system", // by default the first reply role is the "system"
"content": srt, // message content
"timestamp": int, // timestamp in milliseconds
},
{
"reply_id": str, // reply id
"role": "user", // by default the second reply role is the "user"
"content": srt, // message content
"timestamp": int, // timestamp in milliseconds
},
{
"reply_id": str, // reply id
"role": "assitant", // by default the third reply role is the "assistant"
"content": srt, // message content
"timestamp": int, // timestamp in milliseconds
},
{
"reply_id": str, // reply id
"role": str, // role of the user
"content": srt, // message content
"timestamp": int, // timestamp in milliseconds
}
]
}
]
}
By default a requests.json file will be created simulating a no-SQL database that can be develop for next versions this file its mind to be like this:
{
"<reply_id>": [
{
"user_id": srt, // reply id
"prompt": srt, // message content
"response": int, // timestamp in milliseconds
"timestamp": int, // timestamp in milliseconds
}
]
}
Feel free to contribute and make this chatbot project even better! We welcome contributions from the community! If you'd like to contribute, please follow these steps:
- Fork this repository
- Create a new branch:
git checkout -b feature/YourFeatureName
- Make your changes and commit them:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature/YourFeatureName
- Create a pull request We look forward to your contributions!
For any questions or suggestions, feel free to reach out here is my profile