oneliai 0.2.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.

@@ -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,452 @@
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"
9
+
10
+ appurl="http://localhost:3000"
11
+ class AIClient:
12
+ def __init__(self, client_id, client_secret, base_url=f'{URL}/v1/strategy'):
13
+ self.client_id = client_id
14
+ self.client_secret = client_secret
15
+ self.base_url = base_url
16
+ self.access_token = self._get_access_token()
17
+
18
+ def _get_access_token(self):
19
+ response = requests.post(
20
+ f'{self.base_url}/auth/token',
21
+ json={
22
+ 'client_id': self.client_id,
23
+ 'client_secret': self.client_secret,
24
+ 'grant_type': 'client_credentials'
25
+ }
26
+ )
27
+ if response.status_code == 200:
28
+ return response.json().get('access_token')
29
+ else:
30
+ raise Exception('Failed to get access token')
31
+
32
+ def generate_response(self, question,template_id, variables):
33
+ response = requests.post(
34
+ f'{self.base_url}/dynamic-response',
35
+ json={
36
+ 'question':question,
37
+ 'template_id': template_id,
38
+ 'variables': variables
39
+ },
40
+ headers={'Authorization': f'Bearer {self.access_token}'}
41
+ )
42
+ if response.status_code == 200:
43
+ return response.json().get('response')
44
+ else:
45
+ return response.json()
46
+ # raise Exception('Failed to generate response')
47
+
48
+ def query_data(self, arg, template_id):
49
+ response = requests.post(
50
+ f'{self.base_url}/query-data',
51
+ json={
52
+ 'arg': arg,
53
+ 'template_id': template_id
54
+ },
55
+ headers={'Authorization': f'Bearer {self.access_token}'}
56
+ )
57
+ if response.status_code == 200:
58
+ return response.json()
59
+ else:
60
+ res=response.json()
61
+ raise Exception(res['error'])
62
+
63
+
64
+ def query_intention(self, question):
65
+ response = requests.post(
66
+ f'{self.base_url}/query-intention',
67
+ json={
68
+ 'question': question
69
+
70
+ },
71
+ headers={'Authorization': f'Bearer {self.access_token}'}
72
+ )
73
+ if response.status_code == 200:
74
+ return response.json()
75
+ else:
76
+
77
+ raise Exception('Failed to start intention query')
78
+
79
+ def voc(self,productname,text):
80
+ response = requests.post(
81
+ f'{self.base_url}/voc',
82
+ json={
83
+ 'productname': productname,
84
+ 'text':text
85
+ },
86
+ headers={'Authorization': f'Bearer {self.access_token}'}
87
+ )
88
+ if response.status_code == 200:
89
+ return response.json()
90
+ else:
91
+ raise Exception('Failed to start voc ')
92
+
93
+
94
+ def spec(self,asin):
95
+ response = requests.post(
96
+ f'{self.base_url}/spec',
97
+ json={
98
+ 'asin': asin
99
+
100
+ },
101
+ headers={'Authorization': f'Bearer {self.access_token}'}
102
+ )
103
+ if response.status_code == 200:
104
+ return response.json()
105
+ else:
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,missionid="",asins=[]):
125
+ if not missionid: # Check if missionid is empty
126
+ missionid = str(uuid.uuid4()) # Generate a random UUID
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')
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
+
177
+
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')
349
+
350
+
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')
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
@@ -5,4 +5,6 @@ oneliai.egg-info/PKG-INFO
5
5
  oneliai.egg-info/SOURCES.txt
6
6
  oneliai.egg-info/dependency_links.txt
7
7
  oneliai.egg-info/requires.txt
8
- oneliai.egg-info/top_level.txt
8
+ oneliai.egg-info/top_level.txt
9
+ sdk/__init__.py
10
+ sdk/client.py
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')
@@ -19,7 +19,7 @@ from setuptools import setup, find_packages
19
19
 
20
20
  setup(
21
21
  name='oneliai',
22
- version="0.2.0",
22
+ version="0.4.0",
23
23
  author="oneli.ai",
24
24
  description='SDK for ONELI.AI Customer API',
25
25
  # long_description=open("README.md").read(),
@@ -1,159 +0,0 @@
1
- import requests
2
-
3
- URL="https://apis.oneli.chat"
4
- # URL="http://localhost:8085"
5
- class AIClient:
6
- def __init__(self, client_id, client_secret, base_url=f'{URL}/v1/strategy'):
7
- self.client_id = client_id
8
- self.client_secret = client_secret
9
- self.base_url = base_url
10
- self.access_token = self._get_access_token()
11
-
12
- def _get_access_token(self):
13
- response = requests.post(
14
- f'{self.base_url}/auth/token',
15
- json={
16
- 'client_id': self.client_id,
17
- 'client_secret': self.client_secret,
18
- 'grant_type': 'client_credentials'
19
- }
20
- )
21
- if response.status_code == 200:
22
- return response.json().get('access_token')
23
- else:
24
- raise Exception('Failed to get access token')
25
-
26
- def generate_response(self, question,template_id, variables):
27
- response = requests.post(
28
- f'{self.base_url}/dynamic-response',
29
- json={
30
- 'question':question,
31
- 'template_id': template_id,
32
- 'variables': variables
33
- },
34
- headers={'Authorization': f'Bearer {self.access_token}'}
35
- )
36
- if response.status_code == 200:
37
- return response.json().get('response')
38
- else:
39
- return response.json()
40
- # raise Exception('Failed to generate response')
41
-
42
- def query_data(self, arg, template_id):
43
- response = requests.post(
44
- f'{self.base_url}/query-data',
45
- json={
46
- 'arg': arg,
47
- 'template_id': template_id
48
- },
49
- headers={'Authorization': f'Bearer {self.access_token}'}
50
- )
51
- if response.status_code == 200:
52
- return response.json()
53
- else:
54
- res=response.json()
55
- raise Exception(res['error'])
56
-
57
-
58
- def query_intention(self, question):
59
- response = requests.post(
60
- f'{self.base_url}/query-intention',
61
- json={
62
- 'question': question
63
-
64
- },
65
- headers={'Authorization': f'Bearer {self.access_token}'}
66
- )
67
- if response.status_code == 200:
68
- return response.json()
69
- else:
70
-
71
- raise Exception('Failed to start intention query')
72
-
73
- def voc(self,productname,text):
74
- response = requests.post(
75
- f'{self.base_url}/voc',
76
- json={
77
- 'productname': productname,
78
- 'text':text
79
- },
80
- headers={'Authorization': f'Bearer {self.access_token}'}
81
- )
82
- if response.status_code == 200:
83
- return response.json()
84
- else:
85
- raise Exception('Failed to start voc ')
86
-
87
-
88
- def spec(self,asin):
89
- response = requests.post(
90
- f'{self.base_url}/spec',
91
- json={
92
- 'asin': asin
93
-
94
- },
95
- headers={'Authorization': f'Bearer {self.access_token}'}
96
- )
97
- if response.status_code == 200:
98
- return response.json()
99
- else:
100
- res=response.json()
101
- raise Exception(f'Failed to start voc,reason:{res["error"]}')
102
-
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')
117
-
118
-
119
-
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')
146
-
147
-
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
- # )
156
- # if response.status_code == 200:
157
- # return response.json()
158
- # else:
159
- # raise Exception('Failed to user_roles')
File without changes
File without changes