Welcome to the DeepSeek Chat Application project! This README provides a comprehensive guide to understanding, setting up, and running the project. It covers everything from retrieving the API key, structuring the project, Docker best practices, and deploying the application using Docker Compose.
- Project Overview
- Retrieving the API Key
- Project Directory Structure
- Python Application Setup
- Docker Setup
- Docker Compose
- Running the Application
- Troubleshooting
- Contributing
- License
The DeepSeek Chat Application is a Python-based web application that interacts with the DeepSeek API to provide chat functionality. The application is built using Flask for the backend and is containerized using Docker for easy deployment. It follows best practices for security, such as storing sensitive data in environment variables and running the application as a non-root user in Docker.
To use the DeepSeek API, you need an API key. Here’s how to retrieve it:
-
Sign Up for DeepSeek:
- Visit the DeepSeek platform and create an account.
- Navigate to the API section in your account dashboard.
-
Generate the API Key:
- Look for the option to generate a new API key.
- Copy the API key and store it securely.
The project is organized as follows:
deepseek-project/
│
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .env # Environment variables (sensitive data)
├── .dockerignore # Files to ignore during Docker build
├── .gitignore # Files to ignore in Git
├── static/ # Static files (CSS, JS)
│ ├── styles.css # CSS for the UI
│ └── script.js # JavaScript for interactivity
└── templates/ # HTML templates
└── index.html # Main UI template
The application requires the following Python packages:
- Flask: For the web server.
- requests: For making HTTP requests to the DeepSeek API.
- python-dotenv: For loading environment variables from a
.env
file.
These dependencies are listed in the requirements.txt
file.
Sensitive data, such as the API key, should never be hardcoded in the application. Instead, use environment variables:
-
Create a
.env
File: Add the API key to a.env
file in the project root:DEEPSEEK_API_KEY=your_api_key_here
-
Load Environment Variables in the App: Use the
python-dotenv
package to load the.env
file in your Flask app:from dotenv import load_dotenv import os load_dotenv() DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
-
Multi-stage Builds:
- Use multi-stage builds to reduce the final image size.
- Install dependencies in the first stage and copy only the necessary files to the final image.
-
Non-root User:
- Run the application as a non-root user for security.
-
Minimize Layers:
- Combine commands to minimize the number of layers in the Docker image.
-
Environment Variables:
- Use environment variables for configuration.
-
Build the Docker Image:
docker build -t deepseek-app .
-
Run the Container: Pass the API key as an environment variable:
docker run -d -p 5000:5000 -e DEEPSEEK_API_KEY=your_api_key_here --name deepseek-container deepseek-app
-
Check the Logs:
docker logs deepseek-container
Docker Compose simplifies running multi-container applications. Here’s how to use it:
-
Create a
docker-compose.yml
File:version: "3.8" services: deepseek-app: image: deepseek-app build: . ports: - "5000:5000" environment: - DEEPSEEK_API_KEY=your_api_key_here restart: unless-stopped
-
Run the Application:
docker-compose up -d
-
Access the Application: Open your browser and navigate to
http://localhost:5000/
. -
Test the Chat Functionality: Enter a message and check the response from the DeepSeek API.
-
API Key Not Found:
- Ensure the API key is correctly set in the
.env
file or passed as an environment variable.
- Ensure the API key is correctly set in the
-
Docker Container Fails to Start:
- Check the logs using
docker logs deepseek-container
. - Ensure all dependencies are installed and the
Dockerfile
is correctly configured.
- Check the logs using
-
Module Not Found:
- Verify that all dependencies are listed in
requirements.txt
and installed during the Docker build.
- Verify that all dependencies are listed in
Contributions are welcome! If you’d like to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
docker run -d -p 5000:5000 -e DEEPSEEK_API_KEY=sk-dc4476dc504a4868a3496ed45bdd93fd --name deepseek-container deepseek-app