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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oneliai
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: SDK for ONELI.AI Customer API
5
5
  Author: oneli.ai
6
6
  Requires-Python: >=3.6
@@ -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,asins,missionid=""):
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
- logging.info(task_id)
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'{self.base_url}/conv/analysis/getid',
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 suggestion')
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
- return response.json()
169
+
170
+ result=response.json()
171
+
172
+ return result['data']['task_id']
162
173
  else:
163
- raise Exception('Failed to start suggestion')
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
- response =requests.get(f"{URL}/task/task_status/{taskId}")
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
- response = await self.get_task_status(task_id)
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
- 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')
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oneliai
3
- Version: 0.3.0
3
+ Version: 0.5.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.3.0",
22
+ version="0.5.0",
23
23
  author="oneli.ai",
24
24
  description='SDK for ONELI.AI Customer API',
25
25
  # long_description=open("README.md").read(),
File without changes
File without changes