Skip to content

Commit

Permalink
added hf hub for gguf download
Browse files Browse the repository at this point in the history
  • Loading branch information
rishsriv committed Feb 7, 2024
1 parent cea4c50 commit 3345359
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def package_files(directory):
name="sqlcoder",
packages=find_packages(),
package_data={"sqlcoder": next_static_files},
version="0.2.0",
version="0.2.1",
description="SQLCoder is a large language model for converting text questions in SQL queries.",
author="Defog, Inc",
license="Apache-2",
Expand All @@ -31,7 +31,7 @@ def package_files(directory):
"pandas",
"sqlparse",
"argparse",
"tqdm",
"huggingface-hub",
],
entry_points={
"console_scripts": [
Expand Down
21 changes: 3 additions & 18 deletions sqlcoder/query_routes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from fastapi import APIRouter, Request
import os
import sys
import requests
import tqdm
import json
from defog import Defog
from defog.query import execute_query_once
from huggingface_hub import hf_hub_download

router = APIRouter()

Expand Down Expand Up @@ -54,25 +53,11 @@

if not os.path.exists(filepath):
print(
"Downloading the SQLCoder-7b GGUF file. This is a 4GB file and may take a long time to download..."
"Downloading the SQLCoder-7b GGUF file. This is a 4GB file and may take a long time to download. But once it's downloaded, it will be saved on your machine and you won't have to download it again."
)

# download the gguf file from the internet and save it
url = "https://huggingface.co/defog/sqlcoder-7b-2/blob/main/sqlcoder-7b-q5_k_m.gguf"
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:
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")
hf_hub_download(repo_id="defog/sqlcoder-7b-2", filename="sqlcoder-7b-q5_k_m.gguf", local_dir=defog_path)

if device_type == "apple_silicon":
llm = Llama(model_path=filepath, n_gpu_layers=1, n_ctx=4096)
Expand Down

0 comments on commit 3345359

Please sign in to comment.