Skip to content

Commit

Permalink
Merge branch 'main' into CAI-191-fix-error-visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobottaro authored Oct 24, 2024
2 parents d6ecd63 + 60bd477 commit a6bb676
Show file tree
Hide file tree
Showing 50 changed files with 1,569 additions and 1,016 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-needles-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": patch
---

Fix chatbot issue with sending empty messages
6 changes: 5 additions & 1 deletion apps/chatbot/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CHB_WEBSITE_URL=...
CHB_REDIS_INDEX_NAME=...
CHB_LLAMAINDEX_INDEX_ID=...
CHB_DOCUMENTATION_DIR=...
CHB_USE_PRESIDIO=...
CHB_GOOGLE_API_KEY=...
CHB_PROVIDER=...
CHB_MODEL_ID=...
Expand All @@ -21,6 +22,9 @@ CHB_MODEL_MAXTOKENS=...
CHB_EMBED_MODEL_ID=...
CHB_ENGINE_SIMILARITY_TOPK=...
CHB_ENGINE_SIMILARITY_CUTOFF=...
CHB_ENGINE_USE_ASYNC=...
CHB_ENGINE_USE_ASYNC=True
CHB_ENGINE_USE_STREAMING=...
CHB_QUERY_TABLE_PREFIX=chatbot-local
CHB_DYNAMODB_URL=http://locahost:8080
CHB_USE_PRESIDIO=True
CHB_SESSION_MAX_DURATION_DAYS=1
27 changes: 18 additions & 9 deletions apps/chatbot/config/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ config_presidio:
-
lang_code: it
model_name: it_core_news_md
# -
# lang_code: de
# model_name: de_core_news_md
# -
# lang_code: es
# model_name: es_core_news_md
# -
# lang_code: fr
# model_name: fr_core_news_md
-
lang_code: es
model_name: es_core_news_md
-
lang_code: de
model_name: de_core_news_md
-
lang_code: fr
model_name: fr_core_news_md
-
lang_code: el
model_name: el_core_news_md
-
lang_code: hr
model_name: hr_core_news_md
-
lang_code: sl
model_name: sl_core_news_md
ner_model_configuration:
labels_to_ignore:
- ORDINAL
Expand Down
10 changes: 8 additions & 2 deletions apps/chatbot/config/prompts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ qa_prompt_str: |
- the answer must be clear, non-redundant, and have not repeated sentences.
- the answer must not include the query.
- If your answer is based on this retrieved context, include a "Rif" section at the end of the response, listing the titles and filenames from the source nodes used. If no context is used, do not include a reference.
- the answer must be with the same language of the query.
--------------------
Output Examples:
Query: Cos'è il nodo dei pagamenti?
Expand All @@ -38,7 +37,14 @@ qa_prompt_str: |
--------------------
Task:
Given the query: {query_str}
Answer the query according to the `Chatbot Policy` listed above.
Reply to the user following these two steps:
Step 1:
Pay great attention in detail on the query's language and determine if it is formulated in Italian, English, Spanish, French, German, Greek, Croatian, or Slovenian ('yes' or 'no').
Step 2:
If Step 1 returns 'yes': reply always in Italian, regardless of the input language, according to the `Chatbot Policy` listed above.
Otherwise: reply you cannot speak that language and ask for a new query written in an accepted language.
Answer:
Expand Down
6 changes: 5 additions & 1 deletion apps/chatbot/docker/app.local.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM python:3.12.4-slim-bullseye
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y \
curl

ENV PYTHONPATH=/app

RUN pip install --upgrade pip \
Expand All @@ -14,4 +18,4 @@ RUN poetry install

COPY . .

CMD ["fastapi", "dev", "src/app/main.py", "--port", "8080"]
CMD ["fastapi", "dev", "src/app/main.py", "--port", "8080", "--host", "0.0.0.0"]
57 changes: 57 additions & 0 deletions apps/chatbot/docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
services:
api:
build:
context: ..
dockerfile: docker/app.local.Dockerfile
ports:
- "8080:8080"
volumes:
- ..:/app
- ./files/.aws:/root/.aws
- ../../nextjs-website/out:/app/build-devp/out
depends_on:
redis:
condition: service_started
dynamodb:
condition: service_started
networks:
- ntw

dynamodb:
image: amazon/dynamodb-local:2.5.2
environment:
- AWS_ACCESS_KEY_ID=dummy
- AWS_SECRET_ACCESS_KEY=dummy
- AWS_DEFAULT_REGION=local
ports:
- "8000:8000"
networks:
- ntw

redis:
image: redis/redis-stack:7.2.0-v13
ports:
- "6379:6379"
- "8001:8001"
networks:
- ntw

create_index:
build:
context: ..
dockerfile: docker/app.local.Dockerfile
ports:
- "8080:8080"
volumes:
- ..:/app
- ../../nextjs-website/out:/app/build-devp/out
command: "python src/modules/create_vector_index.py --params config/params.yaml"
tty: true
depends_on:
redis:
condition: service_started
networks:
- ntw

networks:
ntw:
2 changes: 2 additions & 0 deletions apps/chatbot/docker/docker-compose-run-create_index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose -f docker/compose.yaml -p chatbot run create_index
2 changes: 2 additions & 0 deletions apps/chatbot/docker/docker-compose-up-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose -f docker/compose.yaml -p chatbot up api
2 changes: 2 additions & 0 deletions apps/chatbot/docker/docker-run-create-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose -f docker/compose.yaml -p chatbot up create_index
2 changes: 2 additions & 0 deletions apps/chatbot/docker/docker-run-local-bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker run -it --env-file ./.env fastapi-local bash
2 changes: 2 additions & 0 deletions apps/chatbot/docker/files/.aws/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[profile default]
region = eu-south-1
3 changes: 3 additions & 0 deletions apps/chatbot/docker/files/.aws/credentials
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
aws_access_key_id = 123
aws_secret_access_key = xyz
Loading

0 comments on commit a6bb676

Please sign in to comment.