Skip to content

Commit e2d66d3

Browse files
committed
Only load hf_token when needed
1 parent e87f0f4 commit e2d66d3

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

llm-complete-guide/steps/rag_deployment.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import webbrowser
33

44
from huggingface_hub import HfApi
5+
6+
from utils.hf_utils import get_hf_token
57
from utils.llm_utils import process_input_with_retrieval
68
from zenml import step
79
from zenml.client import Client
@@ -11,7 +13,6 @@
1113

1214
ZENML_API_TOKEN = secret.secret_values["zenml_api_token"]
1315
ZENML_STORE_URL = secret.secret_values["zenml_store_url"]
14-
HF_TOKEN = os.getenv("HF_TOKEN")
1516
SPACE_USERNAME = os.environ.get("ZENML_HF_USERNAME", "zenml")
1617
SPACE_NAME = os.environ.get("ZENML_HF_SPACE_NAME", "llm-complete-guide-rag")
1718

@@ -50,7 +51,7 @@ def predict(message, history):
5051

5152

5253
def upload_files_to_repo(
53-
api, repo_id: str, files_mapping: dict, token: str = HF_TOKEN
54+
api, repo_id: str, files_mapping: dict, token: str
5455
):
5556
"""Upload multiple files to a Hugging Face repository
5657
@@ -89,7 +90,7 @@ def gradio_rag_deployment() -> None:
8990
space_sdk="gradio",
9091
private=True,
9192
exist_ok=True,
92-
token=HF_TOKEN,
93+
token=get_hf_token(),
9394
)
9495
api.add_space_secret(
9596
repo_id=hf_repo_id,
@@ -112,6 +113,6 @@ def gradio_rag_deployment() -> None:
112113
hf_repo_requirements: "requirements.txt",
113114
}
114115

115-
upload_files_to_repo(api, hf_repo_id, files_to_upload, HF_TOKEN)
116+
upload_files_to_repo(api, hf_repo_id, files_to_upload, get_hf_token())
116117

117118
webbrowser.open(f"https://huggingface.co/spaces/{hf_repo_id}")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from constants import SECRET_NAME
2+
from zenml.client import Client
3+
4+
5+
def get_hf_token() -> str:
6+
api_key = Client().get_secret(SECRET_NAME).secret_values["hf_token"]
7+
8+
return api_key

llm-complete-guide/utils/openai_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from zenml.client import Client
33

44

5-
def get_openai_api_key():
5+
def get_openai_api_key() -> str:
66
api_key = Client().get_secret(SECRET_NAME).secret_values["openai_api_key"]
77

88
return api_key

0 commit comments

Comments
 (0)