The CS50 AI Chatbot is designed to provide an interactive chatting experience using artificial intelligence. Built on the Flask framework and leveraging the power of Mistral AI, this project demonstrates the integration of AI with web applications. Users can interact with the chatbot through a web interface, and the chatbot can respond intelligently based on the inputs provided.
Ensure you have the following installed:
You will also need MISTRAL_API_KEY
as an environmental variable. To get it, visit mistral.ai and
generate an API token. Place it into your IDE configuration or use a .env file.
For example, in PyCharm:
Run
-> Edit Configurations
.MISTRAL_API_KEY
with the value of your API token.Navigate to the folder where app.py
is located and create a .env file:
echo "export MISTRAL_API_KEY=<YOUR_API_TOKEN>" >> .env
Ensure your code loads the environment variables correctly. You can use the python-dotenv
package to manage your
environment variables. Update your code as follows:
from dotenv import load_dotenv
import os
# Load environment variables (if .env is in the same folder)
load_dotenv()
# Change ChatBot initialization (global scope)
bot = ChatBot(api_key=os.getenv("MISTRAL_API_KEY"), model=DEFAULT_MODEL, system_message="", temperature=DEFAULT_TEMPERATURE)
To start the project, open a terminal in the folder where app.py
is located and run:
flask run
This will start the Flask development server. You can then open your web browser and navigate to http://127.0.0.1:5000
to interact with the chatbot.
Here’s a brief overview of the project’s structure:
The application provides secure login and registration functionality using Flask-Session to manage user sessions. Passwords are hashed for security.
Users can start new chats or continue previous ones. Each chat is associated with a user and stored in the database. The chat interface displays the conversation history and allows users to send new messages.
The chatbot uses Mistral AI to generate responses based on user inputs. The integration is handled by the ChatBot
class, which sends user inputs to the Mistral API and processes the responses.
After setting up the environment and starting the Flask server, follow these steps to use the chatbot:
If you encounter issues, check the following:
MISTRAL_API_KEY
is correctly set.requirements.txt
) or run:
pip install -r requirements.txt
http://127.0.0.1:5000
.To further enhance the chatbot, consider implementing the following features:
main
branch.Contributions to the project are welcome. If you have ideas for new features or improvements, feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
For any questions or feedback, please reach out to me on GitHub.
By following this guide and using the provided code, you should be able to set up and run the CS50 AI Chatbot successfully. Happy chatting!