diff --git a/README.md b/README.md index a4b3874..e12d981 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,32 @@ `$ deactivate` -## Deployment Setup +## Local Docker Setup -TBD \ No newline at end of file +1. Generate requirements, (pipreqs only generate requirements for the current project) + +`$ pip install pipreqs` + +`$ pipreqs . --ignore ".venv" ` + +2. Build image + +`$ docker build -t your-image-name:tag .` + +3. Run image + +`$ docker run -d --name your-container-name -p 8501:8501 -v ~/.aws:/root/.aws your-image-name:latest` + +4. Visit localhost:8501 in the browser + +5. Cleanup work: stop container + +`$ docker stop test-container` + +6. Cleanup work: delete container + +`$ docker rm test-container` + +7. Cleanup work: delete image + +`$ docker rmi <image_name>:<tag> ` \ No newline at end of file diff --git a/chatbot.py b/chatbot.py index 4ead4f0..b1b237c 100644 --- a/chatbot.py +++ b/chatbot.py @@ -1,4 +1,5 @@ from utils.db.es import search_vector, search_data +from utils import RAG_utils sparse_index_name = 'rag-dataset-12000-train' dense_index_name = 'rag-dataset-12000-train-vector' @@ -8,7 +9,17 @@ def get_response(prompt, retrieval_selectbox): if retrieval_selectbox == 'Sparse': # BM25 Sparse Retreival response = search_data(prompt, sparse_index_name, num_results=1)[0] + res = response['_source']['sentence'] if response else None else: # Dense Retrieval response = search_vector(prompt, dense_index_name, num_results=1)[0] - return response['_source']['sentence'] if response else None \ No newline at end of file + res = response['_source']['sentence'] if response else None + if res: + # Get generated answer + system_message = """You are a helpful assistant. Answer the user's question in one sentence based on the provided context. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Do NOT start your response with "According to the provided context." """ + user_message_template = """Context: {context} Question: {question}""" + user_message = user_message_template.format(context=response, question=prompt) + + res = RAG_utils.gen_text_ollama(sys_msg=system_message, user_msg=user_message, + options={'seed': 0, 'temperature': 0.01}) + return res \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ed6f7c4..9db23e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,85 +1,13 @@ -aiohttp==3.9.5 -aiosignal==1.3.1 -altair==5.3.0 -annotated-types==0.6.0 -async-timeout==4.0.3 -attrs==23.2.0 -blinker==1.8.1 boto3==1.34.98 -botocore==1.34.98 -cachetools==5.3.3 -certifi==2024.2.2 -charset-normalizer==3.3.2 -click==8.1.7 -dataclasses-json==0.6.5 elasticsearch==7.13.4 -filelock==3.14.0 -frozenlist==1.4.1 -fsspec==2024.3.1 -gitdb==4.0.11 -GitPython==3.1.43 -huggingface-hub==0.23.0 -idna==3.7 -Jinja2==3.1.3 -jmespath==1.0.1 -joblib==1.4.2 -jsonpatch==1.33 -jsonpointer==2.4 -jsonschema==4.22.0 -jsonschema-specifications==2023.12.1 -langchain-community==0.0.36 -langchain-core==0.1.50 -langsmith==0.1.54 -markdown-it-py==3.0.0 -MarkupSafe==2.1.5 -marshmallow==3.21.2 -mdurl==0.1.2 -mpmath==1.3.0 -multidict==6.0.5 -mypy-extensions==1.0.0 -networkx==3.2.1 -numpy==1.26.4 -orjson==3.10.3 -packaging==23.2 +langchain_community==0.0.36 +langchain_text_splitters==0.0.1 +nltk==3.8.1 +ollama==0.1.9 pandas==2.2.2 -pillow==10.3.0 -protobuf==4.25.3 -pyaml==24.4.0 -pyarrow==16.0.0 -pydantic==2.7.1 -pydantic_core==2.18.2 -pydeck==0.9.0 -Pygments==2.18.0 -python-dateutil==2.9.0.post0 -pytz==2024.1 PyYAML==6.0.1 -referencing==0.35.1 -regex==2024.4.28 -requests==2.31.0 -requests-aws4auth==1.2.3 -rich==13.7.1 -rpds-py==0.18.0 -s3transfer==0.10.1 -safetensors==0.4.3 -scikit-learn==1.4.2 -scipy==1.13.0 -sentence-transformers==2.7.0 -six==1.16.0 -smmap==5.0.1 -SQLAlchemy==2.0.30 +PyYAML==6.0.1 +requests_aws4auth==1.2.3 streamlit==1.34.0 -sympy==1.12 -tenacity==8.2.3 -threadpoolctl==3.5.0 -tokenizers==0.19.1 -toml==0.10.2 -toolz==0.12.1 -torch==2.3.0 -tornado==6.4 +tqdm==4.65.0 tqdm==4.66.4 -transformers==4.40.1 -typing-inspect==0.9.0 -typing_extensions==4.11.0 -tzdata==2024.1 -urllib3==1.26.18 -yarl==1.9.4