oneliai 0.3.0__tar.gz → 0.5.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.5.0}/PKG-INFO +1 -1
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai/client.py +44 -25
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai.egg-info/PKG-INFO +1 -1
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai.egg-info/SOURCES.txt +3 -1
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai.egg-info/top_level.txt +1 -0
- oneliai-0.5.0/sdk/__init__.py +0 -0
- oneliai-0.5.0/sdk/client.py +129 -0
- {oneliai-0.3.0 → oneliai-0.5.0}/setup.py +1 -1
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai/__init__.py +0 -0
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai.egg-info/dependency_links.txt +0 -0
- {oneliai-0.3.0 → oneliai-0.5.0}/oneliai.egg-info/requires.txt +0 -0
- {oneliai-0.3.0 → oneliai-0.5.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,23 @@ class AIClient:
|
|
|
184
196
|
|
|
185
197
|
|
|
186
198
|
async def getTaskStatus(self,taskId):
|
|
187
|
-
|
|
199
|
+
data=await self.get_token()
|
|
200
|
+
print(data['token'])
|
|
201
|
+
response =requests.get(f"{URL}/v1/task/task_status/{taskId}",
|
|
202
|
+
headers={'Authorization': f"Bearer {data['token']}"})
|
|
203
|
+
print(response.json())
|
|
188
204
|
if response.status_code == 200:
|
|
189
205
|
return response.json()
|
|
190
206
|
else:
|
|
191
207
|
raise Exception('Failed to request task_status')
|
|
192
208
|
|
|
193
209
|
async def check_task_status(self,task_id):
|
|
210
|
+
print(3)
|
|
211
|
+
|
|
194
212
|
while True:
|
|
195
213
|
try:
|
|
196
|
-
|
|
214
|
+
|
|
215
|
+
response = await self.getTaskStatus(task_id)
|
|
197
216
|
logging.info(response)
|
|
198
217
|
status = response.get('status')
|
|
199
218
|
logging.info(f"Task status: {status}")
|
|
@@ -207,7 +226,7 @@ class AIClient:
|
|
|
207
226
|
await asyncio.sleep(1) # Sleep for 1 second
|
|
208
227
|
|
|
209
228
|
|
|
210
|
-
def getGoodinfofromAmazon(self, asins,filename=None):
|
|
229
|
+
async def getGoodinfofromAmazon(self, asins,filename=None):
|
|
211
230
|
if filename:
|
|
212
231
|
locafile,filename=self.upload_file(filename)
|
|
213
232
|
print(filename)
|
|
@@ -328,20 +347,20 @@ class AIClient:
|
|
|
328
347
|
raise Exception('Failed to request task_status')
|
|
329
348
|
|
|
330
349
|
|
|
331
|
-
async def check_task_status(self,task_id: str) -> dict:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
350
|
+
# async def check_task_status(self,task_id: str) -> dict:
|
|
351
|
+
# response =requests.get(f"{URL}/task/task_status/{task_id}")
|
|
352
|
+
# if response.status_code == 200:
|
|
353
|
+
# ret= response.json()
|
|
354
|
+
# """Mock implementation - replace with actual status check"""
|
|
355
|
+
# return {
|
|
356
|
+
# "status": ret["status"],
|
|
357
|
+
# "result": {
|
|
358
|
+
# "code": 200,
|
|
359
|
+
# "missionid": ret["result"]["missionid"]
|
|
360
|
+
# }
|
|
361
|
+
# }
|
|
362
|
+
# else:
|
|
363
|
+
# raise Exception('Failed to request task_status')
|
|
345
364
|
|
|
346
365
|
async def get_token(self):
|
|
347
366
|
|
|
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
|