Skip to content

Commit 365e1e6

Browse files
committed
Correct readme
1 parent 2482e84 commit 365e1e6

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,20 @@ To build the Docker image for the frontend Streamlit application, run the follow
294294
docker build -t llm-tinyllama-frontend:latest frontend
295295
```
296296

297+
#### Accessing the Services
298+
299+
- To access the frontend in Docker, go to:
300+
301+
```bash
302+
http://localhost:8501
303+
```
304+
- To access the backend in Docker, go to:
305+
306+
```bash
307+
http://localhost:8000/docs
308+
```
309+
**Note**: You can wait a few minutes for the bakcend load the TinyLlama model and be ready to receive requests.
310+
297311
### Running the Docker Image Locally
298312

299313
To run the Docker image for the backend FastAPI application, run the following command:
@@ -371,6 +385,8 @@ To deploy the services with Docker Compose using GitHub Container Registry image
371385
```bash
372386
http://localhost:8000/docs
373387
```
388+
389+
**Note**: You can wait a few minutes for the bakcend load the TinyLlama model and be ready to receive requests.
374390

375391
### Deployment with Kubernetes
376392

@@ -434,7 +450,10 @@ To deploy the backend and frontend services to Kubernetes, follow these steps:
434450

435451
```bash
436452
http://localhost:8000/docs
437-
```
453+
```
454+
455+
**Note**: You can wait a few minutes for the bakcend load the TinyLlama model and be ready to receive requests.
456+
438457
## Running Tests
439458

440459
To run the tests for the backend FastAPI application, run the following command from the root directory:

backend/Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ COPY .env /api
1717
# Expose the port the api runs in
1818
EXPOSE 8000
1919

20-
# Define environment variable
21-
ENV NAME TinyLlamaLLMApi
22-
2320
# Execute the command to run the app when the container starts
2421
CMD ["uvicorn", "main:api", "--host", "0.0.0.0", "--port", "8000"]

docker-compose-ghimages.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ services:
2020
- backend
2121
environment:
2222
- SERVICE_TOKEN=myllservicetoken2024
23+
- RUNNING_IN_DOCKER=true
2324

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ services:
2121
depends_on:
2222
- backend
2323
environment:
24-
- SERVICE_TOKEN=myllservicetoken2024
24+
- SERVICE_TOKEN=myllservicetoken2024
25+
- RUNNING_IN_DOCKER=true

frontend/.env

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
SERVICE_TOKEN=myllservicetoken2024
1+
SERVICE_TOKEN=myllservicetoken2024
2+
LOCAL_API_URL=http://127.0.0.1:8000/api/v1/chat
3+
DOCKER_API_URL=http://host.docker.internal:8000/api/v1/chat

frontend/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ COPY .env /app
1717
# Make port 8501 available to the world outside this container
1818
EXPOSE 8501
1919

20-
# Define environment variable
21-
ENV NAME TinyLlamaLLMFrontend
20+
ENV RUNNING_IN_DOCKER=true
2221

2322
# Run app.py when the container launches
2423
CMD ["streamlit", "run", "main.py", "--server.port=8501", "--server.address=0.0.0.0"]

frontend/app/main.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@
88
import requests, logging, os
99
from dotenv import load_dotenv
1010

11+
# Set up logging
12+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
13+
1114
# Load the environment variables from the .env file
1215
load_dotenv()
16+
17+
# Get the API URL from the environment variables
18+
api_url = os.getenv('DOCKER_API_URL') if os.getenv('RUNNING_IN_DOCKER') else os.getenv('LOCAL_API_URL')
19+
20+
# Loggin api_url
21+
logging.info(f"API URL: {api_url}")
22+
1323
# Static token for the API
1424
STATIC_TOKEN = os.getenv("SERVICE_TOKEN")
1525
# Verify that the SERVICE_TOKEN is defined in the environment variables
1626
if STATIC_TOKEN is None:
1727
raise ValueError("The SERVICE_TOKEN environment variable is not defined")
1828

19-
# Set up logging
20-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
21-
2229
# Default LLM configuration values
2330
DEFAULT_MAX_NEW_TOKENS = 100
2431
DEFAULT_DO_SAMPLE = True
@@ -115,7 +122,7 @@ def main():
115122
# Make a request to the API
116123
try:
117124
with st.spinner("The assistant is thinking..."):
118-
response = requests.post("http://host.docker.internal:8000/api/v1/chat", headers=headers, json=data)
125+
response = requests.post(api_url, headers=headers, json=data)
119126
logging.info(f"Response status code: {response.status_code}")
120127
logging.info(f"Response content: {response.content}")
121128
if response.status_code == 200:

frontend/k8s/deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ spec:
1818
ports:
1919
- containerPort: 8501
2020
env:
21+
- name: RUNNING_IN_DOCKER
22+
value: "true"
2123
- name: SERVICE_TOKEN
2224
valueFrom:
2325
secretKeyRef:

0 commit comments

Comments
 (0)