-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
75 lines (62 loc) · 1.87 KB
/
index.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
68
69
70
71
72
73
74
75
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 MENTORS.
def index_document_from_file():
"""
Index file document for a particular mentor.
"""
pathway = "" # The pathway here should match the name of the mentor for which the document is being indexed
payload = {"type": "file", "pathway": pathway}
files = [
(
"file",
(
"space_EN.pdf",
open("/path/to/document/space_EN.pdf", "rb"),
"application/pdf",
),
)
]
headers = {"Authorization": f"Api-Token {ACCESS_TOKEN}"}
response = requests.post(
f"{BASE_URL}api/ai-index/orgs/{TENANT}/users/{USERNAME}/documents/train/",
data=payload,
files=files,
headers=headers,
)
if response.ok:
print(response.json())
else:
print(response.status_code)
print(response.text)
def index_document_from_url():
"""
Index url document for a particular mentor.
"""
headers = {
"Authorization": f"Api-Token {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
pathway = "" # The pathway here should match the name of the mentor for which the document is being indexed
url = "" # url of the webpage you want indexed.
data = {
"type": "webcrawler",
"pathway": pathway,
"url": url,
}
response = requests.post(
f"{BASE_URL}api/ai-index/orgs/{TENANT}/users/{USERNAME}/documents/train/",
headers=headers,
data=json.dumps(data),
)
if response.ok:
print(response.json())
else:
print(response.status_code)
print(response.text)