oneliai 0.3.0__tar.gz → 0.4.0__tar.gz
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.
Potentially problematic release.
This version of oneliai might be problematic. Click here for more details.
- {oneliai-0.3.0 → oneliai-0.4.0}/PKG-INFO +1 -1
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai/client.py +44 -24
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai.egg-info/PKG-INFO +1 -1
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai.egg-info/SOURCES.txt +3 -1
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai.egg-info/top_level.txt +1 -0
- oneliai-0.4.0/sdk/__init__.py +0 -0
- oneliai-0.4.0/sdk/client.py +129 -0
- {oneliai-0.3.0 → oneliai-0.4.0}/setup.py +1 -1
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai/__init__.py +0 -0
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai.egg-info/dependency_links.txt +0 -0
- {oneliai-0.3.0 → oneliai-0.4.0}/oneliai.egg-info/requires.txt +0 -0
- {oneliai-0.3.0 → oneliai-0.4.0}/setup.cfg +0 -0
|
@@ -121,21 +121,26 @@ class AIClient:
|
|
|
121
121
|
else:
|
|
122
122
|
raise Exception('Failed to start suggestion')
|
|
123
123
|
|
|
124
|
-
async def competitor_analysis(self,
|
|
124
|
+
async def competitor_analysis(self,missionid="",asins=[]):
|
|
125
125
|
if not missionid: # Check if missionid is empty
|
|
126
126
|
missionid = str(uuid.uuid4()) # Generate a random UUID
|
|
127
|
+
|
|
127
128
|
task_id = await self.get_competitive_data(missionid,asins)
|
|
128
|
-
|
|
129
|
+
|
|
130
|
+
# logging.info(task_id)
|
|
129
131
|
|
|
130
132
|
if task_id:
|
|
133
|
+
|
|
131
134
|
task = await self.check_task_status(task_id)
|
|
135
|
+
|
|
132
136
|
if task['status'] == "SUCCESS":
|
|
133
137
|
ret=await self.analysis_details(missionid)
|
|
134
138
|
return ret
|
|
135
139
|
|
|
140
|
+
|
|
136
141
|
async def analysis_details(self,missionid):
|
|
137
142
|
response = requests.post(
|
|
138
|
-
f'{
|
|
143
|
+
f'{URL}/v1/conv/analysis/getid',
|
|
139
144
|
json={
|
|
140
145
|
'missionid': missionid
|
|
141
146
|
|
|
@@ -145,22 +150,29 @@ class AIClient:
|
|
|
145
150
|
if response.status_code == 200:
|
|
146
151
|
return response.json()
|
|
147
152
|
else:
|
|
148
|
-
raise Exception('Failed to start
|
|
153
|
+
raise Exception('Failed to start analysis')
|
|
149
154
|
|
|
150
155
|
|
|
151
|
-
async def get_competitive_data(self,asins):
|
|
156
|
+
async def get_competitive_data(self,missionid,asins):
|
|
157
|
+
print(2)
|
|
152
158
|
response = requests.post(
|
|
153
159
|
f'{self.base_url}/competitor_analysis',
|
|
154
160
|
json={
|
|
155
|
-
"asins": asins
|
|
161
|
+
"asins": asins,
|
|
162
|
+
"missionid":missionid
|
|
156
163
|
|
|
157
164
|
},
|
|
158
165
|
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
159
166
|
)
|
|
167
|
+
|
|
160
168
|
if response.status_code == 200:
|
|
161
|
-
|
|
169
|
+
|
|
170
|
+
result=response.json()
|
|
171
|
+
|
|
172
|
+
return result['data']['task_id']
|
|
162
173
|
else:
|
|
163
|
-
raise Exception('Failed to
|
|
174
|
+
raise Exception('Failed to request get_competitive_data')
|
|
175
|
+
|
|
164
176
|
|
|
165
177
|
|
|
166
178
|
#获取所有asins
|
|
@@ -184,16 +196,24 @@ class AIClient:
|
|
|
184
196
|
|
|
185
197
|
|
|
186
198
|
async def getTaskStatus(self,taskId):
|
|
187
|
-
|
|
199
|
+
print("232332")
|
|
200
|
+
data=await self.get_token()
|
|
201
|
+
print(data['token'])
|
|
202
|
+
response =requests.get(f"{URL}/v1/task/task_status/{taskId}",
|
|
203
|
+
headers={'Authorization': f"Bearer {data['token']}"})
|
|
204
|
+
print(response.json())
|
|
188
205
|
if response.status_code == 200:
|
|
189
206
|
return response.json()
|
|
190
207
|
else:
|
|
191
208
|
raise Exception('Failed to request task_status')
|
|
192
209
|
|
|
193
210
|
async def check_task_status(self,task_id):
|
|
211
|
+
print(3)
|
|
212
|
+
|
|
194
213
|
while True:
|
|
195
214
|
try:
|
|
196
|
-
|
|
215
|
+
|
|
216
|
+
response = await self.getTaskStatus(task_id)
|
|
197
217
|
logging.info(response)
|
|
198
218
|
status = response.get('status')
|
|
199
219
|
logging.info(f"Task status: {status}")
|
|
@@ -328,20 +348,20 @@ class AIClient:
|
|
|
328
348
|
raise Exception('Failed to request task_status')
|
|
329
349
|
|
|
330
350
|
|
|
331
|
-
async def check_task_status(self,task_id: str) -> dict:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
351
|
+
# async def check_task_status(self,task_id: str) -> dict:
|
|
352
|
+
# response =requests.get(f"{URL}/task/task_status/{task_id}")
|
|
353
|
+
# if response.status_code == 200:
|
|
354
|
+
# ret= response.json()
|
|
355
|
+
# """Mock implementation - replace with actual status check"""
|
|
356
|
+
# return {
|
|
357
|
+
# "status": ret["status"],
|
|
358
|
+
# "result": {
|
|
359
|
+
# "code": 200,
|
|
360
|
+
# "missionid": ret["result"]["missionid"]
|
|
361
|
+
# }
|
|
362
|
+
# }
|
|
363
|
+
# else:
|
|
364
|
+
# raise Exception('Failed to request task_status')
|
|
345
365
|
|
|
346
366
|
async def get_token(self):
|
|
347
367
|
|
|
File without changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import jwt
|
|
3
|
+
import datetime
|
|
4
|
+
|
|
5
|
+
# URL="https://apis.oneli.chat"
|
|
6
|
+
URL="http://localhost:8085"
|
|
7
|
+
class AICustomerClient:
|
|
8
|
+
def __init__(self, client_id, client_secret, base_url=f'{URL}/v1/strategy'):
|
|
9
|
+
self.client_id = client_id
|
|
10
|
+
self.client_secret = client_secret
|
|
11
|
+
self.base_url = base_url
|
|
12
|
+
self.access_token = self._get_access_token()
|
|
13
|
+
|
|
14
|
+
def _get_access_token(self):
|
|
15
|
+
response = requests.post(
|
|
16
|
+
f'{self.base_url}/auth/token',
|
|
17
|
+
json={
|
|
18
|
+
'client_id': self.client_id,
|
|
19
|
+
'client_secret': self.client_secret,
|
|
20
|
+
'grant_type': 'client_credentials'
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
if response.status_code == 200:
|
|
24
|
+
return response.json().get('access_token')
|
|
25
|
+
else:
|
|
26
|
+
raise Exception('Failed to get access token')
|
|
27
|
+
|
|
28
|
+
def generate_response(self, template_id, variables):
|
|
29
|
+
response = requests.post(
|
|
30
|
+
f'{self.base_url}/dynamic-response',
|
|
31
|
+
json={
|
|
32
|
+
'template_id': template_id,
|
|
33
|
+
'variables': variables
|
|
34
|
+
},
|
|
35
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
36
|
+
)
|
|
37
|
+
if response.status_code == 200:
|
|
38
|
+
return response.json().get('response')
|
|
39
|
+
else:
|
|
40
|
+
return response.json()
|
|
41
|
+
# raise Exception('Failed to generate response')
|
|
42
|
+
|
|
43
|
+
def query_data(self, arg, template_id):
|
|
44
|
+
response = requests.post(
|
|
45
|
+
f'{self.base_url}/query-data',
|
|
46
|
+
json={
|
|
47
|
+
'arg': arg,
|
|
48
|
+
'template_id': template_id
|
|
49
|
+
},
|
|
50
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
51
|
+
)
|
|
52
|
+
if response.status_code == 200:
|
|
53
|
+
return response.json()
|
|
54
|
+
else:
|
|
55
|
+
res=response.json()
|
|
56
|
+
raise Exception(res['error'])
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def query_intention(self, question):
|
|
60
|
+
response = requests.post(
|
|
61
|
+
f'{self.base_url}/query-intention',
|
|
62
|
+
json={
|
|
63
|
+
'question': question
|
|
64
|
+
|
|
65
|
+
},
|
|
66
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
67
|
+
)
|
|
68
|
+
if response.status_code == 200:
|
|
69
|
+
return response.json()
|
|
70
|
+
else:
|
|
71
|
+
raise Exception('Failed to start intention query')
|
|
72
|
+
|
|
73
|
+
def registEndpoint(self, name,endpointpath):
|
|
74
|
+
response = requests.post(
|
|
75
|
+
f'{self.base_url}/createEndpoints',
|
|
76
|
+
json={
|
|
77
|
+
"endpointpath": endpointpath,
|
|
78
|
+
"method": "POST",
|
|
79
|
+
"name":name
|
|
80
|
+
},
|
|
81
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
82
|
+
)
|
|
83
|
+
if response.status_code == 200:
|
|
84
|
+
return response.json()
|
|
85
|
+
else:
|
|
86
|
+
raise Exception('Failed to createEndpoints')
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def createRoles(self, role_name, description):
|
|
91
|
+
response = requests.post(
|
|
92
|
+
f'{self.base_url}/createRoles',
|
|
93
|
+
json={
|
|
94
|
+
"role_name": role_name,
|
|
95
|
+
"description":description
|
|
96
|
+
},
|
|
97
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
98
|
+
)
|
|
99
|
+
if response.status_code == 200:
|
|
100
|
+
return response.json()
|
|
101
|
+
else:
|
|
102
|
+
raise Exception('Failed to createRoles')
|
|
103
|
+
|
|
104
|
+
def roles_endpoint(self, role_id, endpoint_id):
|
|
105
|
+
response = requests.post(
|
|
106
|
+
f'{self.base_url}/roles/{role_id}/endpoints',
|
|
107
|
+
json={
|
|
108
|
+
"endpoint_id": endpoint_id
|
|
109
|
+
},
|
|
110
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
111
|
+
)
|
|
112
|
+
if response.status_code == 200:
|
|
113
|
+
return response.json()
|
|
114
|
+
else:
|
|
115
|
+
raise Exception('Failed to roles_endpoint')
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def user_roles(self, user_id, role_id):
|
|
119
|
+
response = requests.post(
|
|
120
|
+
f'{self.base_url}/users/{user_id}/roles',
|
|
121
|
+
json={
|
|
122
|
+
"role_id": role_id
|
|
123
|
+
},
|
|
124
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
125
|
+
)
|
|
126
|
+
if response.status_code == 200:
|
|
127
|
+
return response.json()
|
|
128
|
+
else:
|
|
129
|
+
raise Exception('Failed to user_roles')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|