Skip to content

Commit cd8d0fc

Browse files
pavanjavapavanmantha
andauthored
Remaining litserve impl (#35)
* -modified fastapi to litserve * -modified env to include default key * -fixed the react instance bug --------- Co-authored-by: pavanmantha <pavan.mantha@thevaslabs.io>
1 parent c77ff67 commit cd8d0fc

File tree

55 files changed

+280
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+280
-679
lines changed

bootstraprag/templates/llamaindex/rag_with_flare/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ WARN = 30
1919
INFO = 20
2020
DEBUG = 10
2121
NOTSET = 0
22+
23+
LIT_SERVER_PORT=8000
24+
LIT_SERVER_WORKERS_PER_DEVICE=4

bootstraprag/templates/llamaindex/rag_with_flare/api_core/__init__.py

Whitespace-only changes.

bootstraprag/templates/llamaindex/rag_with_flare/api_core/config.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

bootstraprag/templates/llamaindex/rag_with_flare/api_routes/__init__.py

Whitespace-only changes.

bootstraprag/templates/llamaindex/rag_with_flare/api_routes/apis.py

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from abc import ABC
2+
from dotenv import load_dotenv, find_dotenv
3+
from base_rag import BaseRAG
4+
import litserve as ls
5+
import os
6+
7+
_ = load_dotenv(find_dotenv())
8+
9+
10+
class ReactRAGServingAPI(ls.LitAPI, ABC):
11+
def __init__(self):
12+
self.base_rag = None
13+
14+
def setup(self, devices):
15+
self.base_rag = BaseRAG(show_progress=True, data_path='data')
16+
17+
def decode_request(self, request, **kwargs):
18+
return request["query"]
19+
20+
def predict(self, query: str):
21+
try:
22+
return self.base_rag.query(query_string=query)
23+
except Exception as e:
24+
return e.args[0]
25+
26+
def encode_response(self, output, **kwargs):
27+
return {'response': output}
28+
29+
30+
if __name__ == '__main__':
31+
api = ReactRAGServingAPI()
32+
server = ls.LitServer(lit_api=api, api_path='/api/v1/chat-completion',
33+
workers_per_device=int(os.environ.get('LIT_SERVER_WORKERS_PER_DEVICE')))
34+
server.run(port=os.environ.get('LIT_SERVER_PORT'))

bootstraprag/templates/llamaindex/rag_with_flare/apis.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

bootstraprag/templates/llamaindex/rag_with_flare/models/__init__.py

Whitespace-only changes.

bootstraprag/templates/llamaindex/rag_with_flare/models/payload.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

bootstraprag/templates/llamaindex/rag_with_flare/readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@
66
- In the data folder place your data preferably any ".pdf"
77
#### Note: ensure your qdrant and ollama (if LLM models are pointing to local) are running
88
- run `python main.py`
9+
10+
### How to expose RAG as API
11+
- run `python api_server.py`
12+
- verify the swagger redoc and documentation as below
13+
- open browser and hit `http://localhost:8000/redoc`
14+
- open browser and hit `http://localhost:8000/docs`
15+
16+
### Payload Specification
17+
18+
- Method: POST
19+
- API: http://localhost:8000/api/v1/chat-completion
20+
- Body:
21+
```json
22+
{
23+
"query": "explain mlops architecture"
24+
}
25+
```

0 commit comments

Comments
 (0)