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