pdrMottaS commited on
Commit
1f523aa
·
1 Parent(s): d4c6396

change python version

Browse files
Files changed (3) hide show
  1. main.py +4 -3
  2. models/__init__.py +5 -0
  3. models/sql_model.py +5 -0
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
  import uvicorn
@@ -7,6 +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
 
11
  app = FastAPI()
12
 
@@ -31,10 +32,10 @@ def startup():
31
  query_file_path = hf_hub_download(repo_id=dataset_name, filename=duckdb_filename, repo_type="dataset")
32
 
33
  @app.post("/sql")
34
- async def query_database(query:str):
35
  global query_file_path
36
  conn = duckdb.connect(query_file_path,read_only=True)
37
- df = conn.execute(query).fetch_df()
38
  return JSONResponse(df.to_json(orient = "records"))
39
 
40
  # @app.post("/llm")
 
1
+ from fastapi import FastAPI,Req
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
  import uvicorn
 
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
 
12
  app = FastAPI()
13
 
 
32
  query_file_path = hf_hub_download(repo_id=dataset_name, filename=duckdb_filename, repo_type="dataset")
33
 
34
  @app.post("/sql")
35
+ async def query_database(query_data: SQL):
36
  global query_file_path
37
  conn = duckdb.connect(query_file_path,read_only=True)
38
+ df = conn.execute(query_data.query).fetch_df()
39
  return JSONResponse(df.to_json(orient = "records"))
40
 
41
  # @app.post("/llm")
models/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from .sql_model import SQL
2
+
3
+ __all__ = [
4
+ "SQL"
5
+ ]
models/sql_model.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class SQL(BaseModel):
5
+ query:str