Skip to content

Commit 22da46a

Browse files
committed
Add prerequisites documentation
1 parent e24e62a commit 22da46a

10 files changed

+104
-50
lines changed

Diff for: Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ run-pgadmin:
133133
echo "$$SERVERS_JSON" > ./pgadmin/servers.json && \
134134
docker volume create pgadmin_data && \
135135
docker compose -f pgadmin.yml up --force-recreate
136-
137-
load-server-pgadmin:
138-
docker exec -it pgadmin python /pgadmin4/setup.py --load-servers servers.json
139136

140137
clean-pgadmin:
141138
docker volume rm pgadmin_data

Diff for: README.md

+69-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Developing web applications can be a challenging process, especially when dealin
1414
- Development Best Practices: We apply code formatting, type checking, and static analysis tools to ensure that the code is readable, robust, and reliable.
1515

1616
## Table of Contents
17-
1. [Set environment variables](#set-environment-variables)
17+
1. [Prerequisites](#prerequisites)
1818
2. [Run the project using Docker containers and forcing build containers](#run-the-project-using-docker-containers-and-forcing-build-containers)
1919
3. [Run project using Docker containers](#run-project-using-docker-containers)
2020
4. [Setup database with initial data](#setup-database-with-initial-data)
@@ -36,10 +36,72 @@ Developing web applications can be a challenging process, especially when dealin
3636
20. [TODO List](#todo-list)
3737
21. [License](#license)
3838

39+
# Prerequisites
40+
3941
## Set environment variables
4042

4143
Create an **.env** file on root folder and copy the content from **.env.example**. Feel free to change it according to your own configuration.
4244

45+
## Docker engine
46+
This project utilizes Docker and Docker Compose, so please ensure that you have installed the latest version compatible with your operating system. If you haven't already installed Docker, you can find detailed instructions on how to do so [here](https://docs.docker.com/engine/install/). Docker desktop can be good for a dev computer.
47+
48+
You can check if it is installed with this command
49+
```
50+
docker --version
51+
```
52+
53+
## Make
54+
"Make" is a build automation tool that is primarily used to manage the compilation and building of software projects. It reads a file called a "Makefile" which specifies a set of rules and dependencies for building a project, and then executes the necessary commands to build the project according to those rules. Depending of your OS you will requiere to install it in different ways.
55+
56+
Mac
57+
```
58+
xcode-select --install
59+
```
60+
61+
Ubuntu
62+
```
63+
sudo apt-get install build-essential
64+
sudo apt-get -y install make
65+
```
66+
67+
You can check if it is installed with this command
68+
```
69+
make --version
70+
```
71+
72+
## Python ">3.9,<3.12"
73+
If you haven't already installed Python. You can download and install python from [here](https://www.python.org/downloads/).
74+
75+
You can check yu python version:
76+
```
77+
python --version
78+
```
79+
80+
## Poetry
81+
82+
Python Poetry is a tool for dependency management and packaging in Python. It provides a modern and efficient approach to managing Python projects' dependencies, virtual environments, and packaging. You can find detailed instructions on how install it [here](https://python-poetry.org/docs/#installing-with-the-official-installer). Poetry manages packages in **pyproject.toml** file; In this project you can find it in the folder backend/app.
83+
84+
You can check if it is installed with this command
85+
```
86+
poetry --version
87+
```
88+
89+
### Dev tip to activate virtual environment
90+
When you are opening python files do this cna help you to vscode detect installed packages.
91+
92+
```
93+
cd backend/app/
94+
poetry shell
95+
```
96+
97+
After that you can show the interpreted path. You can copy that path and set as the default for the project in vscode. Press on **Enter interpreter path ..** and past path.
98+
99+
<p align="center">
100+
<img src="static/python_int.png" align="center"/>
101+
</p>
102+
103+
104+
43105
## Run the project using Docker containers and forcing build containers
44106

45107
*Using docker compose command*
@@ -92,12 +154,7 @@ You can connect to the Database using pgAdmin4 and use the credentials from .env
92154
make run-pgadmin
93155
```
94156

95-
*Load server configuration (It is required just the first time)*
96-
```sh
97-
make load-server-pgadmin
98-
```
99-
100-
This starts pgamin in [http://localhost:15432](http://localhost:15432).
157+
This starts pgamin in [http://localhost:15432](http://localhost:15432). When connecting to db server introduce the password by default it is **postgres** if you didn't change it in .env file.
101158

102159
<p align="center">
103160
<img src="static/tables.png" align="center"/>
@@ -298,13 +355,13 @@ make mypy
298355
```
299356

300357
## Basic chatbot example with Langchain and OpenAI
301-
In addition to its core features, this project template demonstrates how to integrate an basic chatbot powered by Langchain and OpenAI through websockets.
358+
In addition to its core features, this project template demonstrates how to integrate an basic chatbot powered by Langchain and OpenAI through websockets. You can use [PieSocket Websocket Tester](https://chromewebstore.google.com/detail/oilioclnckkoijghdniegedkbocfpnip) to test websockets.
302359

303360
To begin experimenting with the basic chatbot, follow these steps:
304361

305362
1. **Obtain an OpenAI API Key**: You'll need to set the `OPENAI_API_KEY` environment variable, which you can obtain from [OpenAI's platform](https://platform.openai.com/).
306363

307-
2. **Test Websocket Connection**: You can test the websocket connection by using the following URL: [ws://fastapi.localhost/chat/\<USER_ID\>](ws://fastapi.localhost/chat/<USER_ID>). Replace `<USER_ID>` with a user identifier of your choice.
364+
2. **Test Websocket Connection**: You can test the websocket connection by using the following URL: [ws://fastapi.localhost/chat/\<USER_ID\>](ws://fastapi.localhost/chat/<USER_ID>). Replace `<USER_ID>` with a user identifier of your choice. It should be the ID of your user.
308365

309366
3. **Sending and Receiving Messages**: You should be able to send messages to the chatbot using the provided websocket connection. To do this, use the following message structure:
310367

@@ -313,6 +370,9 @@ To begin experimenting with the basic chatbot, follow these steps:
313370
```
314371
Once you send a message, the chatbot will respond with generated responses based on the content of your input.
315372

373+
<p align="center">
374+
<img src="static/ws.png" align="center"/>
375+
</p>
316376

317377
## Inspiration and References
318378

Diff for: backend/app/app/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: UUID):
189189
# Receive and send back the client message
190190
data = await websocket.receive_json()
191191
await ws_ratelimit(websocket)
192-
user_message = IUserMessage.parse_obj(data)
192+
user_message = IUserMessage.model_validate(data)
193193
user_message.user_id = user_id
194194

195195
resp = IChatResponse(
@@ -227,7 +227,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: UUID):
227227
message_id="",
228228
id="",
229229
sender="bot",
230-
message="Sorry, something went wrong. Your user limit of api usages has been reached.",
230+
message="Sorry, something went wrong. Your user limit of api usages has been reached or check your API key.",
231231
type="error",
232232
)
233233
await websocket.send_json(resp.dict())

Diff for: backend/app/app/schemas/common_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TokenType(str, Enum):
2828
class IUserMessage(BaseModel):
2929
"""User message schema."""
3030

31-
user_id: UUID | None
31+
user_id: UUID | None = None
3232
message: str
3333

3434

Diff for: docker-compose-dev.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ services:
1818
- caddy_reverse_proxy:storage.localhost
1919

2020
database:
21-
image: bitnami/postgresql:13.3.0
21+
image: bitnami/postgresql
2222
restart: always
2323
container_name: database
2424
env_file: ".env"
2525
user: root
2626
volumes:
27-
- ./db_docker:/bitnami/postgresql
27+
- db_docker:/bitnami/postgresql
2828
- ./create-dbs.sql:/docker-entrypoint-initdb.d/create-dbs.sql
2929
ports:
3030
- 5454:5432 # Remove this on production
3131
expose:
3232
- 5432
3333
environment:
34-
- POSTGRES_USERNAME=${DATABASE_USER}
35-
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
36-
- POSTGRES_DATABASE=${DATABASE_NAME}
37-
- POSTGRES_HOST_AUTH_METHOD= "trust"
34+
- POSTGRESQL_USERNAME=${DATABASE_USER}
35+
- POSTGRESQL_PASSWORD=${DATABASE_PASSWORD}
36+
- POSTGRESQL_DATABASE=${DATABASE_NAME}
3837

3938
redis_server:
4039
image: redis:alpine
@@ -108,5 +107,6 @@ services:
108107
- caddy_config:/config
109108

110109
volumes:
110+
db_docker:
111111
caddy_data:
112112
caddy_config:

Diff for: docker-compose-sonarqube.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: "3.9"
33
services:
44
sonarqube:
55
container_name: "sonarqube"
6-
image: "sonarqube:9.9.1-community"
6+
image: "sonarqube:9.9.2-community"
77
volumes:
88
- ./sonarqube/extensions:/opt/sonarqube/extensions
99
- ./sonarqube/logs:/opt/sonarqube/logs

Diff for: docker-compose-test.yml

+7-10
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@ services:
2222
- caddy_reverse_proxy:storage.localhost
2323

2424
database:
25-
image: bitnami/postgresql:13.3.0
25+
image: bitnami/postgresql
2626
restart: always
2727
container_name: database
2828
env_file: ".env"
2929
user: root
3030
volumes:
31-
- ./db_docker:/bitnami/postgresql
31+
- db_docker:/bitnami/postgresql
3232
- ./create-dbs.sql:/docker-entrypoint-initdb.d/create-dbs.sql
3333
ports:
3434
- 5454:5432 # Remove this on production
3535
expose:
3636
- 5432
3737
environment:
38-
- POSTGRES_USERNAME=${DATABASE_USER}
39-
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
40-
- POSTGRES_DATABASE=${DATABASE_NAME}
41-
- POSTGRES_HOST_AUTH_METHOD= "trust"
38+
- POSTGRESQL_USERNAME=${DATABASE_USER}
39+
- POSTGRESQL_PASSWORD=${DATABASE_PASSWORD}
40+
- POSTGRESQL_DATABASE=${DATABASE_NAME}
4241

4342
redis_server:
4443
image: redis:alpine
@@ -52,10 +51,7 @@ services:
5251
container_name: celery_worker
5352
restart: always
5453
# platform: linux/arm64/v8
55-
build:
56-
context: ./backend
57-
args:
58-
INSTALL_DEV: "true"
54+
build: ./backend
5955
command: "watchfiles 'celery -A app.core.celery worker -l info' "
6056
volumes:
6157
- ./backend/app:/code
@@ -115,5 +111,6 @@ services:
115111
- caddy_config:/config
116112

117113
volumes:
114+
db_docker:
118115
caddy_data:
119116
caddy_config:

Diff for: docker-compose.yml

+18-18
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ services:
1616
links:
1717
- caddy_reverse_proxy:storage.localhost
1818

19-
database:
20-
image: bitnami/postgresql:13.3.0
21-
restart: always
22-
container_name: database
23-
env_file: ".env"
24-
user: root
25-
volumes:
26-
- ./db_docker:/bitnami/postgresql
27-
- ./create-dbs.sql:/docker-entrypoint-initdb.d/create-dbs.sql
28-
ports:
29-
- 5454:5432 # Remove this on production
30-
expose:
31-
- 5432
32-
environment:
33-
- POSTGRES_USERNAME=${DATABASE_USER}
34-
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
35-
- POSTGRES_DATABASE=${DATABASE_NAME}
36-
- POSTGRES_HOST_AUTH_METHOD= "trust"
19+
## You need to set your external database credentials in .env file or uncomment below lines to run database as container (No recommended because db needs persitence)
20+
# database:
21+
# image: bitnami/postgresql
22+
# restart: always
23+
# container_name: database
24+
# env_file: ".env"
25+
# user: root
26+
# volumes:
27+
# - db_docker:/bitnami/postgresql
28+
# - ./create-dbs.sql:/docker-entrypoint-initdb.d/create-dbs.sql
29+
# ports:
30+
# - 5454:5432 # Remove this on production
31+
# expose:
32+
# - 5432
33+
# environment:
34+
# - POSTGRESQL_USERNAME=${DATABASE_USER}
35+
# - POSTGRESQL_PASSWORD=${DATABASE_PASSWORD}
36+
# - POSTGRESQL_DATABASE=${DATABASE_NAME}
3737

3838

3939
redis_server:

Diff for: static/python_int.png

220 KB
Loading

Diff for: static/ws.png

795 KB
Loading

0 commit comments

Comments
 (0)