JPBianchi commited on
Commit
809d184
1 Parent(s): 5014462

instructions & tests

Browse files
Files changed (4) hide show
  1. Dockerfile +2 -1
  2. README.md +10 -0
  3. app/tests/__init__.py +0 -0
  4. app/tests/test_main.py +36 -0
Dockerfile CHANGED
@@ -11,7 +11,6 @@ COPY ./app /app
11
  WORKDIR /app
12
  RUN mkdir /data
13
 
14
-
15
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
16
  # ^ no caching of the packages to save space
17
 
@@ -22,5 +21,7 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
22
  RUN chmod -R 777 /usr/local/lib/python3.10/site-packages/llama_index/legacy/_static/nltk_cache
23
 
24
  ENV TRANSFORMERS_CACHE=/usr/local/lib/python3.10/site-packages/llama_index/legacy/_static/nltk_cache
 
 
25
 
26
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
11
  WORKDIR /app
12
  RUN mkdir /data
13
 
 
14
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
  # ^ no caching of the packages to save space
16
 
 
21
  RUN chmod -R 777 /usr/local/lib/python3.10/site-packages/llama_index/legacy/_static/nltk_cache
22
 
23
  ENV TRANSFORMERS_CACHE=/usr/local/lib/python3.10/site-packages/llama_index/legacy/_static/nltk_cache
24
+ # ^ not elegant but it works
25
+ # HF warning says that TRANSFORMERS_CACHE will be deprecated in transformers v5, and advise to use HF_HOME
26
 
27
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -9,3 +9,13 @@ license: mit
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
+
13
+ ### How to use the endpoint
14
+
15
+ Please see the notebook 'app/notebooks/upload_index.ipynb' for examples of how to upload docs, index them, delete the data, erase the vector store, do a vector search or a full RAG.
16
+
17
+ One can upload as many documents as he wants, and decide when to index them, and then continue uploading documents, and, again, index them at any time.
18
+
19
+ The code works locally with uvicorn and here on Huggingface.
20
+
21
+ In 'tests/test_main.py', one can find a few ideas about how to test the code. It is of course far from being exhaustive, but I included simple unit tests and also some that test the overall capability of the code, ie answering a question with a LLM, fed by the results of a hybrid search on a Weaviate database.
app/tests/__init__.py ADDED
File without changes
app/tests/test_main.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ sys.path.append("../")
3
+ from main import app
4
+
5
+ from fastapi.testclient import TestClient
6
+
7
+ from settings import datadir
8
+
9
+ client = TestClient(app)
10
+
11
+ def test_read_root():
12
+ response = client.get("/ping/")
13
+ assert response.status_code == 200
14
+ assert int(response.json()['answer']) < 100
15
+
16
+ def test_list_files():
17
+ response = client.get("/list_files/")
18
+ files = os.listdir(datadir)
19
+ assert response.status_code == 200
20
+ assert len(response.json()['files']) == len(files)
21
+ for f in response.json()['files']:
22
+ assert f in files
23
+
24
+ def test_vector_search():
25
+ question_data = {"question": "Does ATT have postpaid phone customers?"}
26
+ response = client.post("/ask/", json=question_data)
27
+ assert response.status_code == 200
28
+ assert len(response.json()['answer']) > 0 # we assume vector store works if it returns something
29
+ assert any(['postpaid' in a.lower() for a in response.json()['answer']])
30
+
31
+
32
+ def test_ragit():
33
+ question_data = {"question": "Does ATT have postpaid phone customers?"}
34
+ response = client.post("/ragit/", json=question_data)
35
+ assert response.status_code == 200
36
+ assert 'yes' in response.json()['answer'].lower()