diff --git a/guardrails/cli/hub/template.py b/guardrails/cli/hub/template.py index 39b7a57ec..c9785aae4 100644 --- a/guardrails/cli/hub/template.py +++ b/guardrails/cli/hub/template.py @@ -9,19 +9,21 @@ def get_template(template_name: str) -> tuple[dict, str]: if template_name.endswith(".json"): template_file_name = template_name try: - file_path = os.path.join(os.getcwd(), template_name) - with open(file_path, "r") as fin: + file_path = os.path.abspath(template_name) + with open(file_path, "r", encoding="utf-8") as fin: return json.load(fin), template_file_name except FileNotFoundError: raise FileNotFoundError(f"Template file {template_name} not found.") - template_file_name = f"{template_name.split('/')[-1]}.json" + name_split = template_name.split("/") + template_file_base = name_split[-1] + template_file_name = f"{template_file_base}.json" template = get_guard_template(template_name) # write template to file - out_path = os.path.join(os.getcwd(), template_file_name) - with open(out_path, "wt") as file_out: - file_out.write(json.dumps(template, indent=4)) + out_path = os.path.abspath(template_file_name) + with open(out_path, "w", encoding="utf-8") as file_out: + json.dump(template, file_out, indent=4) return template, template_file_name diff --git a/guardrails/cli/server/hub_client.py b/guardrails/cli/server/hub_client.py index 203deea61..afa9907a9 100644 --- a/guardrails/cli/server/hub_client.py +++ b/guardrails/cli/server/hub_client.py @@ -1,17 +1,16 @@ -import sys import os +import sys from string import Template from typing import Any, Dict, Optional +import jwt import requests from guardrails_hub_types import Manifest -import jwt -from jwt import ExpiredSignatureError, DecodeError +from jwt import DecodeError, ExpiredSignatureError - -from guardrails.settings import settings from guardrails.classes.rc import RC from guardrails.cli.logger import logger +from guardrails.settings import settings from guardrails.version import GUARDRAILS_VERSION FIND_NEW_TOKEN = "You can find a new token at https://hub.guardrailsai.com/keys"