Spaces:
Sleeping
Sleeping
pdrMottaS
commited on
Commit
·
f789d71
1
Parent(s):
7a01fd5
add llm endpoint
Browse files- main.py +6 -5
- models/__init__.py +3 -1
- models/prompt.py +5 -0
main.py
CHANGED
@@ -7,7 +7,7 @@ from query_engine import set_query_engine
|
|
7 |
from llama_index.core.indices.struct_store import NLSQLTableQueryEngine
|
8 |
import os
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
-
from models import SQL
|
11 |
import json
|
12 |
|
13 |
app = FastAPI()
|
@@ -43,9 +43,10 @@ async def query_database(query_data: SQL):
|
|
43 |
df = conn.execute(query_data.query).fetch_df()
|
44 |
return JSONResponse(json.loads(df.to_json(orient = "records")))
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
uvicorn.run(app,host='0.0.0.0',port=7860)
|
|
|
7 |
from llama_index.core.indices.struct_store import NLSQLTableQueryEngine
|
8 |
import os
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
+
from models import SQL, Prompt
|
11 |
import json
|
12 |
|
13 |
app = FastAPI()
|
|
|
43 |
df = conn.execute(query_data.query).fetch_df()
|
44 |
return JSONResponse(json.loads(df.to_json(orient = "records")))
|
45 |
|
46 |
+
@app.post("/llm")
|
47 |
+
async def llm(prompt_data: Prompt):
|
48 |
+
global query_engine
|
49 |
+
response = query_engine.query(prompt_data.promt)
|
50 |
+
return JSONResponse({"promt":prompt_data.promt,"response":response})
|
51 |
|
52 |
uvicorn.run(app,host='0.0.0.0',port=7860)
|
models/__init__.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
from .sql_model import SQL
|
|
|
2 |
|
3 |
__all__ = [
|
4 |
-
"SQL"
|
|
|
5 |
]
|
|
|
1 |
from .sql_model import SQL
|
2 |
+
from .prompt import Prompt
|
3 |
|
4 |
__all__ = [
|
5 |
+
"SQL",
|
6 |
+
"Prompt"
|
7 |
]
|
models/prompt.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class Prompt(BaseModel):
|
5 |
+
promt:str
|