Skip to content

Commit

Permalink
added tqdm for better download visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rishsriv committed Dec 6, 2023
1 parent afc4a96 commit 4a9ec72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions defog/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import json
import sqlparse
import tqdm

try:
from llama_cpp import Llama
Expand All @@ -23,13 +24,24 @@

# download the gguf file from the internet and save it
url = "https://storage.googleapis.com/defog-ai/sqlcoder-7b/v2/sqlcoder-7b-q4_k_m.gguf"
r = requests.get(url)
response = requests.get(url, stream=True)

total_size = int(response.headers.get("content-length", 0))
block_size = 1024 # 1 Kibibyte
t = tqdm(total=total_size, unit="B", unit_scale=True, unit_divisor=1024)

with open(filepath, "wb") as f:
f.write(r.content)
for data in response.iter_content(block_size):
t.update(len(data))
f.write(data)

t.close()
if total_size != 0 and t.n != total_size:
print("ERROR, something went wrong while downloading the file")

llm = Llama(model_path=filepath, n_gpu_layers=1)
except Exception as e:
print(e)
print("")


app = FastAPI()
Expand Down Expand Up @@ -224,8 +236,6 @@ async def query_db(request: Request):
with open(filepath, "r") as f:
ddl = f.read()

print(ddl)

user_question = params.get("question")
prompt = f"""# Task
Generate a SQL query to answer the following question:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def package_files(directory):
name="defog",
packages=find_packages(),
package_data={"defog": ["gcp/*", "aws/*"] + next_static_files},
version="0.54.3",
version="0.54.5",
description="Defog is a Python library that helps you generate data queries from natural language questions.",
author="Full Stack Data Pte. Ltd.",
license="MIT",
Expand All @@ -37,6 +37,7 @@ def package_files(directory):
"prompt-toolkit>=3.0.38",
"fastapi",
"uvicorn",
"tqdm",
],
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 4a9ec72

Please sign in to comment.