Skip to content

Commit

Permalink
Merge branch 'main' into chatbot/llamaindex-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
batdevis committed Nov 26, 2024
2 parents 0890a21 + 7fe96a6 commit e683d64
Show file tree
Hide file tree
Showing 28 changed files with 1,281 additions and 1,025 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ yarn-error.log*

# local env files
.env*.local
.env*.test

# vercel
.vercel
Expand Down
3 changes: 2 additions & 1 deletion apps/chatbot/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.env*
build-devp
.pytest_cache
load-test
6 changes: 6 additions & 0 deletions apps/chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ This script reads the documentation, split it into chucks with gerarchical organ

Check out the params in order to store your vector index accordingly.

## test

```
pytest
```

## Web App

python src/webapp/app.py
Expand Down
5 changes: 1 addition & 4 deletions apps/chatbot/config/params.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
documentation:
path: build-devp/out

vector_index:
path: index
chunk_sizes: [2816, 704, 176]
Expand Down Expand Up @@ -83,4 +80,4 @@ config_presidio:
- id-pay
- ID-Pay
- id-Pay
- ID-pay
- ID-pay
18 changes: 5 additions & 13 deletions apps/chatbot/config/prompts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ qa_prompt_str: |
refine_prompt_str: |
We have the opportunity to refine the original answer (only if needed).
Given the chat history between the user and the assistant here below:
Given the original answer: {existing_answer}, we have the opportunity to refine it (only if needed) with some more context here below:
--------------------
{context_msg}
--------------------
Chatbot Policy:
- the refined answer must be generated using only the context information and not prior knowledge.
- the refined answer must synthesize than the existing answer if the latter longer than 3 sentenses.
- the refined answer must be clear, non-redundant, and have not repeated sentences.
- the refined answer must be respectful and accurate.
- the refined answer must not include any offensive or discriminatory content.
- the refined answer must be in Italian.
--------------------
Task:
Given the User query: {query_str}
Given the original answer: {existing_answer}
Answer with either the original answer or with a refined answer to better answer the user query according to the `Chatbot Policy` listed above.
Given the new context, refine the original answer to better answer the query.
If the context isn't useful, return the original answer.
The answer must be in Italian.
Answer:
condense_prompt_str: |
Expand Down
2 changes: 1 addition & 1 deletion apps/chatbot/docker/app.local.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN wget https://github.com/rphrp1985/selenium_support/raw/main/chrome_114_amd64
ENV PYTHONPATH=/app

RUN pip install --upgrade pip \
&& pip install poetry
&& pip install poetry awscli

WORKDIR /app
COPY pyproject.toml .
Expand Down
42 changes: 42 additions & 0 deletions apps/chatbot/docker/compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:
api-test:
build:
context: ..
dockerfile: docker/app.local.Dockerfile
command: "./scripts/run.test.sh"
env_file: "../.env.test"
ports:
- "8080:8080"
volumes:
- ..:/app
- ./files/.aws:/root/.aws
- ./files/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
healthcheck:
test: ["CMD-SHELL", '[ "$(curl -s -o /dev/null -I -w ''%{http_code}'' http://localhost:8000)" == "400" ]']
interval: 10s
timeout: 10s
retries: 10
networks:
- ntw

redis:
image: redis/redis-stack:7.2.0-v13
networks:
- ntw

networks:
ntw:
2 changes: 2 additions & 0 deletions apps/chatbot/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ services:
build:
context: ..
dockerfile: docker/app.local.Dockerfile
env_file: ../.env.local
command: "./scripts/run.local.sh"
ports:
- "8080:8080"
volumes:
Expand Down
2 changes: 2 additions & 0 deletions apps/chatbot/docker/docker-compose-run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker compose -f docker/compose.test.yaml -p chatbot-test run api-test
2 changes: 1 addition & 1 deletion apps/chatbot/docker/docker-compose-up-api.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker compose --env-file .env -f docker/compose.yaml -p chatbot up api
docker compose -f docker/compose.yaml -p chatbot up api
3 changes: 3 additions & 0 deletions apps/chatbot/docker/docker-run-create-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
docker compose -f docker/compose.yaml -p chatbot run api \
python src/modules/create_vector_index.py --params config/params.yaml
4 changes: 2 additions & 2 deletions apps/chatbot/docker/files/.aws/credentials
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[default]
aws_access_key_id = 123
aws_secret_access_key = xyz
aws_access_key_id = dummy
aws_secret_access_key = dummy
51 changes: 51 additions & 0 deletions apps/chatbot/docker/files/dynamodb_schemas/queries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"TableName": "chatbot-local-queries",
"KeySchema": [
{
"AttributeName": "sessionId",
"KeyType": "HASH"
},
{
"AttributeName": "id",
"KeyType": "RANGE"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "sessionId",
"AttributeType": "S"
},
{
"AttributeName": "createdAt",
"AttributeType": "S"
}
],
"LocalSecondaryIndexes": [
{
"IndexName": "QueriesByCreatedAtIndex",
"KeySchema": [
{
"AttributeName": "sessionId",
"KeyType": "HASH"
},
{
"AttributeName": "createdAt",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
}
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableClass": "STANDARD",
"DeletionProtectionEnabled": true
}
51 changes: 51 additions & 0 deletions apps/chatbot/docker/files/dynamodb_schemas/sessions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"TableName": "chatbot-local-sessions",
"KeySchema": [
{
"AttributeName": "userId",
"KeyType": "HASH"
},
{
"AttributeName": "id",
"KeyType": "RANGE"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "userId",
"AttributeType": "S"
},
{
"AttributeName": "createdAt",
"AttributeType": "S"
}
],
"LocalSecondaryIndexes": [
{
"IndexName": "SessionsByCreatedAtIndex",
"KeySchema": [
{
"AttributeName": "userId",
"KeyType": "HASH"
},
{
"AttributeName": "createdAt",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
}
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableClass": "STANDARD",
"DeletionProtectionEnabled": true
}
11 changes: 7 additions & 4 deletions apps/chatbot/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "chatbot",
"version": "4.0.0",
"private": true
}
"name": "chatbot",
"version": "4.0.0",
"private": true,
"scripts": {
"test": "./docker/docker-compose-run-tests.sh"
}
}
Loading

0 comments on commit e683d64

Please sign in to comment.