maitai-python 1.1.0b2__tar.gz → 1.1.1__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.
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/PKG-INFO +1 -1
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_config.py +14 -2
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_inference.py +7 -2
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_maitai.py +63 -37
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_maitai_async.py +62 -36
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/version.py +1 -1
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/chat/__init__.py +1 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/README.md +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_azure.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_context.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_evaluator.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_types.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/_utils.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/setup.cfg +0 -0
- {maitai_python-1.1.0b2 → maitai_python-1.1.1}/setup.py +0 -0
|
@@ -2,6 +2,8 @@ import os
|
|
|
2
2
|
from typing import List
|
|
3
3
|
|
|
4
4
|
import requests
|
|
5
|
+
from requests.adapters import HTTPAdapter
|
|
6
|
+
from urllib3 import Retry
|
|
5
7
|
|
|
6
8
|
from maitai._config_listener_thread import ConfigListenerThread
|
|
7
9
|
from maitai._utils import __version__ as version
|
|
@@ -16,6 +18,16 @@ class Config:
|
|
|
16
18
|
maitai_ws = os.environ.get("MAITAI_WS", 'wss://09hidyy627.execute-api.us-west-2.amazonaws.com/production')
|
|
17
19
|
|
|
18
20
|
def __init__(self):
|
|
21
|
+
retry_strategy = Retry(
|
|
22
|
+
total=3,
|
|
23
|
+
backoff_factor=1
|
|
24
|
+
)
|
|
25
|
+
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
26
|
+
|
|
27
|
+
self._session = requests.Session()
|
|
28
|
+
self._session.mount("http://", adapter)
|
|
29
|
+
self._session.mount("https://", adapter)
|
|
30
|
+
|
|
19
31
|
self._api_key = None
|
|
20
32
|
self._applications: dict[str, Application] = {}
|
|
21
33
|
self._company_id = None
|
|
@@ -69,7 +81,7 @@ class Config:
|
|
|
69
81
|
'x-client-version': version,
|
|
70
82
|
}
|
|
71
83
|
|
|
72
|
-
response =
|
|
84
|
+
response = self._session.get(url, headers=headers, timeout=15)
|
|
73
85
|
if response.status_code != 200:
|
|
74
86
|
print(f"Failed to initialize API client. Status code: {response.status_code}. Error: {response.text}")
|
|
75
87
|
return
|
|
@@ -85,7 +97,7 @@ class Config:
|
|
|
85
97
|
'x-client-version': version,
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
response =
|
|
100
|
+
response = self._session.get(url, headers=headers, timeout=15)
|
|
89
101
|
if response.status_code != 200:
|
|
90
102
|
print(f"Failed to initialize API client. Status code: {response.status_code}. Error: {response.text}")
|
|
91
103
|
return
|
|
@@ -18,6 +18,11 @@ class InferenceException(Exception):
|
|
|
18
18
|
super().__init__(msg)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
class MaitaiConnectionError(ConnectionError):
|
|
22
|
+
def __init__(self, msg: str):
|
|
23
|
+
super().__init__(msg)
|
|
24
|
+
|
|
25
|
+
|
|
21
26
|
class InferenceWarning(Warning):
|
|
22
27
|
def __init__(self, *args, **kwargs):
|
|
23
28
|
pass
|
|
@@ -70,7 +75,7 @@ class Inference(MaitaiClient):
|
|
|
70
75
|
}
|
|
71
76
|
response = requests.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE), stream=True)
|
|
72
77
|
if response.status_code != 200:
|
|
73
|
-
raise
|
|
78
|
+
raise MaitaiConnectionError(f"Failed to send inference request. Status code: {response.status_code}. Error: {response.text}")
|
|
74
79
|
try:
|
|
75
80
|
for line in response.iter_lines():
|
|
76
81
|
if line:
|
|
@@ -95,7 +100,7 @@ class Inference(MaitaiClient):
|
|
|
95
100
|
async with session.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE)) as response:
|
|
96
101
|
if response.status != 200:
|
|
97
102
|
error_text = await response.text()
|
|
98
|
-
exception =
|
|
103
|
+
exception = MaitaiConnectionError(f"Failed to send inference request. Status code: {response.status}. Error: {error_text}")
|
|
99
104
|
if chunk_queue:
|
|
100
105
|
chunk_queue.put(exception)
|
|
101
106
|
if async_chunk_queue:
|
|
@@ -12,7 +12,7 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
12
12
|
import maitai
|
|
13
13
|
from maitai._config import config
|
|
14
14
|
from maitai._evaluator import Evaluator
|
|
15
|
-
from maitai._inference import InferenceException, InferenceWarning
|
|
15
|
+
from maitai._inference import InferenceException, InferenceWarning, MaitaiConnectionError
|
|
16
16
|
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query, ToolFunction
|
|
17
17
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
18
18
|
from maitai.tools import Tools
|
|
@@ -59,9 +59,9 @@ class Maitai:
|
|
|
59
59
|
config.auth_keys.groq_api_key.key_value = groq_api_key
|
|
60
60
|
if anthropic_api_key:
|
|
61
61
|
config.auth_keys.anthropic_api_key.key_value = anthropic_api_key
|
|
62
|
-
self.
|
|
62
|
+
self._client = None
|
|
63
63
|
if api_key or openai_api_key or os.environ.get("OPENAI_API_KEY"):
|
|
64
|
-
self.
|
|
64
|
+
self._client = openai.OpenAI(
|
|
65
65
|
api_key=api_key or openai_api_key or os.environ.get("OPENAI_API_KEY"),
|
|
66
66
|
organization=organization,
|
|
67
67
|
project=project,
|
|
@@ -80,7 +80,7 @@ class Maitai:
|
|
|
80
80
|
default_headers=default_headers or {},
|
|
81
81
|
default_query=default_query or {},
|
|
82
82
|
)
|
|
83
|
-
self.chat = Chat(self.
|
|
83
|
+
self.chat = Chat(self._client, client_params)
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
class Chat:
|
|
@@ -90,8 +90,8 @@ class Chat:
|
|
|
90
90
|
|
|
91
91
|
class Completions:
|
|
92
92
|
def __init__(self, client: Optional[openai.Client] = None, client_params: Optional[ClientParams] = None):
|
|
93
|
-
self.
|
|
94
|
-
self.
|
|
93
|
+
self._client = client
|
|
94
|
+
self._client_params = client_params or ClientParams()
|
|
95
95
|
|
|
96
96
|
@required_args(["action_type", "application_ref_name", "messages"],
|
|
97
97
|
["intent", "application_ref_name", "messages"],
|
|
@@ -145,6 +145,7 @@ class Completions:
|
|
|
145
145
|
extra_body: Optional[Body] = None,
|
|
146
146
|
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
147
147
|
) -> Union[MaitaiCompletion, Iterable[MaitaiChunk]]:
|
|
148
|
+
retry_args = locals()
|
|
148
149
|
if not config.api_key:
|
|
149
150
|
raise ValueError("Maitai API Key has not been set")
|
|
150
151
|
if server_side_inference is False and apply_corrections is True:
|
|
@@ -188,6 +189,8 @@ class Completions:
|
|
|
188
189
|
stream_options = ChatCompletionStreamOptionsParam(include_usage=True)
|
|
189
190
|
if context_retrieval_enabled is None:
|
|
190
191
|
context_retrieval_enabled = maitai_config.context_retrieval_enabled
|
|
192
|
+
if fallback_model is None and maitai_config.fallback_model:
|
|
193
|
+
fallback_model = maitai_config.fallback_model
|
|
191
194
|
completion_params = get_chat_completion_params(
|
|
192
195
|
messages=messages,
|
|
193
196
|
model=model,
|
|
@@ -228,28 +231,40 @@ class Completions:
|
|
|
228
231
|
fallback_model=fallback_model,
|
|
229
232
|
user_id=user_id,
|
|
230
233
|
assistant=assistant,
|
|
231
|
-
client_params=self.
|
|
234
|
+
client_params=self._client_params,
|
|
232
235
|
)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
236
|
+
try:
|
|
237
|
+
response = maitai.Inference.infer(chat_request, callback, response_timeout)
|
|
238
|
+
if stream:
|
|
239
|
+
if 'self' in retry_args:
|
|
240
|
+
del retry_args['self']
|
|
241
|
+
retry_args['server_side_inference'] = False
|
|
242
|
+
retry_args['model'] = model
|
|
243
|
+
retry_args['fallback_model'] = fallback_model
|
|
244
|
+
return _process_inference_stream(response, retry_args, self.create)
|
|
245
|
+
# ChatCompletion only
|
|
246
|
+
for resp in response:
|
|
247
|
+
if resp.warning:
|
|
248
|
+
warnings.warn(resp.warning, InferenceWarning)
|
|
249
|
+
if resp.error:
|
|
250
|
+
raise InferenceException(resp.error)
|
|
251
|
+
return MaitaiCompletion(resp.chat_completion_response)
|
|
252
|
+
raise InferenceException("No data received")
|
|
253
|
+
except MaitaiConnectionError as e:
|
|
254
|
+
if "gpt" not in model and fallback_model and "gpt" in fallback_model:
|
|
255
|
+
model = fallback_model
|
|
256
|
+
if "gpt" not in model:
|
|
257
|
+
raise e
|
|
258
|
+
print("Maitai issue, retrying on client side")
|
|
259
|
+
server_side_inference = False
|
|
260
|
+
if not server_side_inference:
|
|
261
|
+
if self._client is None:
|
|
262
|
+
self._client = openai.OpenAI(
|
|
263
|
+
default_query=self._client_params.default_query or None,
|
|
264
|
+
default_headers=self._client_params.default_headers or None,
|
|
265
|
+
base_url=self._client_params.base_url or None,
|
|
251
266
|
)
|
|
252
|
-
response = self.
|
|
267
|
+
response = self._client.chat.completions.create(
|
|
253
268
|
messages=messages,
|
|
254
269
|
model=model,
|
|
255
270
|
frequency_penalty=frequency_penalty,
|
|
@@ -358,14 +373,25 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
358
373
|
)
|
|
359
374
|
|
|
360
375
|
|
|
361
|
-
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[MaitaiChunk]:
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
376
|
+
def _process_inference_stream(stream: Iterable[InferenceStreamResponse], retry_args: dict, retry_func) -> Iterable[MaitaiChunk]:
|
|
377
|
+
try:
|
|
378
|
+
for infer_resp in stream:
|
|
379
|
+
if infer_resp.warning:
|
|
380
|
+
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
381
|
+
if infer_resp.error:
|
|
382
|
+
raise InferenceException(infer_resp.error)
|
|
383
|
+
chunk = infer_resp.chat_completion_chunk
|
|
384
|
+
if chunk is not None:
|
|
385
|
+
yield MaitaiChunk(chunk)
|
|
386
|
+
if chunk.choices and chunk.choices[0].finish_reason:
|
|
387
|
+
return
|
|
388
|
+
except MaitaiConnectionError as e:
|
|
389
|
+
if 'gpt' not in retry_args.get('model', '') and 'gpt' in retry_args.get('fallback_model', ''):
|
|
390
|
+
retry_args['model'] = retry_args['fallback_model']
|
|
391
|
+
if 'gpt' in retry_args.get('model', ''):
|
|
392
|
+
print("Maitai issue, retrying on client side")
|
|
393
|
+
response = retry_func(**retry_args)
|
|
394
|
+
for resp in response:
|
|
395
|
+
yield resp
|
|
396
|
+
else:
|
|
397
|
+
raise e
|
|
@@ -11,7 +11,7 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
11
11
|
import maitai
|
|
12
12
|
from maitai._config import config
|
|
13
13
|
from maitai._evaluator import Evaluator
|
|
14
|
-
from maitai._inference import InferenceException, InferenceWarning
|
|
14
|
+
from maitai._inference import InferenceException, InferenceWarning, MaitaiConnectionError
|
|
15
15
|
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query, ToolFunction
|
|
16
16
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
17
17
|
from maitai.tools import Tools
|
|
@@ -59,7 +59,7 @@ class MaitaiAsync:
|
|
|
59
59
|
config.auth_keys.groq_api_key.key_value = groq_api_key
|
|
60
60
|
if anthropic_api_key:
|
|
61
61
|
config.auth_keys.anthropic_api_key.key_value = anthropic_api_key
|
|
62
|
-
self.
|
|
62
|
+
self._client = openai.AsyncClient(
|
|
63
63
|
api_key=api_key or openai_api_key,
|
|
64
64
|
organization=organization,
|
|
65
65
|
project=project,
|
|
@@ -79,7 +79,7 @@ class MaitaiAsync:
|
|
|
79
79
|
default_headers=default_headers or {},
|
|
80
80
|
default_query=default_query or {},
|
|
81
81
|
)
|
|
82
|
-
self.chat = AsyncChat(self.
|
|
82
|
+
self.chat = AsyncChat(self._client, client_params)
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
class AsyncChat:
|
|
@@ -89,8 +89,8 @@ class AsyncChat:
|
|
|
89
89
|
|
|
90
90
|
class AsyncCompletions:
|
|
91
91
|
def __init__(self, client: Optional[openai.AsyncClient] = None, client_params: Optional[ClientParams] = None):
|
|
92
|
-
self.
|
|
93
|
-
self.
|
|
92
|
+
self._client = client
|
|
93
|
+
self._client_params = client_params or ClientParams()
|
|
94
94
|
|
|
95
95
|
@required_args(["action_type", "application_ref_name", "messages"],
|
|
96
96
|
["intent", "application_ref_name", "messages"],
|
|
@@ -142,6 +142,7 @@ class AsyncCompletions:
|
|
|
142
142
|
extra_body: Optional[Body] = None,
|
|
143
143
|
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
144
144
|
) -> Union[MaitaiCompletion, AsyncIterable[MaitaiChunk]]:
|
|
145
|
+
retry_args = locals()
|
|
145
146
|
if not config.api_key:
|
|
146
147
|
raise ValueError("Maitai API Key has not been set")
|
|
147
148
|
if server_side_inference is False and apply_corrections is True:
|
|
@@ -185,7 +186,8 @@ class AsyncCompletions:
|
|
|
185
186
|
stream_options = ChatCompletionStreamOptionsParam(include_usage=True)
|
|
186
187
|
if context_retrieval_enabled is None:
|
|
187
188
|
context_retrieval_enabled = maitai_config.context_retrieval_enabled
|
|
188
|
-
|
|
189
|
+
if fallback_model is None and maitai_config.fallback_model:
|
|
190
|
+
fallback_model = maitai_config.fallback_model
|
|
189
191
|
completion_params = get_chat_completion_params(
|
|
190
192
|
messages=messages,
|
|
191
193
|
model=model,
|
|
@@ -226,27 +228,40 @@ class AsyncCompletions:
|
|
|
226
228
|
fallback_model=fallback_model,
|
|
227
229
|
user_id=user_id,
|
|
228
230
|
assistant=assistant,
|
|
229
|
-
client_params=self.
|
|
231
|
+
client_params=self._client_params,
|
|
230
232
|
)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
233
|
+
try:
|
|
234
|
+
response = await maitai.Inference.infer_async(chat_request, callback, response_timeout)
|
|
235
|
+
if stream:
|
|
236
|
+
if 'self' in retry_args:
|
|
237
|
+
del retry_args['self']
|
|
238
|
+
retry_args['server_side_inference'] = False
|
|
239
|
+
retry_args['model'] = model
|
|
240
|
+
retry_args['fallback_model'] = fallback_model
|
|
241
|
+
return _process_inference_stream_async(response, retry_args, self.create)
|
|
242
|
+
# ChatCompletion only
|
|
243
|
+
async for resp in response:
|
|
244
|
+
if resp.warning:
|
|
245
|
+
warnings.warn(resp.warning, InferenceWarning)
|
|
246
|
+
if resp.error:
|
|
247
|
+
raise InferenceException(resp.error)
|
|
248
|
+
return MaitaiCompletion(resp.chat_completion_response)
|
|
249
|
+
raise InferenceException("No data received")
|
|
250
|
+
except MaitaiConnectionError as e:
|
|
251
|
+
if "gpt" not in model and fallback_model and "gpt" in fallback_model:
|
|
252
|
+
model = fallback_model
|
|
253
|
+
if "gpt" not in model:
|
|
254
|
+
raise e
|
|
255
|
+
print("Maitai issue, retrying on client side")
|
|
256
|
+
server_side_inference = False
|
|
257
|
+
if not server_side_inference:
|
|
258
|
+
if self._client is None:
|
|
259
|
+
self._client = openai.AsyncOpenAI(
|
|
260
|
+
default_headers=self._client_params.default_headers or None,
|
|
261
|
+
default_query=self._client_params.default_query or None,
|
|
262
|
+
base_url=self._client_params.base_url or None,
|
|
248
263
|
)
|
|
249
|
-
response = await self.
|
|
264
|
+
response = await self._client.chat.completions.create(
|
|
250
265
|
messages=messages,
|
|
251
266
|
model=model,
|
|
252
267
|
frequency_penalty=frequency_penalty,
|
|
@@ -357,14 +372,25 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
357
372
|
)
|
|
358
373
|
|
|
359
374
|
|
|
360
|
-
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[MaitaiChunk]:
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
375
|
+
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse], retry_args: dict, retry_func) -> AsyncIterable[MaitaiChunk]:
|
|
376
|
+
try:
|
|
377
|
+
async for infer_resp in stream:
|
|
378
|
+
if infer_resp.warning:
|
|
379
|
+
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
380
|
+
if infer_resp.error:
|
|
381
|
+
raise InferenceException(infer_resp.error)
|
|
382
|
+
chunk = infer_resp.chat_completion_chunk
|
|
383
|
+
if chunk is not None:
|
|
384
|
+
yield MaitaiChunk(chunk)
|
|
385
|
+
if chunk.choices and chunk.choices[0].finish_reason:
|
|
386
|
+
return
|
|
387
|
+
except MaitaiConnectionError as e:
|
|
388
|
+
if 'gpt' not in retry_args.get('model', '') and 'gpt' in retry_args.get('fallback_model', ''):
|
|
389
|
+
retry_args['model'] = retry_args['fallback_model']
|
|
390
|
+
if 'gpt' in retry_args.get('model', ''):
|
|
391
|
+
print("Maitai issue, retrying on client side")
|
|
392
|
+
response = retry_func(**retry_args)
|
|
393
|
+
for resp in response:
|
|
394
|
+
yield resp
|
|
395
|
+
else:
|
|
396
|
+
raise e
|
|
@@ -320,6 +320,7 @@ class EvaluateRequest(betterproto.Message):
|
|
|
320
320
|
timeout: float = betterproto.float_field(19)
|
|
321
321
|
partial: str = betterproto.string_field(20)
|
|
322
322
|
stream: bool = betterproto.bool_field(21)
|
|
323
|
+
apply_corrections: bool = betterproto.bool_field(22)
|
|
323
324
|
|
|
324
325
|
|
|
325
326
|
@dataclass(eq=False, repr=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maitai_python-1.1.0b2 → maitai_python-1.1.1}/maitai_common/processes/websocket_listener_thread.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|