smallestai 2.2.0__py3-none-any.whl → 3.0.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 smallestai might be problematic. Click here for more details.
- smallestai/__init__.py +95 -0
- smallestai/atoms/__init__.py +182 -0
- smallestai/atoms/api/__init__.py +12 -0
- smallestai/atoms/api/agent_templates_api.py +573 -0
- smallestai/atoms/api/agents_api.py +1465 -0
- smallestai/atoms/api/calls_api.py +320 -0
- smallestai/atoms/api/campaigns_api.py +1689 -0
- smallestai/atoms/api/knowledge_base_api.py +2271 -0
- smallestai/atoms/api/logs_api.py +305 -0
- smallestai/atoms/api/organization_api.py +285 -0
- smallestai/atoms/api/user_api.py +285 -0
- smallestai/atoms/api_client.py +797 -0
- smallestai/atoms/api_response.py +21 -0
- smallestai/atoms/atoms_client.py +560 -0
- smallestai/atoms/configuration.py +582 -0
- smallestai/atoms/exceptions.py +216 -0
- smallestai/atoms/models/__init__.py +72 -0
- smallestai/atoms/models/agent_dto.py +130 -0
- smallestai/atoms/models/agent_dto_language.py +91 -0
- smallestai/atoms/models/agent_dto_synthesizer.py +99 -0
- smallestai/atoms/models/agent_dto_synthesizer_voice_config.py +111 -0
- smallestai/atoms/models/api_response.py +89 -0
- smallestai/atoms/models/bad_request_error_response.py +89 -0
- smallestai/atoms/models/create_agent_from_template200_response.py +89 -0
- smallestai/atoms/models/create_agent_from_template_request.py +91 -0
- smallestai/atoms/models/create_agent_request.py +113 -0
- smallestai/atoms/models/create_agent_request_language.py +124 -0
- smallestai/atoms/models/create_agent_request_language_synthesizer.py +110 -0
- smallestai/atoms/models/create_agent_request_language_synthesizer_voice_config.py +137 -0
- smallestai/atoms/models/create_campaign200_response.py +93 -0
- smallestai/atoms/models/create_campaign200_response_data.py +106 -0
- smallestai/atoms/models/create_campaign200_response_inner.py +106 -0
- smallestai/atoms/models/create_campaign201_response.py +93 -0
- smallestai/atoms/models/create_campaign201_response_data.py +104 -0
- smallestai/atoms/models/create_campaign_request.py +93 -0
- smallestai/atoms/models/create_knowledge_base201_response.py +89 -0
- smallestai/atoms/models/create_knowledge_base_request.py +89 -0
- smallestai/atoms/models/delete_agent200_response.py +87 -0
- smallestai/atoms/models/get_agent_by_id200_response.py +93 -0
- smallestai/atoms/models/get_agent_templates200_response.py +97 -0
- smallestai/atoms/models/get_agent_templates200_response_data_inner.py +97 -0
- smallestai/atoms/models/get_agents200_response.py +93 -0
- smallestai/atoms/models/get_agents200_response_data.py +101 -0
- smallestai/atoms/models/get_campaign_by_id200_response.py +93 -0
- smallestai/atoms/models/get_campaign_by_id200_response_data.py +114 -0
- smallestai/atoms/models/get_campaigns200_response.py +97 -0
- smallestai/atoms/models/get_campaigns200_response_data_inner.py +118 -0
- smallestai/atoms/models/get_campaigns200_response_data_inner_agent.py +89 -0
- smallestai/atoms/models/get_campaigns200_response_data_inner_audience.py +89 -0
- smallestai/atoms/models/get_campaigns_request.py +89 -0
- smallestai/atoms/models/get_conversation200_response.py +93 -0
- smallestai/atoms/models/get_conversation200_response_data.py +125 -0
- smallestai/atoms/models/get_conversation_logs200_response.py +93 -0
- smallestai/atoms/models/get_conversation_logs200_response_data.py +125 -0
- smallestai/atoms/models/get_current_user200_response.py +93 -0
- smallestai/atoms/models/get_current_user200_response_data.py +99 -0
- smallestai/atoms/models/get_knowledge_base_by_id200_response.py +93 -0
- smallestai/atoms/models/get_knowledge_base_items200_response.py +97 -0
- smallestai/atoms/models/get_knowledge_bases200_response.py +97 -0
- smallestai/atoms/models/get_organization200_response.py +93 -0
- smallestai/atoms/models/get_organization200_response_data.py +105 -0
- smallestai/atoms/models/get_organization200_response_data_members_inner.py +89 -0
- smallestai/atoms/models/get_organization200_response_data_subscription.py +87 -0
- smallestai/atoms/models/internal_server_error_response.py +89 -0
- smallestai/atoms/models/knowledge_base_dto.py +93 -0
- smallestai/atoms/models/knowledge_base_item_dto.py +124 -0
- smallestai/atoms/models/start_outbound_call200_response.py +93 -0
- smallestai/atoms/models/start_outbound_call200_response_data.py +87 -0
- smallestai/atoms/models/start_outbound_call_request.py +89 -0
- smallestai/atoms/models/unauthorized_error_reponse.py +89 -0
- smallestai/atoms/models/update_agent200_response.py +89 -0
- smallestai/atoms/models/update_agent_request.py +119 -0
- smallestai/atoms/models/update_agent_request_language.py +99 -0
- smallestai/atoms/models/update_agent_request_synthesizer.py +110 -0
- smallestai/atoms/models/update_agent_request_synthesizer_voice_config.py +137 -0
- smallestai/atoms/models/update_agent_request_synthesizer_voice_config_one_of.py +111 -0
- smallestai/atoms/models/update_agent_request_synthesizer_voice_config_one_of1.py +99 -0
- smallestai/atoms/models/upload_text_to_knowledge_base_request.py +89 -0
- smallestai/atoms/py.typed +0 -0
- smallestai/atoms/rest.py +258 -0
- smallestai/waves/__init__.py +5 -0
- smallest/async_tts.py → smallestai/waves/async_waves_client.py +3 -3
- {smallest → smallestai/waves}/stream_tts.py +6 -6
- {smallest → smallestai/waves}/utils.py +2 -2
- smallest/tts.py → smallestai/waves/waves_client.py +3 -3
- {smallestai-2.2.0.dist-info → smallestai-3.0.0.dist-info}/METADATA +194 -42
- smallestai-3.0.0.dist-info/RECORD +92 -0
- {smallestai-2.2.0.dist-info → smallestai-3.0.0.dist-info}/WHEEL +1 -1
- smallestai-3.0.0.dist-info/top_level.txt +1 -0
- smallest/__init__.py +0 -5
- smallestai-2.2.0.dist-info/RECORD +0 -12
- smallestai-2.2.0.dist-info/top_level.txt +0 -1
- {smallest → smallestai/waves}/exceptions.py +0 -0
- {smallest → smallestai/waves}/models.py +0 -0
- {smallestai-2.2.0.dist-info → smallestai-3.0.0.dist-info/licenses}/LICENSE +0 -0
smallestai/atoms/rest.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Agent Management API
|
|
5
|
+
|
|
6
|
+
API for managing agents, their templates, and call logs
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import io
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
import ssl
|
|
19
|
+
|
|
20
|
+
import urllib3
|
|
21
|
+
|
|
22
|
+
from smallestai.atoms.exceptions import ApiException, ApiValueError
|
|
23
|
+
|
|
24
|
+
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
|
25
|
+
RESTResponseType = urllib3.HTTPResponse
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_socks_proxy_url(url):
|
|
29
|
+
if url is None:
|
|
30
|
+
return False
|
|
31
|
+
split_section = url.split("://")
|
|
32
|
+
if len(split_section) < 2:
|
|
33
|
+
return False
|
|
34
|
+
else:
|
|
35
|
+
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class RESTResponse(io.IOBase):
|
|
39
|
+
|
|
40
|
+
def __init__(self, resp) -> None:
|
|
41
|
+
self.response = resp
|
|
42
|
+
self.status = resp.status
|
|
43
|
+
self.reason = resp.reason
|
|
44
|
+
self.data = None
|
|
45
|
+
|
|
46
|
+
def read(self):
|
|
47
|
+
if self.data is None:
|
|
48
|
+
self.data = self.response.data
|
|
49
|
+
return self.data
|
|
50
|
+
|
|
51
|
+
def getheaders(self):
|
|
52
|
+
"""Returns a dictionary of the response headers."""
|
|
53
|
+
return self.response.headers
|
|
54
|
+
|
|
55
|
+
def getheader(self, name, default=None):
|
|
56
|
+
"""Returns a given response header."""
|
|
57
|
+
return self.response.headers.get(name, default)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class RESTClientObject:
|
|
61
|
+
|
|
62
|
+
def __init__(self, configuration) -> None:
|
|
63
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
64
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
65
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
66
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
67
|
+
|
|
68
|
+
# cert_reqs
|
|
69
|
+
if configuration.verify_ssl:
|
|
70
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
71
|
+
else:
|
|
72
|
+
cert_reqs = ssl.CERT_NONE
|
|
73
|
+
|
|
74
|
+
pool_args = {
|
|
75
|
+
"cert_reqs": cert_reqs,
|
|
76
|
+
"ca_certs": configuration.ssl_ca_cert,
|
|
77
|
+
"cert_file": configuration.cert_file,
|
|
78
|
+
"key_file": configuration.key_file,
|
|
79
|
+
"ca_cert_data": configuration.ca_cert_data,
|
|
80
|
+
}
|
|
81
|
+
if configuration.assert_hostname is not None:
|
|
82
|
+
pool_args['assert_hostname'] = (
|
|
83
|
+
configuration.assert_hostname
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if configuration.retries is not None:
|
|
87
|
+
pool_args['retries'] = configuration.retries
|
|
88
|
+
|
|
89
|
+
if configuration.tls_server_name:
|
|
90
|
+
pool_args['server_hostname'] = configuration.tls_server_name
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if configuration.socket_options is not None:
|
|
94
|
+
pool_args['socket_options'] = configuration.socket_options
|
|
95
|
+
|
|
96
|
+
if configuration.connection_pool_maxsize is not None:
|
|
97
|
+
pool_args['maxsize'] = configuration.connection_pool_maxsize
|
|
98
|
+
|
|
99
|
+
# https pool manager
|
|
100
|
+
self.pool_manager: urllib3.PoolManager
|
|
101
|
+
|
|
102
|
+
if configuration.proxy:
|
|
103
|
+
if is_socks_proxy_url(configuration.proxy):
|
|
104
|
+
from urllib3.contrib.socks import SOCKSProxyManager
|
|
105
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
106
|
+
pool_args["headers"] = configuration.proxy_headers
|
|
107
|
+
self.pool_manager = SOCKSProxyManager(**pool_args)
|
|
108
|
+
else:
|
|
109
|
+
pool_args["proxy_url"] = configuration.proxy
|
|
110
|
+
pool_args["proxy_headers"] = configuration.proxy_headers
|
|
111
|
+
self.pool_manager = urllib3.ProxyManager(**pool_args)
|
|
112
|
+
else:
|
|
113
|
+
self.pool_manager = urllib3.PoolManager(**pool_args)
|
|
114
|
+
|
|
115
|
+
def request(
|
|
116
|
+
self,
|
|
117
|
+
method,
|
|
118
|
+
url,
|
|
119
|
+
headers=None,
|
|
120
|
+
body=None,
|
|
121
|
+
post_params=None,
|
|
122
|
+
_request_timeout=None
|
|
123
|
+
):
|
|
124
|
+
"""Perform requests.
|
|
125
|
+
|
|
126
|
+
:param method: http request method
|
|
127
|
+
:param url: http request url
|
|
128
|
+
:param headers: http request headers
|
|
129
|
+
:param body: request json body, for `application/json`
|
|
130
|
+
:param post_params: request post parameters,
|
|
131
|
+
`application/x-www-form-urlencoded`
|
|
132
|
+
and `multipart/form-data`
|
|
133
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
134
|
+
number provided, it will be total request
|
|
135
|
+
timeout. It can also be a pair (tuple) of
|
|
136
|
+
(connection, read) timeouts.
|
|
137
|
+
"""
|
|
138
|
+
method = method.upper()
|
|
139
|
+
assert method in [
|
|
140
|
+
'GET',
|
|
141
|
+
'HEAD',
|
|
142
|
+
'DELETE',
|
|
143
|
+
'POST',
|
|
144
|
+
'PUT',
|
|
145
|
+
'PATCH',
|
|
146
|
+
'OPTIONS'
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
if post_params and body:
|
|
150
|
+
raise ApiValueError(
|
|
151
|
+
"body parameter cannot be used with post_params parameter."
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
post_params = post_params or {}
|
|
155
|
+
headers = headers or {}
|
|
156
|
+
|
|
157
|
+
timeout = None
|
|
158
|
+
if _request_timeout:
|
|
159
|
+
if isinstance(_request_timeout, (int, float)):
|
|
160
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
161
|
+
elif (
|
|
162
|
+
isinstance(_request_timeout, tuple)
|
|
163
|
+
and len(_request_timeout) == 2
|
|
164
|
+
):
|
|
165
|
+
timeout = urllib3.Timeout(
|
|
166
|
+
connect=_request_timeout[0],
|
|
167
|
+
read=_request_timeout[1]
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
try:
|
|
171
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
172
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
|
173
|
+
|
|
174
|
+
# no content type provided or payload is json
|
|
175
|
+
content_type = headers.get('Content-Type')
|
|
176
|
+
if (
|
|
177
|
+
not content_type
|
|
178
|
+
or re.search('json', content_type, re.IGNORECASE)
|
|
179
|
+
):
|
|
180
|
+
request_body = None
|
|
181
|
+
if body is not None:
|
|
182
|
+
request_body = json.dumps(body)
|
|
183
|
+
r = self.pool_manager.request(
|
|
184
|
+
method,
|
|
185
|
+
url,
|
|
186
|
+
body=request_body,
|
|
187
|
+
timeout=timeout,
|
|
188
|
+
headers=headers,
|
|
189
|
+
preload_content=False
|
|
190
|
+
)
|
|
191
|
+
elif content_type == 'application/x-www-form-urlencoded':
|
|
192
|
+
r = self.pool_manager.request(
|
|
193
|
+
method,
|
|
194
|
+
url,
|
|
195
|
+
fields=post_params,
|
|
196
|
+
encode_multipart=False,
|
|
197
|
+
timeout=timeout,
|
|
198
|
+
headers=headers,
|
|
199
|
+
preload_content=False
|
|
200
|
+
)
|
|
201
|
+
elif content_type == 'multipart/form-data':
|
|
202
|
+
# must del headers['Content-Type'], or the correct
|
|
203
|
+
# Content-Type which generated by urllib3 will be
|
|
204
|
+
# overwritten.
|
|
205
|
+
del headers['Content-Type']
|
|
206
|
+
# Ensures that dict objects are serialized
|
|
207
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
|
|
208
|
+
r = self.pool_manager.request(
|
|
209
|
+
method,
|
|
210
|
+
url,
|
|
211
|
+
fields=post_params,
|
|
212
|
+
encode_multipart=True,
|
|
213
|
+
timeout=timeout,
|
|
214
|
+
headers=headers,
|
|
215
|
+
preload_content=False
|
|
216
|
+
)
|
|
217
|
+
# Pass a `string` parameter directly in the body to support
|
|
218
|
+
# other content types than JSON when `body` argument is
|
|
219
|
+
# provided in serialized form.
|
|
220
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
221
|
+
r = self.pool_manager.request(
|
|
222
|
+
method,
|
|
223
|
+
url,
|
|
224
|
+
body=body,
|
|
225
|
+
timeout=timeout,
|
|
226
|
+
headers=headers,
|
|
227
|
+
preload_content=False
|
|
228
|
+
)
|
|
229
|
+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
|
230
|
+
request_body = "true" if body else "false"
|
|
231
|
+
r = self.pool_manager.request(
|
|
232
|
+
method,
|
|
233
|
+
url,
|
|
234
|
+
body=request_body,
|
|
235
|
+
preload_content=False,
|
|
236
|
+
timeout=timeout,
|
|
237
|
+
headers=headers)
|
|
238
|
+
else:
|
|
239
|
+
# Cannot generate the request from given parameters
|
|
240
|
+
msg = """Cannot prepare a request message for provided
|
|
241
|
+
arguments. Please check that your arguments match
|
|
242
|
+
declared content type."""
|
|
243
|
+
raise ApiException(status=0, reason=msg)
|
|
244
|
+
# For `GET`, `HEAD`
|
|
245
|
+
else:
|
|
246
|
+
r = self.pool_manager.request(
|
|
247
|
+
method,
|
|
248
|
+
url,
|
|
249
|
+
fields={},
|
|
250
|
+
timeout=timeout,
|
|
251
|
+
headers=headers,
|
|
252
|
+
preload_content=False
|
|
253
|
+
)
|
|
254
|
+
except urllib3.exceptions.SSLError as e:
|
|
255
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
256
|
+
raise ApiException(status=0, reason=msg)
|
|
257
|
+
|
|
258
|
+
return RESTResponse(r)
|
|
@@ -6,12 +6,12 @@ import aiofiles
|
|
|
6
6
|
import requests
|
|
7
7
|
from typing import Optional, Union, List, AsyncIterator
|
|
8
8
|
|
|
9
|
-
from
|
|
10
|
-
from
|
|
9
|
+
from smallestai.waves.exceptions import TTSError, APIError
|
|
10
|
+
from smallestai.waves.utils import (TTSOptions, validate_input, preprocess_text, add_wav_header, chunk_text,
|
|
11
11
|
get_smallest_languages, get_smallest_models, ALLOWED_AUDIO_EXTENSIONS, API_BASE_URL)
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class
|
|
14
|
+
class AsyncWavesClient:
|
|
15
15
|
def __init__(
|
|
16
16
|
self,
|
|
17
17
|
api_key: str = None,
|
|
@@ -4,15 +4,15 @@ from threading import Thread
|
|
|
4
4
|
from queue import Queue, Empty
|
|
5
5
|
from typing import AsyncGenerator, Optional, Union, List, Dict, Any
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
7
|
+
from smallestai.waves.waves_client import WavesClient
|
|
8
|
+
from smallestai.waves.exceptions import APIError
|
|
9
|
+
from smallestai.waves.async_waves_client import AsyncWavesClient
|
|
10
|
+
from smallestai.waves.utils import SENTENCE_END_REGEX
|
|
11
11
|
|
|
12
12
|
class TextToAudioStream:
|
|
13
13
|
def __init__(
|
|
14
14
|
self,
|
|
15
|
-
tts_instance: Union[
|
|
15
|
+
tts_instance: Union[WavesClient, AsyncWavesClient],
|
|
16
16
|
queue_timeout: Optional[float] = 5.0,
|
|
17
17
|
max_retries: Optional[int] = 3,
|
|
18
18
|
verbose: bool = False
|
|
@@ -182,7 +182,7 @@ class TextToAudioStream:
|
|
|
182
182
|
try:
|
|
183
183
|
sentence = self.queue.get_nowait()
|
|
184
184
|
|
|
185
|
-
if isinstance(self.tts_instance,
|
|
185
|
+
if isinstance(self.tts_instance, AsyncWavesClient):
|
|
186
186
|
audio_content = await self._synthesize_async(sentence)
|
|
187
187
|
else:
|
|
188
188
|
loop = asyncio.get_running_loop()
|
|
@@ -5,8 +5,8 @@ from typing import Optional
|
|
|
5
5
|
from pydub import AudioSegment
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
|
|
8
|
-
from
|
|
9
|
-
from
|
|
8
|
+
from smallestai.waves.exceptions import ValidationError
|
|
9
|
+
from smallestai.waves.models import TTSModels, TTSLanguages
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
API_BASE_URL = "https://waves-api.smallest.ai/api/v1"
|
|
@@ -5,11 +5,11 @@ import copy
|
|
|
5
5
|
import requests
|
|
6
6
|
from typing import Optional, Union, List, Iterator
|
|
7
7
|
|
|
8
|
-
from
|
|
9
|
-
from
|
|
8
|
+
from smallestai.waves.exceptions import TTSError, APIError
|
|
9
|
+
from smallestai.waves.utils import (TTSOptions, validate_input, preprocess_text, add_wav_header, chunk_text,
|
|
10
10
|
get_smallest_languages, get_smallest_models, ALLOWED_AUDIO_EXTENSIONS, API_BASE_URL)
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class WavesClient:
|
|
13
13
|
def __init__(
|
|
14
14
|
self,
|
|
15
15
|
api_key: str = None,
|