-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.py
46 lines (37 loc) · 1.48 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from getpass import getpass
import requests
import os
from dotenv import load_dotenv
def fetch_nvapi_key():
# Load environment variables from .env file
load_dotenv()
hard_reset = False ## <-- Set to True if you want to reset your NVIDIA_API_KEY
while "nvapi-" not in os.environ.get("NVIDIA_API_KEY", "") or hard_reset:
try:
assert not hard_reset
response = requests.get("http://docker_router:8070/get_key").json()
assert response.get("nvapi_key")
except:
response = {"nvapi_key": getpass("NVIDIA API Key: ")}
os.environ["NVIDIA_API_KEY"] = response.get("nvapi_key")
try:
requests.post(
"http://docker_router:8070/set_key/",
json={"nvapi_key": os.environ["NVIDIA_API_KEY"]},
).json()
except:
pass
hard_reset = False
if "nvapi-" not in os.environ.get("NVIDIA_API_KEY", ""):
print(
"[!] API key assignment failed. Make sure it starts with `nvapi-` as generated from the model pages."
)
print(
f"Retrieved NVIDIA_API_KEY beginning with \"{os.environ.get('NVIDIA_API_KEY')[:9]}...\""
)
return os.environ.get("NVIDIA_API_KEY")
from langchain_nvidia_ai_endpoints._common import NVEModel
def get_available_models():
nve_model = NVEModel()
print(nve_model.available_models)
return nve_model.available_models