Spaces:
Sleeping
Sleeping
initial commit
Browse files- src/main.py +18 -5
src/main.py
CHANGED
|
@@ -9,28 +9,41 @@ from .parameters import *
|
|
| 9 |
from fastapi import FastAPI, Header, HTTPException, BackgroundTasks
|
| 10 |
from fastapi.responses import FileResponse
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
vector_db = VectorDB(emb_model, db_location, full_actions_list_file_path, num_sub_vectors, batch_size)
|
| 16 |
open_ai_connector = OpenAIConnector()
|
| 17 |
|
| 18 |
@app.get("/find-action")
|
| 19 |
async def find_action(query: str):
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
#data = vector_db.get_embedding_db_as_pandas()
|
| 22 |
#print(data)
|
| 23 |
|
| 24 |
|
| 25 |
prefiltered_names, prefiltered_descriptions = vector_db.retrieve_prefiltered_hits(query, K)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
print(prefiltered_names)
|
| 29 |
|
| 30 |
-
|
| 31 |
response = open_ai_connector.query_open_ai(query, prefiltered_names, prefiltered_descriptions)
|
| 32 |
-
|
| 33 |
|
|
|
|
| 34 |
return {'success': True, 'query': query, 'response': response}
|
| 35 |
|
| 36 |
|
|
|
|
| 9 |
from fastapi import FastAPI, Header, HTTPException, BackgroundTasks
|
| 10 |
from fastapi.responses import FileResponse
|
| 11 |
|
| 12 |
+
import logging
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
|
| 18 |
app = FastAPI()
|
| 19 |
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
logger.setLevel(logging.DEBUG)
|
| 23 |
+
logger.addHandler(logging.StreamHandler(sys.stdout))
|
| 24 |
+
|
| 25 |
vector_db = VectorDB(emb_model, db_location, full_actions_list_file_path, num_sub_vectors, batch_size)
|
| 26 |
open_ai_connector = OpenAIConnector()
|
| 27 |
|
| 28 |
@app.get("/find-action")
|
| 29 |
async def find_action(query: str):
|
| 30 |
+
#logging.basicConfig(filename='myapp.log', level=logging.INFO)
|
| 31 |
+
logger.info('Started')
|
| 32 |
+
#print('start action')
|
| 33 |
#data = vector_db.get_embedding_db_as_pandas()
|
| 34 |
#print(data)
|
| 35 |
|
| 36 |
|
| 37 |
prefiltered_names, prefiltered_descriptions = vector_db.retrieve_prefiltered_hits(query, K)
|
| 38 |
|
| 39 |
+
logger.info('prefiltered list')
|
| 40 |
+
#print(prefiltered_names)
|
| 41 |
|
| 42 |
+
logger.info('start query openAI')
|
| 43 |
response = open_ai_connector.query_open_ai(query, prefiltered_names, prefiltered_descriptions)
|
| 44 |
+
logger.info(response)
|
| 45 |
|
| 46 |
+
logger.info('Finished')
|
| 47 |
return {'success': True, 'query': query, 'response': response}
|
| 48 |
|
| 49 |
|