oneliai 0.1.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/__init__.py ADDED
File without changes
oneliai/client.py ADDED
@@ -0,0 +1,156 @@
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, template_id, variables):
27
+ response = requests.post(
28
+ f'{self.base_url}/dynamic-response',
29
+ json={
30
+ 'template_id': template_id,
31
+ 'variables': variables
32
+ },
33
+ headers={'Authorization': f'Bearer {self.access_token}'}
34
+ )
35
+ if response.status_code == 200:
36
+ return response.json().get('response')
37
+ else:
38
+ return response.json()
39
+ # raise Exception('Failed to generate response')
40
+
41
+ def query_data(self, arg, template_id):
42
+ response = requests.post(
43
+ f'{self.base_url}/query-data',
44
+ json={
45
+ 'arg': arg,
46
+ 'template_id': template_id
47
+ },
48
+ headers={'Authorization': f'Bearer {self.access_token}'}
49
+ )
50
+ if response.status_code == 200:
51
+ return response.json()
52
+ else:
53
+ res=response.json()
54
+ raise Exception(res['error'])
55
+
56
+
57
+ def query_intention(self, question):
58
+ response = requests.post(
59
+ f'{self.base_url}/query-intention',
60
+ json={
61
+ 'question': question
62
+
63
+ },
64
+ headers={'Authorization': f'Bearer {self.access_token}'}
65
+ )
66
+ if response.status_code == 200:
67
+ return response.json()
68
+ else:
69
+ raise Exception('Failed to start intention query')
70
+
71
+ def voc(self,productname,text):
72
+ response = requests.post(
73
+ f'{self.base_url}/voc',
74
+ json={
75
+ 'productname': productname,
76
+ 'text':text
77
+ },
78
+ headers={'Authorization': f'Bearer {self.access_token}'}
79
+ )
80
+ if response.status_code == 200:
81
+ return response.json()
82
+ else:
83
+ raise Exception('Failed to start voc ')
84
+
85
+
86
+ def spec(self,asin):
87
+ response = requests.post(
88
+ f'{self.base_url}/spec',
89
+ json={
90
+ 'asin': asin
91
+
92
+ },
93
+ headers={'Authorization': f'Bearer {self.access_token}'}
94
+ )
95
+ if response.status_code == 200:
96
+ return response.json()
97
+ else:
98
+ raise Exception('Failed to start voc ')
99
+
100
+ # def registEndpoint(self, name,endpointpath):
101
+ # response = requests.post(
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')
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.1
2
+ Name: oneliai
3
+ Version: 0.1.0
4
+ Summary: SDK for ONELI.AI Customer API
5
+ Author: oneli.ai
6
+ Requires-Python: >=3.6
7
+ Requires-Dist: requests
8
+
@@ -0,0 +1,8 @@
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,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.37.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ oneliai
sdk/__init__.py ADDED
File without changes
sdk/client.py ADDED
@@ -0,0 +1,127 @@
1
+ import requests
2
+
3
+ # URL="https://apis.oneli.chat"
4
+ URL="http://localhost:8085"
5
+ class AICustomerClient:
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, template_id, variables):
27
+ response = requests.post(
28
+ f'{self.base_url}/dynamic-response',
29
+ json={
30
+ 'template_id': template_id,
31
+ 'variables': variables
32
+ },
33
+ headers={'Authorization': f'Bearer {self.access_token}'}
34
+ )
35
+ if response.status_code == 200:
36
+ return response.json().get('response')
37
+ else:
38
+ return response.json()
39
+ # raise Exception('Failed to generate response')
40
+
41
+ def query_data(self, arg, template_id):
42
+ response = requests.post(
43
+ f'{self.base_url}/query-data',
44
+ json={
45
+ 'arg': arg,
46
+ 'template_id': template_id
47
+ },
48
+ headers={'Authorization': f'Bearer {self.access_token}'}
49
+ )
50
+ if response.status_code == 200:
51
+ return response.json()
52
+ else:
53
+ res=response.json()
54
+ raise Exception(res['error'])
55
+
56
+
57
+ def query_intention(self, question):
58
+ response = requests.post(
59
+ f'{self.base_url}/query-intention',
60
+ json={
61
+ 'question': question
62
+
63
+ },
64
+ headers={'Authorization': f'Bearer {self.access_token}'}
65
+ )
66
+ if response.status_code == 200:
67
+ return response.json()
68
+ else:
69
+ raise Exception('Failed to start intention query')
70
+
71
+ def registEndpoint(self, name,endpointpath):
72
+ response = requests.post(
73
+ f'{self.base_url}/createEndpoints',
74
+ json={
75
+ "endpointpath": endpointpath,
76
+ "method": "POST",
77
+ "name":name
78
+ },
79
+ headers={'Authorization': f'Bearer {self.access_token}'}
80
+ )
81
+ if response.status_code == 200:
82
+ return response.json()
83
+ else:
84
+ raise Exception('Failed to createEndpoints')
85
+
86
+
87
+
88
+ def createRoles(self, role_name, description):
89
+ response = requests.post(
90
+ f'{self.base_url}/createRoles',
91
+ json={
92
+ "role_name": role_name,
93
+ "description":description
94
+ },
95
+ headers={'Authorization': f'Bearer {self.access_token}'}
96
+ )
97
+ if response.status_code == 200:
98
+ return response.json()
99
+ else:
100
+ raise Exception('Failed to createRoles')
101
+
102
+ def roles_endpoint(self, role_id, endpoint_id):
103
+ response = requests.post(
104
+ f'{self.base_url}/roles/{role_id}/endpoints',
105
+ json={
106
+ "endpoint_id": endpoint_id
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 roles_endpoint')
114
+
115
+
116
+ def user_roles(self, user_id, role_id):
117
+ response = requests.post(
118
+ f'{self.base_url}/users/{user_id}/roles',
119
+ json={
120
+ "role_id": role_id
121
+ },
122
+ headers={'Authorization': f'Bearer {self.access_token}'}
123
+ )
124
+ if response.status_code == 200:
125
+ return response.json()
126
+ else:
127
+ raise Exception('Failed to user_roles')