-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllm_credentials.py
67 lines (50 loc) · 1.4 KB
/
llm_credentials.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
import requests
# Manager base url to be changed
BASE_URL = "https://base.manager.<DOMAIN>/"
# user details to be changed
TENANT = ""
USERNAME = ""
ACCESS_TOKEN = "" # this must be a tenant api key
# THIS ENDPOINT ALLOWS ONLY TENANT ADMINS TO CREATE LLM CREDENTIALS.
# Details of the llm credentials to be created.
data = {
"name": "openai",
"value": {"key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
"platform": "main",
}
def llm_credential_creation(data):
"""
Create llm credential for a tenant via the API.
"""
headers = {
"Authorization": f"Api-Token {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
response = requests.post(
f"{BASE_URL}api/ai-account/orgs/{TENANT}/credential/",
headers=headers,
data=json.dumps(data),
)
if response.ok:
print(response.json())
else:
print(response.status_code)
print(response.text)
def get_llm_credentials():
"""
Get llm credential for a tenant via the API.
"""
headers = {
"Authorization": f"Api-Token {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
response = requests.get(
f"{BASE_URL}api/ai-account/orgs/{TENANT}/credential/",
headers=headers,
)
if response.ok:
print(response.json())
else:
print(response.status_code)
print(response.text)