Spaces:
Runtime error
Runtime error
🎉Easily expose FastAPI
Browse files- README.md +9 -1
- qnabot/QnABot.py +0 -1
- qnabot/__init__.py +1 -0
- qnabot/api.py +13 -0
README.md
CHANGED
@@ -27,15 +27,23 @@ bot.save_index("index.pickle")
|
|
27 |
bot = QnABot(directory="./mydata", index="index.pickle")
|
28 |
```
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
### Features
|
31 |
|
32 |
- [x] Create a question answering bot over your documents with one line of code using GPT
|
33 |
- [x] Save / load index to reduce costs (Open AI embedings are used to create the index)
|
34 |
- [x] Local data source (directory of documents) or S3 data source
|
35 |
- [x] FAISS for storing vectors / index
|
|
|
36 |
- [ ] Support for other vector databases (e.g. Weaviate, Pinecone)
|
37 |
- [ ] Customise prompt
|
38 |
-
- [ ] Expose API
|
39 |
- [ ] Support for LLaMA model
|
40 |
- [ ] Support for Anthropic models
|
41 |
- [ ] CLI / UI
|
|
|
27 |
bot = QnABot(directory="./mydata", index="index.pickle")
|
28 |
```
|
29 |
|
30 |
+
You can also create a FastAPI app that will expose the bot as an API. You should then be able to visit `http://localhost:8000/docs` to see the API documentation.
|
31 |
+
|
32 |
+
```python
|
33 |
+
from qnabot import QnABot, create_app
|
34 |
+
|
35 |
+
app = create_app(QnABot("./examples/files"))
|
36 |
+
```
|
37 |
+
|
38 |
### Features
|
39 |
|
40 |
- [x] Create a question answering bot over your documents with one line of code using GPT
|
41 |
- [x] Save / load index to reduce costs (Open AI embedings are used to create the index)
|
42 |
- [x] Local data source (directory of documents) or S3 data source
|
43 |
- [x] FAISS for storing vectors / index
|
44 |
+
- [x] Expose bot over API using FastAPI
|
45 |
- [ ] Support for other vector databases (e.g. Weaviate, Pinecone)
|
46 |
- [ ] Customise prompt
|
|
|
47 |
- [ ] Support for LLaMA model
|
48 |
- [ ] Support for Anthropic models
|
49 |
- [ ] CLI / UI
|
qnabot/QnABot.py
CHANGED
@@ -6,7 +6,6 @@ from langchain.chains.qa_with_sources import load_qa_with_sources_chain
|
|
6 |
from langchain.vectorstores.faiss import FAISS
|
7 |
import pickle
|
8 |
import os
|
9 |
-
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
10 |
|
11 |
|
12 |
class QnABot:
|
|
|
6 |
from langchain.vectorstores.faiss import FAISS
|
7 |
import pickle
|
8 |
import os
|
|
|
9 |
|
10 |
|
11 |
class QnABot:
|
qnabot/__init__.py
CHANGED
@@ -1 +1,2 @@
|
|
1 |
from .QnABot import QnABot
|
|
|
|
1 |
from .QnABot import QnABot
|
2 |
+
from .api import create_app
|
qnabot/api.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from qnabot import QnABot
|
3 |
+
|
4 |
+
|
5 |
+
def create_app(bot: QnABot):
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
@app.get("/v1/ask/{question}")
|
9 |
+
async def ask(question: str):
|
10 |
+
answer = bot.get_answer(question)
|
11 |
+
return {"answer": answer}
|
12 |
+
|
13 |
+
return app
|