oneliai 0.1.0__py3-none-any.whl → 0.3.0__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.
Potentially problematic release.
This version of oneliai might be problematic. Click here for more details.
- oneliai/client.py +337 -61
- {oneliai-0.1.0.dist-info → oneliai-0.3.0.dist-info}/METADATA +1 -1
- oneliai-0.3.0.dist-info/RECORD +8 -0
- oneliai-0.1.0.dist-info/RECORD +0 -8
- {oneliai-0.1.0.dist-info → oneliai-0.3.0.dist-info}/WHEEL +0 -0
- {oneliai-0.1.0.dist-info → oneliai-0.3.0.dist-info}/top_level.txt +0 -0
oneliai/client.py
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import requests
|
|
2
|
+
import asyncio
|
|
3
|
+
import uuid
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
URL="https://apis.oneli.chat"
|
|
8
|
+
# URL="http://localhost:8085"
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
URL="http://localhost:8085"
|
|
10
|
+
appurl="http://localhost:3000"
|
|
5
11
|
class AIClient:
|
|
6
12
|
def __init__(self, client_id, client_secret, base_url=f'{URL}/v1/strategy'):
|
|
7
13
|
self.client_id = client_id
|
|
@@ -23,10 +29,11 @@ class AIClient:
|
|
|
23
29
|
else:
|
|
24
30
|
raise Exception('Failed to get access token')
|
|
25
31
|
|
|
26
|
-
def generate_response(self, template_id, variables):
|
|
32
|
+
def generate_response(self, question,template_id, variables):
|
|
27
33
|
response = requests.post(
|
|
28
34
|
f'{self.base_url}/dynamic-response',
|
|
29
35
|
json={
|
|
36
|
+
'question':question,
|
|
30
37
|
'template_id': template_id,
|
|
31
38
|
'variables': variables
|
|
32
39
|
},
|
|
@@ -66,6 +73,7 @@ class AIClient:
|
|
|
66
73
|
if response.status_code == 200:
|
|
67
74
|
return response.json()
|
|
68
75
|
else:
|
|
76
|
+
|
|
69
77
|
raise Exception('Failed to start intention query')
|
|
70
78
|
|
|
71
79
|
def voc(self,productname,text):
|
|
@@ -95,62 +103,330 @@ class AIClient:
|
|
|
95
103
|
if response.status_code == 200:
|
|
96
104
|
return response.json()
|
|
97
105
|
else:
|
|
98
|
-
|
|
106
|
+
res=response.json()
|
|
107
|
+
raise Exception(f'Failed to start voc,reason:{res["error"]}')
|
|
108
|
+
|
|
109
|
+
#选品建议
|
|
110
|
+
def suggestion(self, selected_products):
|
|
111
|
+
response = requests.post(
|
|
112
|
+
f'{self.base_url}/suggestion',
|
|
113
|
+
json={
|
|
114
|
+
"final_selected_products": selected_products
|
|
115
|
+
|
|
116
|
+
},
|
|
117
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
118
|
+
)
|
|
119
|
+
if response.status_code == 200:
|
|
120
|
+
return response.json()
|
|
121
|
+
else:
|
|
122
|
+
raise Exception('Failed to start suggestion')
|
|
123
|
+
|
|
124
|
+
async def competitor_analysis(self,asins,missionid=""):
|
|
125
|
+
if not missionid: # Check if missionid is empty
|
|
126
|
+
missionid = str(uuid.uuid4()) # Generate a random UUID
|
|
127
|
+
task_id = await self.get_competitive_data(missionid,asins)
|
|
128
|
+
logging.info(task_id)
|
|
129
|
+
|
|
130
|
+
if task_id:
|
|
131
|
+
task = await self.check_task_status(task_id)
|
|
132
|
+
if task['status'] == "SUCCESS":
|
|
133
|
+
ret=await self.analysis_details(missionid)
|
|
134
|
+
return ret
|
|
135
|
+
|
|
136
|
+
async def analysis_details(self,missionid):
|
|
137
|
+
response = requests.post(
|
|
138
|
+
f'{self.base_url}/conv/analysis/getid',
|
|
139
|
+
json={
|
|
140
|
+
'missionid': missionid
|
|
141
|
+
|
|
142
|
+
},
|
|
143
|
+
headers={"Content-Type": "application/json"}
|
|
144
|
+
)
|
|
145
|
+
if response.status_code == 200:
|
|
146
|
+
return response.json()
|
|
147
|
+
else:
|
|
148
|
+
raise Exception('Failed to start suggestion')
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
async def get_competitive_data(self,asins):
|
|
152
|
+
response = requests.post(
|
|
153
|
+
f'{self.base_url}/competitor_analysis',
|
|
154
|
+
json={
|
|
155
|
+
"asins": asins
|
|
156
|
+
|
|
157
|
+
},
|
|
158
|
+
headers={'Authorization': f'Bearer {self.access_token}'}
|
|
159
|
+
)
|
|
160
|
+
if response.status_code == 200:
|
|
161
|
+
return response.json()
|
|
162
|
+
else:
|
|
163
|
+
raise Exception('Failed to start suggestion')
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
#获取所有asins
|
|
167
|
+
async def productList(self,missionid):
|
|
168
|
+
data=await self.get_token()
|
|
169
|
+
print(data['token'])
|
|
170
|
+
response = requests.post(
|
|
171
|
+
f"{URL}/v1/agent/productList",
|
|
172
|
+
json={
|
|
173
|
+
'missionid':missionid
|
|
174
|
+
},
|
|
175
|
+
headers={'Authorization': f"Bearer {data['token']}"}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
print(response)
|
|
179
|
+
if response.status_code == 200:
|
|
180
|
+
return response.json()
|
|
181
|
+
else:
|
|
182
|
+
raise Exception('Failed to request task_status')
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
async def getTaskStatus(self,taskId):
|
|
187
|
+
response =requests.get(f"{URL}/task/task_status/{taskId}")
|
|
188
|
+
if response.status_code == 200:
|
|
189
|
+
return response.json()
|
|
190
|
+
else:
|
|
191
|
+
raise Exception('Failed to request task_status')
|
|
192
|
+
|
|
193
|
+
async def check_task_status(self,task_id):
|
|
194
|
+
while True:
|
|
195
|
+
try:
|
|
196
|
+
response = await self.get_task_status(task_id)
|
|
197
|
+
logging.info(response)
|
|
198
|
+
status = response.get('status')
|
|
199
|
+
logging.info(f"Task status: {status}")
|
|
200
|
+
|
|
201
|
+
if status == "SUCCESS":
|
|
202
|
+
return {"status": "SUCCESS", "result": response.get('result')}
|
|
203
|
+
|
|
204
|
+
except Exception as error:
|
|
205
|
+
logging.error(f"Error checking task status: {error}")
|
|
206
|
+
|
|
207
|
+
await asyncio.sleep(1) # Sleep for 1 second
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def getGoodinfofromAmazon(self, asins,filename=None):
|
|
211
|
+
if filename:
|
|
212
|
+
locafile,filename=self.upload_file(filename)
|
|
213
|
+
print(filename)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
response=self.create_asin_mission(locafile,filename)
|
|
217
|
+
asins=response['asins']
|
|
218
|
+
|
|
219
|
+
response = requests.post(
|
|
220
|
+
f'{appurl}/api/run-task',
|
|
221
|
+
json={
|
|
222
|
+
"type": "asin",
|
|
223
|
+
"data":{"asins": asins}
|
|
224
|
+
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
if response.status_code == 200:
|
|
230
|
+
return response.json()
|
|
231
|
+
else:
|
|
232
|
+
raise Exception('Failed to run task')
|
|
233
|
+
|
|
234
|
+
async def getAsinfromAmazon(self,title,keywords):
|
|
235
|
+
missionid = str(uuid.uuid4())
|
|
236
|
+
await self.update_mission("app_"+missionid, title,keywords)
|
|
237
|
+
response = requests.post(
|
|
238
|
+
f'{appurl}/api/run-task',
|
|
239
|
+
json={
|
|
240
|
+
"type": "list",
|
|
241
|
+
"data":{"keywords":keywords,"missionid":"app_"+missionid}
|
|
242
|
+
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# if response.status_code == 202:
|
|
249
|
+
# task_id = response.json()['task_id']
|
|
250
|
+
# print(f"Task started with ID: {task_id}")
|
|
251
|
+
# return task_id
|
|
252
|
+
#print(response)
|
|
253
|
+
if response.status_code == 200:
|
|
254
|
+
return response.json()
|
|
255
|
+
else:
|
|
256
|
+
raise Exception('Failed to run task')
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def upload_file(self,file_path):
|
|
260
|
+
url =f"{URL}/v1/task/upload"
|
|
261
|
+
file_name = os.path.basename(file_path)
|
|
262
|
+
with open(file_path, 'rb') as f:
|
|
263
|
+
files = {'file': (file_name, f)}
|
|
264
|
+
response = requests.post(url, files=files)
|
|
265
|
+
|
|
266
|
+
if response.status_code == 200:
|
|
267
|
+
data = response.json()
|
|
268
|
+
print(f"Uploaded filename: {data['filename']}")
|
|
269
|
+
return file_name,data['filename']
|
|
270
|
+
else:
|
|
271
|
+
print(f"Upload failed: {response.text}")
|
|
272
|
+
return None
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
async def create_asin_mission(self,locafile,filename):
|
|
276
|
+
# Start ASIN extraction process
|
|
277
|
+
task_id = await self.create_asin_mission_api(filename)
|
|
278
|
+
|
|
279
|
+
if task_id:
|
|
280
|
+
task = await self.check_task_status(task_id)
|
|
281
|
+
|
|
282
|
+
if task["status"] == "SUCCESS" and task["result"]["code"] == 200:
|
|
283
|
+
missionid = task["result"]["missionid"]
|
|
284
|
+
|
|
285
|
+
# Generate report title using AI
|
|
286
|
+
gentitle_prompt = f"""
|
|
287
|
+
以下是选品报告标题的关键要素
|
|
288
|
+
今天是{datetime.now()}
|
|
289
|
+
用户了提交了asin 列表,文件名称为{locafile}
|
|
290
|
+
请生成亚马逊选品分析报告的标题
|
|
291
|
+
"""
|
|
292
|
+
response_title = await self.call_ai_api([{"role": "user", "content": gentitle_prompt}])
|
|
293
|
+
title = response_title["data"]
|
|
294
|
+
|
|
295
|
+
# Update mission with generated title
|
|
296
|
+
task_res = await self.update_mission(missionid, title, "无需关键词")
|
|
297
|
+
|
|
298
|
+
if task_res["code"] == 200:
|
|
299
|
+
# Get ASIN list for the mission
|
|
300
|
+
res = await self.get_asin_list(missionid)
|
|
301
|
+
|
|
302
|
+
if res["code"] == 200:
|
|
303
|
+
asinlist = res["data"]
|
|
304
|
+
asins = [item["asin"] for item in asinlist]
|
|
305
|
+
return {"missionid": missionid, "asins": asins}
|
|
306
|
+
|
|
307
|
+
# Return None if any step fails
|
|
308
|
+
return None
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
# Example implementations of the required service functions
|
|
313
|
+
async def create_asin_mission_api(self,filename: str) -> str:
|
|
314
|
+
|
|
315
|
+
response = requests.post(
|
|
316
|
+
f"{URL}/task/start_task",
|
|
317
|
+
json={
|
|
318
|
+
'name':"create_asin_mission",
|
|
319
|
+
'data': {"file_name":filename},
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
)
|
|
323
|
+
"""Mock implementation - replace with actual API call"""
|
|
324
|
+
if response.status_code == 200:
|
|
325
|
+
res=response.json()
|
|
326
|
+
return res['task_id']
|
|
327
|
+
else:
|
|
328
|
+
raise Exception('Failed to request task_status')
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
async def check_task_status(self,task_id: str) -> dict:
|
|
332
|
+
response =requests.get(f"{URL}/task/task_status/{task_id}")
|
|
333
|
+
if response.status_code == 200:
|
|
334
|
+
ret= response.json()
|
|
335
|
+
"""Mock implementation - replace with actual status check"""
|
|
336
|
+
return {
|
|
337
|
+
"status": ret["status"],
|
|
338
|
+
"result": {
|
|
339
|
+
"code": 200,
|
|
340
|
+
"missionid": ret["result"]["missionid"]
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else:
|
|
344
|
+
raise Exception('Failed to request task_status')
|
|
345
|
+
|
|
346
|
+
async def get_token(self):
|
|
347
|
+
|
|
348
|
+
response =requests.get(f"{appurl}/api/gettoken")
|
|
349
|
+
if response.status_code == 200:
|
|
350
|
+
return response.json()
|
|
351
|
+
else:
|
|
352
|
+
raise Exception('Failed to request task_status')
|
|
353
|
+
# response =requests.get(f"{URL}/system/sdklogin")
|
|
354
|
+
# if response.status_code == 200:
|
|
355
|
+
# return response.json()
|
|
356
|
+
# else:
|
|
357
|
+
# raise Exception('Failed to request task_status')
|
|
358
|
+
|
|
359
|
+
async def call_ai_api(self,messages,tools):
|
|
360
|
+
data=await self.get_token()
|
|
361
|
+
print(data)
|
|
362
|
+
response = requests.post(
|
|
363
|
+
f"{URL}/agent/fn",
|
|
364
|
+
json={"tools":tools,"messages":messages},
|
|
365
|
+
headers={'Authorization': f"Bearer {data['token']}"}
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
if response.status_code == 200:
|
|
369
|
+
return response.json()
|
|
370
|
+
else:
|
|
371
|
+
raise Exception('Failed to request task_status')
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
async def update_mission(self,missionid: str, title: str, keywords: str) :
|
|
375
|
+
data=await self.get_token()
|
|
376
|
+
print(data['token'])
|
|
377
|
+
response = requests.post(
|
|
378
|
+
f"{URL}/v1/agent/intertMissioinlist",
|
|
379
|
+
json={
|
|
380
|
+
'task_id':missionid,
|
|
381
|
+
'report_title': title,
|
|
382
|
+
'keywords': keywords,
|
|
383
|
+
'task_status':'In Progress',
|
|
384
|
+
'task_status_description':'数据采集任务开始'
|
|
385
|
+
},
|
|
386
|
+
headers={'Authorization': f"Bearer {data['token']}"}
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
print(response)
|
|
390
|
+
if response.status_code == 200:
|
|
391
|
+
return response.json()
|
|
392
|
+
else:
|
|
393
|
+
raise Exception('Failed to request task_status')
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
async def get_asin_list(self,missionid: str):
|
|
397
|
+
response = requests.post(
|
|
398
|
+
f"{URL}/conv/getid",
|
|
399
|
+
json={
|
|
400
|
+
'missionid':missionid}
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
if response.status_code == 200:
|
|
405
|
+
return response.json()
|
|
406
|
+
else:
|
|
407
|
+
raise Exception('Failed to request task_status')
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
async def getallpageData(self,missionid: str) :
|
|
414
|
+
data=await self.get_token()
|
|
415
|
+
print(data['token'])
|
|
416
|
+
response = requests.post(
|
|
417
|
+
f"{URL}/v1/agent/test/getallpageData",
|
|
418
|
+
json={
|
|
419
|
+
'missionid':missionid
|
|
420
|
+
},
|
|
421
|
+
headers={'Authorization': f"Bearer {data['token']}"}
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
print(response)
|
|
425
|
+
if response.status_code == 200:
|
|
426
|
+
return response.json()
|
|
427
|
+
else:
|
|
428
|
+
raise Exception('Failed to request task_status')
|
|
429
|
+
|
|
99
430
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# f'{self.base_url}/createEndpoints',
|
|
103
|
-
# json={
|
|
104
|
-
# "endpointpath": endpointpath,
|
|
105
|
-
# "method": "POST",
|
|
106
|
-
# "name":name
|
|
107
|
-
# },
|
|
108
|
-
# headers={'Authorization': f'Bearer {self.access_token}'}
|
|
109
|
-
# )
|
|
110
|
-
# if response.status_code == 200:
|
|
111
|
-
# return response.json()
|
|
112
|
-
# else:
|
|
113
|
-
# raise Exception('Failed to createEndpoints')
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# def createRoles(self, role_name, description):
|
|
118
|
-
# response = requests.post(
|
|
119
|
-
# f'{self.base_url}/createRoles',
|
|
120
|
-
# json={
|
|
121
|
-
# "role_name": role_name,
|
|
122
|
-
# "description":description
|
|
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 createRoles')
|
|
130
|
-
|
|
131
|
-
# def roles_endpoint(self, role_id, endpoint_id):
|
|
132
|
-
# response = requests.post(
|
|
133
|
-
# f'{self.base_url}/roles/{role_id}/endpoints',
|
|
134
|
-
# json={
|
|
135
|
-
# "endpoint_id": endpoint_id
|
|
136
|
-
# },
|
|
137
|
-
# headers={'Authorization': f'Bearer {self.access_token}'}
|
|
138
|
-
# )
|
|
139
|
-
# if response.status_code == 200:
|
|
140
|
-
# return response.json()
|
|
141
|
-
# else:
|
|
142
|
-
# raise Exception('Failed to roles_endpoint')
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# def user_roles(self, user_id, role_id):
|
|
146
|
-
# response = requests.post(
|
|
147
|
-
# f'{self.base_url}/users/{user_id}/roles',
|
|
148
|
-
# json={
|
|
149
|
-
# "role_id": role_id
|
|
150
|
-
# },
|
|
151
|
-
# headers={'Authorization': f'Bearer {self.access_token}'}
|
|
152
|
-
# )
|
|
153
|
-
# if response.status_code == 200:
|
|
154
|
-
# return response.json()
|
|
155
|
-
# else:
|
|
156
|
-
# raise Exception('Failed to user_roles')
|
|
431
|
+
|
|
432
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
oneliai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
oneliai/client.py,sha256=-sjQayxFFcRd9wueMiaVb7GCkJpSWZqNT-4KpcAyBJ0,14400
|
|
3
|
+
sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
sdk/client.py,sha256=FwUhqzY2DkRTloe_XMyaaaEzg7THaIV6OxPDliMQjq0,4267
|
|
5
|
+
oneliai-0.3.0.dist-info/METADATA,sha256=J1A-JNIohocFBTrPrJJ40W3RpvuqMwHBrfF7DnaXyq0,155
|
|
6
|
+
oneliai-0.3.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
7
|
+
oneliai-0.3.0.dist-info/top_level.txt,sha256=GqjKHlaU6NsCzFm5EOy-2oJoa3YStKZAX8qonkZqB1M,8
|
|
8
|
+
oneliai-0.3.0.dist-info/RECORD,,
|
oneliai-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
oneliai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
oneliai/client.py,sha256=-e3RToSTR2T54C06v9CG-6OH4fXZCvUg3svCbZ8tXC4,5237
|
|
3
|
-
sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
sdk/client.py,sha256=FwUhqzY2DkRTloe_XMyaaaEzg7THaIV6OxPDliMQjq0,4267
|
|
5
|
-
oneliai-0.1.0.dist-info/METADATA,sha256=iKDLgkW148wBs4EdcvJS9gCKtSZzPKBmesWZFa_v914,155
|
|
6
|
-
oneliai-0.1.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
7
|
-
oneliai-0.1.0.dist-info/top_level.txt,sha256=GqjKHlaU6NsCzFm5EOy-2oJoa3YStKZAX8qonkZqB1M,8
|
|
8
|
-
oneliai-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|