worqhat 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- worqhat/__init__.py +10 -0
- worqhat/ai_models/__init__.py +9 -0
- worqhat/ai_models/ai_search.py +41 -0
- worqhat/ai_models/content_mod.py +44 -0
- worqhat/ai_models/image_analysis.py +94 -0
- worqhat/ai_models/image_gen.py +281 -0
- worqhat/ai_models/model_train.py +45 -0
- worqhat/ai_models/text_extract.py +83 -0
- worqhat/ai_models/text_gen.py +177 -0
- worqhat/database_management/Edit.py +140 -0
- worqhat/database_management/Read.py +152 -0
- worqhat/database_management/__init__.py +5 -0
- worqhat/database_management/collection.py +25 -0
- worqhat/test/__init__.py +0 -0
- worqhat/test/test_ai_search.py +38 -0
- worqhat/test/test_content_mod.py +39 -0
- worqhat/test/test_image_analysis.py +52 -0
- worqhat/test/test_image_gen.py +0 -0
- worqhat/test/test_model_train.py +52 -0
- worqhat/test/test_text_extract.py +65 -0
- worqhat/test/test_text_gen.py +66 -0
- worqhat-0.0.1.dist-info/LICENSE +201 -0
- worqhat-0.0.1.dist-info/METADATA +18 -0
- worqhat-0.0.1.dist-info/RECORD +26 -0
- worqhat-0.0.1.dist-info/WHEEL +5 -0
- worqhat-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
def get_ai_response_v2(question="",
|
|
5
|
+
preserve_history=False,
|
|
6
|
+
randomness=0.5,
|
|
7
|
+
stream_data=False,
|
|
8
|
+
conversation_history=[],
|
|
9
|
+
training_data="",
|
|
10
|
+
response_type="text",
|
|
11
|
+
api_key=None):
|
|
12
|
+
url = "https://api.worqhat.com/api/ai/content/v2"
|
|
13
|
+
|
|
14
|
+
payload = {
|
|
15
|
+
"question": question,
|
|
16
|
+
"preserve_history": preserve_history,
|
|
17
|
+
"randomness": randomness,
|
|
18
|
+
"stream_data": stream_data,
|
|
19
|
+
"conversation_history": conversation_history,
|
|
20
|
+
"training_data": training_data,
|
|
21
|
+
"response_type": response_type
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
headers = {"Content-Type": "application/json"}
|
|
25
|
+
|
|
26
|
+
if not api_key:
|
|
27
|
+
api_key = os.getenv("API_KEY")
|
|
28
|
+
|
|
29
|
+
if api_key:
|
|
30
|
+
headers["Authorization"] = "Bearer " + api_key
|
|
31
|
+
else:
|
|
32
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
33
|
+
|
|
34
|
+
response = requests.post(url, json=payload, headers=headers, stream=stream_data)
|
|
35
|
+
|
|
36
|
+
if stream_data:
|
|
37
|
+
for line in response.iter_lines():
|
|
38
|
+
if line:
|
|
39
|
+
if line.startswith(b'data:'):
|
|
40
|
+
json_content = line[len(b'data:'):].decode('utf-8').strip()
|
|
41
|
+
print(json_content)
|
|
42
|
+
else:
|
|
43
|
+
json_response = response.text
|
|
44
|
+
try:
|
|
45
|
+
json_data = json.loads(json_response)
|
|
46
|
+
return(json.dumps(json_data, indent=4))
|
|
47
|
+
except json.JSONDecodeError:
|
|
48
|
+
print(json_response)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_ai_response_v3(question="",
|
|
52
|
+
preserve_history=False,
|
|
53
|
+
randomness=0.5,
|
|
54
|
+
stream_data=False,
|
|
55
|
+
conversation_history=[],
|
|
56
|
+
training_data="",
|
|
57
|
+
response_type="text",
|
|
58
|
+
api_key=None):
|
|
59
|
+
url = "https://api.worqhat.com/api/ai/content/v3"
|
|
60
|
+
|
|
61
|
+
payload = {
|
|
62
|
+
"question": question,
|
|
63
|
+
"preserve_history": preserve_history,
|
|
64
|
+
"randomness": randomness,
|
|
65
|
+
"stream_data": stream_data,
|
|
66
|
+
"conversation_history": conversation_history,
|
|
67
|
+
"training_data": training_data,
|
|
68
|
+
"response_type": response_type
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
headers = {"Content-Type": "application/json"}
|
|
72
|
+
|
|
73
|
+
if not api_key:
|
|
74
|
+
api_key = os.getenv("API_KEY")
|
|
75
|
+
|
|
76
|
+
if api_key:
|
|
77
|
+
headers["Authorization"] = "Bearer " + api_key
|
|
78
|
+
else:
|
|
79
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
80
|
+
|
|
81
|
+
response = requests.post(url, json=payload, headers=headers, stream=stream_data)
|
|
82
|
+
|
|
83
|
+
if stream_data:
|
|
84
|
+
for line in response.iter_lines():
|
|
85
|
+
if line:
|
|
86
|
+
if line.startswith(b'data:'):
|
|
87
|
+
json_content = line[len(b'data:'):].decode('utf-8').strip()
|
|
88
|
+
print(json_content)
|
|
89
|
+
else:
|
|
90
|
+
json_response = response.text
|
|
91
|
+
try:
|
|
92
|
+
json_data = json.loads(json_response)
|
|
93
|
+
print(json.dumps(json_data, indent=4))
|
|
94
|
+
except json.JSONDecodeError:
|
|
95
|
+
print(json_response)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def get_alpha_ai_response(question="",
|
|
99
|
+
preserve_history=False,
|
|
100
|
+
randomness=0.5,
|
|
101
|
+
stream_data=False,
|
|
102
|
+
conversation_history=[],
|
|
103
|
+
training_data="",
|
|
104
|
+
response_type="text",
|
|
105
|
+
api_key=None):
|
|
106
|
+
url = "https://api.worqhat.com/api/ai/content/v3/alpha"
|
|
107
|
+
payload = {
|
|
108
|
+
"question": question,
|
|
109
|
+
"preserve_history": preserve_history,
|
|
110
|
+
"randomness": randomness,
|
|
111
|
+
"stream_data": stream_data,
|
|
112
|
+
"conversation_history": conversation_history,
|
|
113
|
+
"training_data": training_data,
|
|
114
|
+
"response_type": response_type
|
|
115
|
+
}
|
|
116
|
+
headers = {"Content-Type": "application/json"}
|
|
117
|
+
if not api_key:
|
|
118
|
+
api_key = os.getenv("API_KEY")
|
|
119
|
+
if api_key:
|
|
120
|
+
headers["Authorization"] = "Bearer " + api_key
|
|
121
|
+
else:
|
|
122
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
123
|
+
response = requests.request("POST",url, json=payload, headers=headers)
|
|
124
|
+
if stream_data:
|
|
125
|
+
for line in response.iter_lines():
|
|
126
|
+
if line:
|
|
127
|
+
if line.startswith(b'data:'):
|
|
128
|
+
json_content = line[len(b'data:'):].decode('utf-8').strip()
|
|
129
|
+
print(json_content)
|
|
130
|
+
else:
|
|
131
|
+
json_response = response.text
|
|
132
|
+
try:
|
|
133
|
+
json_data = json.loads(json_response)
|
|
134
|
+
print(json.dumps(json_data, indent=4))
|
|
135
|
+
except json.JSONDecodeError:
|
|
136
|
+
print(json_response)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def get_large_ai_response_v2(question="",
|
|
140
|
+
dataset_id="",
|
|
141
|
+
preserve_history=True,
|
|
142
|
+
randomness=0.5,
|
|
143
|
+
stream_data=False,
|
|
144
|
+
conversation_history=[],
|
|
145
|
+
instructions=None,
|
|
146
|
+
api_key=None):
|
|
147
|
+
url = "https://api.worqhat.com/api/ai/content/v2-large/answering"
|
|
148
|
+
payload = {
|
|
149
|
+
"question": question,
|
|
150
|
+
"datasetId": dataset_id,
|
|
151
|
+
"preserve_history": preserve_history,
|
|
152
|
+
"randomness": randomness,
|
|
153
|
+
"stream_data": stream_data,
|
|
154
|
+
"conversation_history": conversation_history,
|
|
155
|
+
"instructions": instructions
|
|
156
|
+
}
|
|
157
|
+
headers = {"Content-Type": "application/json"}
|
|
158
|
+
if not api_key:
|
|
159
|
+
api_key = os.getenv("API_KEY")
|
|
160
|
+
if api_key:
|
|
161
|
+
headers["Authorization"] = "Bearer " + api_key
|
|
162
|
+
else:
|
|
163
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
164
|
+
response = requests.request("POST",url, json=payload, headers=headers)
|
|
165
|
+
if stream_data:
|
|
166
|
+
for line in response.iter_lines():
|
|
167
|
+
if line:
|
|
168
|
+
if line.startswith(b'data:'):
|
|
169
|
+
json_content = line[len(b'data:'):].decode('utf-8').strip()
|
|
170
|
+
print(json_content)
|
|
171
|
+
else:
|
|
172
|
+
json_response = response.text
|
|
173
|
+
try:
|
|
174
|
+
json_data = json.loads(json_response)
|
|
175
|
+
print(json.dumps(json_data, indent=4))
|
|
176
|
+
except json.JSONDecodeError:
|
|
177
|
+
print(json_response)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def add_data_to_collection(collection='', doc_id='', data='',api_key=None ):
|
|
6
|
+
if collection=='':
|
|
7
|
+
return ("Please enter a Collection name")
|
|
8
|
+
if not api_key:
|
|
9
|
+
api_key = os.getenv("API_KEY")
|
|
10
|
+
if not api_key:
|
|
11
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
12
|
+
url = "https://api.worqhat.com/api/collections/data/add"
|
|
13
|
+
headers = {
|
|
14
|
+
"Authorization": "Bearer " + api_key,
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
payload = {
|
|
19
|
+
"collection": collection,
|
|
20
|
+
"docId": doc_id,
|
|
21
|
+
"data": data
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
25
|
+
|
|
26
|
+
return response.text
|
|
27
|
+
|
|
28
|
+
def update_data_in_collection( collection='', doc_id='', data='',api_key=None):
|
|
29
|
+
if collection=='':
|
|
30
|
+
return ("Please enter a Collection name")
|
|
31
|
+
if not api_key:
|
|
32
|
+
api_key = os.getenv("API_KEY")
|
|
33
|
+
if not api_key:
|
|
34
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
35
|
+
url = "https://api.worqhat.com/api/collections/data/update"
|
|
36
|
+
headers = {
|
|
37
|
+
"Authorization": "Bearer " + api_key,
|
|
38
|
+
"Content-Type": "application/json"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
payload = {
|
|
42
|
+
"collection": collection,
|
|
43
|
+
"docId": doc_id,
|
|
44
|
+
"data": data
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
48
|
+
|
|
49
|
+
return response.text
|
|
50
|
+
|
|
51
|
+
def increment_field_in_collection(collection='', doc_id='', field='', increment_value='',api_key=None):
|
|
52
|
+
if collection=='':
|
|
53
|
+
return ("Please enter a Collection name")
|
|
54
|
+
if not api_key:
|
|
55
|
+
api_key = os.getenv("API_KEY")
|
|
56
|
+
if not api_key:
|
|
57
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
58
|
+
url = "https://api.worqhat.com/api/collections/data/increment"
|
|
59
|
+
headers = {
|
|
60
|
+
"Authorization": "Bearer " + api_key,
|
|
61
|
+
"Content-Type": "application/json"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
payload = {
|
|
65
|
+
"collection": collection,
|
|
66
|
+
"docId": doc_id,
|
|
67
|
+
"field": field,
|
|
68
|
+
"increment": increment_value
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
72
|
+
|
|
73
|
+
return response.text
|
|
74
|
+
|
|
75
|
+
def update_array_in_collection(collection='', doc_id='', field='', value='',api_key=None ):
|
|
76
|
+
if collection=='':
|
|
77
|
+
return ("Please enter a Collection name")
|
|
78
|
+
if not api_key:
|
|
79
|
+
api_key = os.getenv("API_KEY")
|
|
80
|
+
if not api_key:
|
|
81
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
82
|
+
url = "https://api.worqhat.com/api/collections/data/array/update/add"
|
|
83
|
+
payload = {
|
|
84
|
+
"collection": collection,
|
|
85
|
+
"docId": doc_id,
|
|
86
|
+
"field": field,
|
|
87
|
+
"arrayUnion": value
|
|
88
|
+
}
|
|
89
|
+
headers = {
|
|
90
|
+
"Authorization": "Bearer " + api_key,
|
|
91
|
+
"Content-Type": "application/json"
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
95
|
+
|
|
96
|
+
return response.text
|
|
97
|
+
|
|
98
|
+
def remove_array_element_from_collection(collection='', doc_id='', field='', value='',api_key=None):
|
|
99
|
+
if collection=='':
|
|
100
|
+
return ("Please enter a Collection name")
|
|
101
|
+
if not api_key:
|
|
102
|
+
api_key = os.getenv("API_KEY")
|
|
103
|
+
if not api_key:
|
|
104
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
105
|
+
url = "https://api.worqhat.com/api/collections/data/array/update/remove"
|
|
106
|
+
payload = {
|
|
107
|
+
"collection": collection,
|
|
108
|
+
"docId": doc_id,
|
|
109
|
+
"field": field,
|
|
110
|
+
"arrayRemove": value
|
|
111
|
+
}
|
|
112
|
+
headers = {
|
|
113
|
+
"Authorization": "Bearer " + api_key,
|
|
114
|
+
"Content-Type": "application/json"
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
118
|
+
|
|
119
|
+
return response.text
|
|
120
|
+
|
|
121
|
+
def delete_doc_from_collection(collection='', doc_id='',api_key=None):
|
|
122
|
+
if collection=='':
|
|
123
|
+
return ("Please enter a Collection name")
|
|
124
|
+
if not api_key:
|
|
125
|
+
api_key = os.getenv("API_KEY")
|
|
126
|
+
if not api_key:
|
|
127
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
128
|
+
url = "https://api.worqhat.com/api/collections/data/delete"
|
|
129
|
+
payload = {
|
|
130
|
+
"collection": collection,
|
|
131
|
+
"docId": doc_id
|
|
132
|
+
}
|
|
133
|
+
headers = {
|
|
134
|
+
"Authorization": "Bearer " + api_key,
|
|
135
|
+
"Content-Type": "application/json"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
response = requests.post(url, json=payload, headers=headers)
|
|
139
|
+
|
|
140
|
+
return response.text
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
def fetch_all_collections(api_key=None):
|
|
5
|
+
if not api_key:
|
|
6
|
+
api_key = os.getenv("API_KEY")
|
|
7
|
+
if not api_key:
|
|
8
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
9
|
+
url = "https://api.worqhat.com/api/collections/fetch-all"
|
|
10
|
+
headers = {
|
|
11
|
+
"Authorization": "Bearer " + api_key
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
response = requests.post("POST",url, headers=headers)
|
|
15
|
+
|
|
16
|
+
return response.text
|
|
17
|
+
|
|
18
|
+
def fetch_all_docs_from_collection(collection='', output_type="json",api_key=None,):
|
|
19
|
+
if collection=='':
|
|
20
|
+
return ("Please enter a Collection name")
|
|
21
|
+
if not api_key:
|
|
22
|
+
api_key = os.getenv("API_KEY")
|
|
23
|
+
if not api_key:
|
|
24
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
25
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/all"
|
|
26
|
+
payload = {
|
|
27
|
+
"collection": collection,
|
|
28
|
+
"outputType": output_type
|
|
29
|
+
}
|
|
30
|
+
headers = {
|
|
31
|
+
"Authorization": "Bearer " + api_key,
|
|
32
|
+
"Content-Type": "application/json"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
36
|
+
|
|
37
|
+
return response.text
|
|
38
|
+
|
|
39
|
+
def fetch_doc_from_collection( collection='', doc_id='',api_key=None):
|
|
40
|
+
if collection=='':
|
|
41
|
+
return ("Please enter a Collection name")
|
|
42
|
+
if not api_key:
|
|
43
|
+
api_key = os.getenv("API_KEY")
|
|
44
|
+
if not api_key:
|
|
45
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
46
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/document"
|
|
47
|
+
payload = {
|
|
48
|
+
"collection": collection,
|
|
49
|
+
"documentId": doc_id
|
|
50
|
+
}
|
|
51
|
+
headers = {
|
|
52
|
+
"Authorization": "Bearer " + api_key,
|
|
53
|
+
"Content-Type": "application/json"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
57
|
+
|
|
58
|
+
return response.text
|
|
59
|
+
|
|
60
|
+
def fetch_doc_count_by_field(collection='', field='',api_key=None):
|
|
61
|
+
if collection=='':
|
|
62
|
+
return ("Please enter a Collection name")
|
|
63
|
+
if not api_key:
|
|
64
|
+
api_key = os.getenv("API_KEY")
|
|
65
|
+
if not api_key:
|
|
66
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
67
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/count"
|
|
68
|
+
payload = {
|
|
69
|
+
"collection": collection,
|
|
70
|
+
"key": field
|
|
71
|
+
}
|
|
72
|
+
headers = {
|
|
73
|
+
"Authorization": "Bearer " + api_key,
|
|
74
|
+
"Content-Type": "application/json"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
78
|
+
|
|
79
|
+
return response.text
|
|
80
|
+
|
|
81
|
+
def fetch_unique_keys_ordered(collection='', field='', order_by='', order_type='',api_key=None):
|
|
82
|
+
if collection=='':
|
|
83
|
+
return ("Please enter a Collection name")
|
|
84
|
+
if not api_key:
|
|
85
|
+
api_key = os.getenv("API_KEY")
|
|
86
|
+
if not api_key:
|
|
87
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
88
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/unique"
|
|
89
|
+
payload = {
|
|
90
|
+
"collection": collection,
|
|
91
|
+
"key": field,
|
|
92
|
+
"orderBy": order_by,
|
|
93
|
+
"orderType": order_type
|
|
94
|
+
}
|
|
95
|
+
headers = {
|
|
96
|
+
"Authorization": "Bearer " + api_key,
|
|
97
|
+
"Content-Type": "application/json"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
101
|
+
|
|
102
|
+
return response.text
|
|
103
|
+
|
|
104
|
+
def fetch_docs_by_query(collection='', queries='', compounding="and", order_by=None, order_type="asc", limit=None, start_after=None, output_type="json",api_key=None ):
|
|
105
|
+
if collection=='':
|
|
106
|
+
return ("Please enter a Collection name")
|
|
107
|
+
if not api_key:
|
|
108
|
+
api_key = os.getenv("API_KEY")
|
|
109
|
+
if not api_key:
|
|
110
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
111
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/query"
|
|
112
|
+
payload = {
|
|
113
|
+
"collection": collection,
|
|
114
|
+
"queries": queries,
|
|
115
|
+
"compounding": compounding,
|
|
116
|
+
"orderBy": order_by,
|
|
117
|
+
"orderType": order_type,
|
|
118
|
+
"limit": limit,
|
|
119
|
+
"startAfter": start_after,
|
|
120
|
+
"outputType": output_type
|
|
121
|
+
}
|
|
122
|
+
headers = {
|
|
123
|
+
"Authorization": "Bearer " + api_key,
|
|
124
|
+
"Content-Type": "application/json"
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
128
|
+
|
|
129
|
+
return response.text
|
|
130
|
+
|
|
131
|
+
def fetch_docs_by_natural_query(collection='', query='', output_type="json",api_key=None ):
|
|
132
|
+
if collection=='':
|
|
133
|
+
return ("Please enter a Collection name")
|
|
134
|
+
if not api_key:
|
|
135
|
+
api_key = os.getenv("API_KEY")
|
|
136
|
+
if not api_key:
|
|
137
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
138
|
+
url = "https://api.worqhat.com/api/collections/data/fetch/natural-query"
|
|
139
|
+
payload = {
|
|
140
|
+
"collection": collection,
|
|
141
|
+
"query": query,
|
|
142
|
+
"outputType": output_type
|
|
143
|
+
}
|
|
144
|
+
headers = {
|
|
145
|
+
"Authorization": "Bearer " + api_key,
|
|
146
|
+
"Content-Type": "application/json"
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
150
|
+
|
|
151
|
+
return response.text
|
|
152
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
def create_collection(collection='', collection_schema='', collection_sort_by='',api_key=None ):
|
|
5
|
+
if collection=='':
|
|
6
|
+
return ("Please enter a Collection name")
|
|
7
|
+
if not api_key:
|
|
8
|
+
api_key = os.getenv("API_KEY")
|
|
9
|
+
if not api_key:
|
|
10
|
+
raise ValueError("API key is missing. Provide it as an argument or in the .env file.")
|
|
11
|
+
url = "https://api.worqhat.com/api/collections/create"
|
|
12
|
+
headers = {
|
|
13
|
+
"Authorization": "Bearer " + api_key,
|
|
14
|
+
"Content-Type": "application/json"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
payload = {
|
|
18
|
+
"collection": collection,
|
|
19
|
+
"collectionSchema": collection_schema,
|
|
20
|
+
"collectionSortBy": collection_sort_by
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
response = requests.post("POST",url, json=payload, headers=headers)
|
|
24
|
+
|
|
25
|
+
return response.text
|
worqhat/test/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import MagicMock
|
|
3
|
+
from ..src.ai_models.ai_search import search_ai_v2, search_ai_v3
|
|
4
|
+
|
|
5
|
+
class TestAISearch(unittest.TestCase):
|
|
6
|
+
|
|
7
|
+
def setUp(self):
|
|
8
|
+
# Mock API key for testing
|
|
9
|
+
self.api_key = "mock_api_key"
|
|
10
|
+
|
|
11
|
+
def test_search_ai_v2(self):
|
|
12
|
+
# Mock response
|
|
13
|
+
mock_response = MagicMock()
|
|
14
|
+
mock_response.text = '{"result": "Test result for AI v2"}'
|
|
15
|
+
requests_mock = MagicMock()
|
|
16
|
+
requests_mock.request.return_value = mock_response
|
|
17
|
+
|
|
18
|
+
with unittest.mock.patch('ai_search.requests', requests_mock):
|
|
19
|
+
result = search_ai_v2(api_key=self.api_key, question="Test question")
|
|
20
|
+
|
|
21
|
+
self.assertEqual(result, '{"result": "Test result for AI v2"}')
|
|
22
|
+
requests_mock.request.assert_called_once()
|
|
23
|
+
|
|
24
|
+
def test_search_ai_v3(self):
|
|
25
|
+
# Mock response
|
|
26
|
+
mock_response = MagicMock()
|
|
27
|
+
mock_response.text = '{"result": "Test result for AI v3"}'
|
|
28
|
+
requests_mock = MagicMock()
|
|
29
|
+
requests_mock.request.return_value = mock_response
|
|
30
|
+
|
|
31
|
+
with unittest.mock.patch('ai_search.requests', requests_mock):
|
|
32
|
+
result = search_ai_v3(api_key=self.api_key, question="Test question")
|
|
33
|
+
|
|
34
|
+
self.assertEqual(result, '{"result": "Test result for AI v3"}')
|
|
35
|
+
requests_mock.request.assert_called_once()
|
|
36
|
+
|
|
37
|
+
if __name__ == '__main__':
|
|
38
|
+
unittest.main()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import MagicMock
|
|
3
|
+
import requests
|
|
4
|
+
from ..src.ai_models.content_mod import content_moderation,image_moderation
|
|
5
|
+
|
|
6
|
+
class TestModeration(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def setUp(self):
|
|
9
|
+
# Mock API key for testing
|
|
10
|
+
self.api_key = "mock_api_key"
|
|
11
|
+
|
|
12
|
+
def test_content_moderation(self):
|
|
13
|
+
# Mock response
|
|
14
|
+
mock_response = MagicMock()
|
|
15
|
+
mock_response.text = '{"result": "Test content moderation result"}'
|
|
16
|
+
requests_mock = MagicMock()
|
|
17
|
+
requests_mock.request.return_value = mock_response
|
|
18
|
+
|
|
19
|
+
with unittest.mock.patch('moderation.requests', requests_mock):
|
|
20
|
+
result = content_moderation(api_key=self.api_key, text_content="Test text content")
|
|
21
|
+
|
|
22
|
+
self.assertEqual(result, '{"result": "Test content moderation result"}')
|
|
23
|
+
requests_mock.request.assert_called_once()
|
|
24
|
+
|
|
25
|
+
def test_image_moderation(self):
|
|
26
|
+
# Mock response
|
|
27
|
+
mock_response = MagicMock()
|
|
28
|
+
mock_response.text = '{"result": "Test image moderation result"}'
|
|
29
|
+
requests_mock = MagicMock()
|
|
30
|
+
requests_mock.request.return_value = mock_response
|
|
31
|
+
|
|
32
|
+
with unittest.mock.patch('moderation.requests', requests_mock):
|
|
33
|
+
result = image_moderation(api_key=self.api_key, image_file=MagicMock(name="mock_image_file"))
|
|
34
|
+
|
|
35
|
+
self.assertEqual(result, '{"result": "Test image moderation result"}')
|
|
36
|
+
requests_mock.request.assert_called_once()
|
|
37
|
+
|
|
38
|
+
if __name__ == '__main__':
|
|
39
|
+
unittest.main()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import MagicMock
|
|
3
|
+
import requests
|
|
4
|
+
from ..src.ai_models.image_analysis import image_analysis, face_detection, facial_comparison
|
|
5
|
+
|
|
6
|
+
class TestImageFunctions(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def setUp(self):
|
|
9
|
+
# Mock API key for testing
|
|
10
|
+
self.api_key = "mock_api_key"
|
|
11
|
+
|
|
12
|
+
def test_image_analysis(self):
|
|
13
|
+
# Mock response
|
|
14
|
+
mock_response = MagicMock()
|
|
15
|
+
mock_response.text = '{"result": "Test image analysis result"}'
|
|
16
|
+
requests_mock = MagicMock()
|
|
17
|
+
requests_mock.request.return_value = mock_response
|
|
18
|
+
|
|
19
|
+
with unittest.mock.patch('your_module.requests', requests_mock):
|
|
20
|
+
result = image_analysis(api_key=self.api_key, images=[MagicMock(name="mock_image")], question="Test question")
|
|
21
|
+
|
|
22
|
+
self.assertEqual(result, '{"result": "Test image analysis result"}')
|
|
23
|
+
requests_mock.request.assert_called_once()
|
|
24
|
+
|
|
25
|
+
def test_face_detection(self):
|
|
26
|
+
# Mock response
|
|
27
|
+
mock_response = MagicMock()
|
|
28
|
+
mock_response.text = '{"result": "Test face detection result"}'
|
|
29
|
+
requests_mock = MagicMock()
|
|
30
|
+
requests_mock.request.return_value = mock_response
|
|
31
|
+
|
|
32
|
+
with unittest.mock.patch('your_module.requests', requests_mock):
|
|
33
|
+
result = face_detection(api_key=self.api_key, image_file=MagicMock(name="mock_image_file"))
|
|
34
|
+
|
|
35
|
+
self.assertEqual(result, '{"result": "Test face detection result"}')
|
|
36
|
+
requests_mock.request.assert_called_once()
|
|
37
|
+
|
|
38
|
+
def test_facial_comparison(self):
|
|
39
|
+
# Mock response
|
|
40
|
+
mock_response = MagicMock()
|
|
41
|
+
mock_response.text = '{"result": "Test facial comparison result"}'
|
|
42
|
+
requests_mock = MagicMock()
|
|
43
|
+
requests_mock.request.return_value = mock_response
|
|
44
|
+
|
|
45
|
+
with unittest.mock.patch('your_module.requests', requests_mock):
|
|
46
|
+
result = facial_comparison(api_key=self.api_key, source_image_file=MagicMock(name="mock_source_image_file"), target_image_file=MagicMock(name="mock_target_image_file"))
|
|
47
|
+
|
|
48
|
+
self.assertEqual(result, '{"result": "Test facial comparison result"}')
|
|
49
|
+
requests_mock.request.assert_called_once()
|
|
50
|
+
|
|
51
|
+
if __name__ == '__main__':
|
|
52
|
+
unittest.main()
|
|
File without changes
|