momegas commited on
Commit
bbbc13b
Β·
1 Parent(s): 3e355cf

πŸ‘€ Add tests to API

Browse files
Files changed (2) hide show
  1. README.md +2 -1
  2. qnabot/tests/test_api.py +21 -0
README.md CHANGED
@@ -44,10 +44,11 @@ app = create_app(QnABot("./mydata"))
44
  - [x] Local data source (directory of documents) or S3 data source
45
  - [x] FAISS for storing vectors / index
46
  - [x] Expose bot over API using FastAPI
 
 
47
  - [ ] Support for other vector databases (e.g. Weaviate, Pinecone)
48
  - [ ] Customise prompt
49
  - [ ] Support for LLaMA model
50
- - [ ] Support for Anthropic models
51
  - [ ] CLI / UI
52
 
53
  ### Here's how it works
 
44
  - [x] Local data source (directory of documents) or S3 data source
45
  - [x] FAISS for storing vectors / index
46
  - [x] Expose bot over API using FastAPI
47
+ - [ ] Integration with [guardrails](https://github.com/ShreyaR/guardrails)
48
+ - [ ] Integration with [GPTCache](https://github.com/zilliztech/GPTCache)
49
  - [ ] Support for other vector databases (e.g. Weaviate, Pinecone)
50
  - [ ] Customise prompt
51
  - [ ] Support for LLaMA model
 
52
  - [ ] CLI / UI
53
 
54
  ### Here's how it works
qnabot/tests/test_api.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from fastapi.testclient import TestClient
3
+ from qnabot import QnABot, create_app
4
+
5
+ bot = QnABot(directory="./examples/files")
6
+ app = create_app(bot)
7
+
8
+ client = TestClient(app)
9
+
10
+
11
+ def test_successful_response():
12
+ response = client.get("/v1/ask/What is your name?")
13
+ assert response.status_code == 200
14
+ assert "answer" in response.json()
15
+ assert isinstance(response.json()["answer"], str)
16
+
17
+
18
+ def test_missing_question_parameter():
19
+ response = client.get("/v1/ask/")
20
+ assert response.status_code == 404
21
+ assert response.json() == {"detail": "Not Found"}