Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
LLM Chat Application
|
| 3 |
+
====================
|
| 4 |
+
|
| 5 |
+
This repository contains a FastAPI application for chatting and question answering using a Large Language Model (LLM). The application supports conversational interactions with memory as well as simple Q&A without conversation history.
|
| 6 |
+
|
| 7 |
+
Features
|
| 8 |
+
--------
|
| 9 |
+
|
| 10 |
+
* **Chat with history**: Interact with the model while maintaining a conversation history.
|
| 11 |
+
* **Simple Q&A**: Ask questions and get answers without maintaining a conversation history.
|
| 12 |
+
* **Streaming Responses**: Receive responses in a streaming fashion.
|
| 13 |
+
|
| 14 |
+
Routes
|
| 15 |
+
------
|
| 16 |
+
|
| 17 |
+
### `/chat`
|
| 18 |
+
|
| 19 |
+
* **Method**: `POST`
|
| 20 |
+
* **Description**: Chat with the model while maintaining conversation history.
|
| 21 |
+
* **Request Body**:
|
| 22 |
+
* `input` (string): The input message from the user.
|
| 23 |
+
* **Response**: Streaming response of the model's reply.
|
| 24 |
+
|
| 25 |
+
### `/ask`
|
| 26 |
+
|
| 27 |
+
* **Method**: `POST`
|
| 28 |
+
* **Description**: Ask a question and get a response without maintaining conversation history.
|
| 29 |
+
* **Request Body**:
|
| 30 |
+
* `input` (string): The input question from the user.
|
| 31 |
+
* **Response**: Streaming response of the model's answer.
|
| 32 |
+
|
| 33 |
+
Getting Started
|
| 34 |
+
---------------
|
| 35 |
+
|
| 36 |
+
### Prerequisites
|
| 37 |
+
|
| 38 |
+
* Python 3.7+
|
| 39 |
+
* Docker (optional, for containerized deployment)
|
| 40 |
+
* A valid `GROQ_API_KEY` (from Groq API)
|
| 41 |
+
|
| 42 |
+
### Installation
|
| 43 |
+
|
| 44 |
+
1. **Clone the repository**:
|
| 45 |
+
|
| 46 |
+
git clone https://github.com/your-username/llm-chat-app.git
|
| 47 |
+
cd llm-chat-app
|
| 48 |
+
|
| 49 |
+
2. **Create a virtual environment and activate it**:
|
| 50 |
+
|
| 51 |
+
python -m venv venv
|
| 52 |
+
source venv/bin/activate # On Windows use `venv\Scripts\activate`
|
| 53 |
+
|
| 54 |
+
3. **Install the dependencies**:
|
| 55 |
+
|
| 56 |
+
pip install -r requirements.txt
|
| 57 |
+
|
| 58 |
+
4. **Create a `.env` file and add your `GROQ_API_KEY`**:
|
| 59 |
+
|
| 60 |
+
echo "GROQ_API_KEY=your_groq_api_key" > .env
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
### Running the Application
|
| 64 |
+
|
| 65 |
+
1. **Start the FastAPI server**:
|
| 66 |
+
|
| 67 |
+
uvicorn main:app --reload
|
| 68 |
+
|
| 69 |
+
2. **The application will be available at** `http://127.0.0.1:8000`.
|
| 70 |
+
|
| 71 |
+
### Using the Application
|
| 72 |
+
|
| 73 |
+
You can interact with the application using tools like `curl`, Postman, or directly from your frontend application.
|
| 74 |
+
|
| 75 |
+
#### Example Requests
|
| 76 |
+
|
| 77 |
+
**Chat with History**:
|
| 78 |
+
|
| 79 |
+
curl -X POST "http://127.0.0.1:8000/chat" -H "Content-Type: application/json" -d '{"input": "Hello, how are you?"}'
|
| 80 |
+
|
| 81 |
+
**Simple Q&A**:
|
| 82 |
+
|
| 83 |
+
curl -X POST "http://127.0.0.1:8000/ask" -H "Content-Type: application/json" -d '{"input": "What is the capital of France?"}'
|
| 84 |
+
|
| 85 |
+
### Testing
|
| 86 |
+
|
| 87 |
+
For testing purposes, you can use the base URL `https://llamachat-ipea.onrender.com/`.
|
| 88 |
+
|
| 89 |
+
**Chat with History**:
|
| 90 |
+
|
| 91 |
+
curl -X POST "https://llamachat-ipea.onrender.com/chat" -H "Content-Type: application/json" -d '{"input": "Hello, how are you?"}'
|
| 92 |
+
|
| 93 |
+
**Simple Q&A**:
|
| 94 |
+
|
| 95 |
+
curl -X POST "https://llamachat-ipea.onrender.com/ask" -H "Content-Type: application/json" -d '{"input": "What is the capital of France?"}'
|
| 96 |
+
|
| 97 |
+
### Docker Deployment (Optional)
|
| 98 |
+
|
| 99 |
+
To run the application in a Docker container:
|
| 100 |
+
|
| 101 |
+
1. **Build the Docker image**:
|
| 102 |
+
|
| 103 |
+
docker build -t llm-chat-app .
|
| 104 |
+
|
| 105 |
+
2. **Run the Docker container**:
|
| 106 |
+
|
| 107 |
+
docker run -d -p 8000:8000 --env-file .env llm-chat-app
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
The application will be available at `http://127.0.0.1:8000`.
|
| 111 |
+
|