maitai-python 1.0.33b0__tar.gz → 1.0.34b0__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.0.33b0 → maitai_python-1.0.34b0}/PKG-INFO +1 -1
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_config.py +2 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_maitai.py +11 -10
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_maitai_async.py +10 -10
- maitai_python-1.0.34b0/maitai/_types.py +40 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/config/config_service.py +1 -1
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/version.py +1 -1
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/chat/__init__.py +3 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/PKG-INFO +1 -1
- maitai_python-1.0.33b0/maitai/_types.py +0 -13
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/README.md +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_azure.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_context.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_evaluator.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_inference.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai/_utils.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/setup.cfg +0 -0
- {maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/setup.py +0 -0
|
@@ -12,11 +12,11 @@ import maitai
|
|
|
12
12
|
from maitai._config import config
|
|
13
13
|
from maitai._evaluator import Evaluator
|
|
14
14
|
from maitai._inference import InferenceException, InferenceWarning
|
|
15
|
-
from maitai._types import Body, Headers, Query
|
|
15
|
+
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
|
|
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_common.utils.proto_utils import openai_messages_to_proto
|
|
18
18
|
from maitai_common.utils.types import EvaluateCallback
|
|
19
|
-
from maitai_gen.chat import
|
|
19
|
+
from maitai_gen.chat import ChatCompletionParams, ChatMessage, EvaluationContentType
|
|
20
20
|
from maitai_gen.config import InferenceLocations
|
|
21
21
|
from maitai_gen.inference import InferenceStreamResponse
|
|
22
22
|
|
|
@@ -132,7 +132,7 @@ class Completions:
|
|
|
132
132
|
extra_query: Optional[Query] = None,
|
|
133
133
|
extra_body: Optional[Body] = None,
|
|
134
134
|
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
135
|
-
) -> Union[
|
|
135
|
+
) -> Union[MaitaiCompletion, Iterable[MaitaiChunk]]:
|
|
136
136
|
if not config.api_key:
|
|
137
137
|
raise ValueError("Maitai API Key has not been set")
|
|
138
138
|
if server_side_inference is False and apply_corrections is True:
|
|
@@ -204,13 +204,13 @@ class Completions:
|
|
|
204
204
|
if stream:
|
|
205
205
|
return _process_inference_stream(response)
|
|
206
206
|
# ChatCompletion only
|
|
207
|
-
chat_completion: Optional[
|
|
207
|
+
chat_completion: Optional[MaitaiCompletion] = None
|
|
208
208
|
for resp in response:
|
|
209
209
|
if resp.warning:
|
|
210
210
|
warnings.warn(resp.warning, InferenceWarning)
|
|
211
211
|
if resp.error:
|
|
212
212
|
raise InferenceException(resp.error)
|
|
213
|
-
return resp.chat_completion_response
|
|
213
|
+
return MaitaiCompletion(resp.chat_completion_response)
|
|
214
214
|
return chat_completion
|
|
215
215
|
else:
|
|
216
216
|
if self.client is None:
|
|
@@ -273,7 +273,7 @@ class Completions:
|
|
|
273
273
|
final_chunk=None,
|
|
274
274
|
content=""
|
|
275
275
|
)
|
|
276
|
-
return maitai_completion
|
|
276
|
+
return MaitaiCompletion(maitai_completion)
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
def _process_openai_stream(session_id: Union[str, int],
|
|
@@ -284,7 +284,7 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
284
284
|
stream: openai.Stream[openai_chat_types.ChatCompletionChunk],
|
|
285
285
|
evaluation_enabled: bool,
|
|
286
286
|
chat_completion_params: ChatCompletionParams,
|
|
287
|
-
callback: Optional[EvaluateCallback] = None, ) -> Iterable[
|
|
287
|
+
callback: Optional[EvaluateCallback] = None, ) -> Iterable[MaitaiChunk]:
|
|
288
288
|
full_body = ""
|
|
289
289
|
proto_messages = openai_messages_to_proto(messages)
|
|
290
290
|
last_chunk = None
|
|
@@ -297,7 +297,7 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
297
297
|
full_body += content
|
|
298
298
|
if maitai_chunk.usage and last_chunk is not None and not last_chunk.usage:
|
|
299
299
|
last_chunk.usage = maitai_chunk.usage
|
|
300
|
-
yield maitai_chunk
|
|
300
|
+
yield MaitaiChunk(maitai_chunk)
|
|
301
301
|
if evaluation_enabled:
|
|
302
302
|
proto_messages.append(ChatMessage(role="assistant", content=full_body))
|
|
303
303
|
Evaluator.evaluate(
|
|
@@ -324,7 +324,7 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
324
324
|
)
|
|
325
325
|
|
|
326
326
|
|
|
327
|
-
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[
|
|
327
|
+
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[MaitaiChunk]:
|
|
328
328
|
for infer_resp in stream:
|
|
329
329
|
if infer_resp.warning:
|
|
330
330
|
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
@@ -332,6 +332,7 @@ def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iter
|
|
|
332
332
|
raise InferenceException(infer_resp.error)
|
|
333
333
|
chunk = infer_resp.chat_completion_chunk
|
|
334
334
|
if chunk is not None:
|
|
335
|
-
|
|
335
|
+
print(chunk)
|
|
336
|
+
yield MaitaiChunk(chunk)
|
|
336
337
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
337
338
|
return
|
|
@@ -11,11 +11,11 @@ import maitai
|
|
|
11
11
|
from maitai._config import config
|
|
12
12
|
from maitai._evaluator import Evaluator
|
|
13
13
|
from maitai._inference import InferenceException, InferenceWarning
|
|
14
|
-
from maitai._types import Body, Headers, Query
|
|
14
|
+
from maitai._types import Body, Headers, MaitaiChunk, MaitaiCompletion, Query
|
|
15
15
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
16
16
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
17
17
|
from maitai_common.utils.types import EvaluateCallback
|
|
18
|
-
from maitai_gen.chat import
|
|
18
|
+
from maitai_gen.chat import ChatCompletionParams, ChatMessage, EvaluationContentType
|
|
19
19
|
from maitai_gen.config import InferenceLocations
|
|
20
20
|
from maitai_gen.inference import InferenceStreamResponse
|
|
21
21
|
|
|
@@ -132,7 +132,7 @@ class AsyncCompletions:
|
|
|
132
132
|
extra_query: Optional[Query] = None,
|
|
133
133
|
extra_body: Optional[Body] = None,
|
|
134
134
|
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
135
|
-
) -> Union[
|
|
135
|
+
) -> Union[MaitaiCompletion, AsyncIterable[MaitaiChunk]]:
|
|
136
136
|
if not config.api_key:
|
|
137
137
|
raise ValueError("Maitai API Key has not been set")
|
|
138
138
|
if server_side_inference is False and apply_corrections is True:
|
|
@@ -205,13 +205,13 @@ class AsyncCompletions:
|
|
|
205
205
|
if stream:
|
|
206
206
|
return _process_inference_stream_async(response)
|
|
207
207
|
# ChatCompletion only
|
|
208
|
-
chat_completion: Optional[
|
|
208
|
+
chat_completion: Optional[MaitaiCompletion] = None
|
|
209
209
|
async for resp in response:
|
|
210
210
|
if resp.warning:
|
|
211
211
|
warnings.warn(resp.warning, InferenceWarning)
|
|
212
212
|
if resp.error:
|
|
213
213
|
raise InferenceException(resp.error)
|
|
214
|
-
return resp.chat_completion_response
|
|
214
|
+
return MaitaiCompletion(resp.chat_completion_response)
|
|
215
215
|
return chat_completion
|
|
216
216
|
else:
|
|
217
217
|
if self.client is None:
|
|
@@ -274,7 +274,7 @@ class AsyncCompletions:
|
|
|
274
274
|
final_chunk=None,
|
|
275
275
|
content=""
|
|
276
276
|
)
|
|
277
|
-
return maitai_completion
|
|
277
|
+
return MaitaiCompletion(maitai_completion)
|
|
278
278
|
|
|
279
279
|
|
|
280
280
|
async def _process_async_openai_stream(session_id: Union[str, int],
|
|
@@ -285,7 +285,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
285
285
|
stream: openai.AsyncStream[openai_chat_types.ChatCompletionChunk],
|
|
286
286
|
evaluation_enabled: bool,
|
|
287
287
|
chat_completion_params: ChatCompletionParams,
|
|
288
|
-
callback: Optional[EvaluateCallback] = None) -> AsyncIterable[
|
|
288
|
+
callback: Optional[EvaluateCallback] = None) -> AsyncIterable[MaitaiChunk]:
|
|
289
289
|
full_body = ""
|
|
290
290
|
proto_messages = openai_messages_to_proto(messages)
|
|
291
291
|
last_chunk = None
|
|
@@ -298,7 +298,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
298
298
|
full_body += content
|
|
299
299
|
if maitai_chunk.usage and last_chunk is not None and not last_chunk.usage:
|
|
300
300
|
last_chunk.usage = maitai_chunk.usage
|
|
301
|
-
yield maitai_chunk
|
|
301
|
+
yield MaitaiChunk(maitai_chunk)
|
|
302
302
|
if last_chunk is None:
|
|
303
303
|
return
|
|
304
304
|
if evaluation_enabled:
|
|
@@ -327,7 +327,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
327
327
|
)
|
|
328
328
|
|
|
329
329
|
|
|
330
|
-
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[
|
|
330
|
+
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[MaitaiChunk]:
|
|
331
331
|
async for infer_resp in stream:
|
|
332
332
|
if infer_resp.warning:
|
|
333
333
|
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
@@ -335,6 +335,6 @@ async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamR
|
|
|
335
335
|
raise InferenceException(infer_resp.error)
|
|
336
336
|
chunk = infer_resp.chat_completion_chunk
|
|
337
337
|
if chunk is not None:
|
|
338
|
-
yield chunk
|
|
338
|
+
yield MaitaiChunk(chunk)
|
|
339
339
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
340
340
|
return
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import Mapping, Union
|
|
2
|
+
|
|
3
|
+
from betterproto import Casing
|
|
4
|
+
from typing_extensions import Literal
|
|
5
|
+
|
|
6
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionResponse, EvaluateRequest, EvaluateResponse
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Omit:
|
|
10
|
+
def __bool__(self) -> Literal[False]:
|
|
11
|
+
return False
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Headers = Mapping[str, Union[str, Omit]]
|
|
15
|
+
Query = Mapping[str, object]
|
|
16
|
+
Body = object
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MaitaiChunk(ChatCompletionChunk):
|
|
20
|
+
def __init__(self, chat_completion_chunk: ChatCompletionChunk = None):
|
|
21
|
+
super().__init__()
|
|
22
|
+
if chat_completion_chunk is not None:
|
|
23
|
+
if chat_completion_chunk.evaluate_response is not None:
|
|
24
|
+
self.evaluate_response = EvaluateResponse(evaluation_request=EvaluateRequest())
|
|
25
|
+
self.from_pydict(chat_completion_chunk.to_pydict())
|
|
26
|
+
|
|
27
|
+
def model_dumps_json(self):
|
|
28
|
+
return self.to_pydict(casing=Casing.SNAKE)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MaitaiCompletion(ChatCompletionResponse):
|
|
32
|
+
def __init__(self, chat_completion_response: ChatCompletionResponse = None):
|
|
33
|
+
super().__init__()
|
|
34
|
+
if chat_completion_response is not None:
|
|
35
|
+
if chat_completion_response.evaluate_response is not None:
|
|
36
|
+
self.evaluate_response = EvaluateResponse(evaluation_request=EvaluateRequest())
|
|
37
|
+
self.from_pydict(chat_completion_response.to_pydict())
|
|
38
|
+
|
|
39
|
+
def model_dumps_json(self):
|
|
40
|
+
return self.to_pydict(casing=Casing.SNAKE)
|
|
@@ -170,6 +170,7 @@ class ChatMessage(betterproto.Message):
|
|
|
170
170
|
2, optional=True, group="_content"
|
|
171
171
|
)
|
|
172
172
|
name: Optional[str] = betterproto.string_field(3, optional=True, group="_name")
|
|
173
|
+
tool_calls: List["ToolCall"] = betterproto.message_field(4)
|
|
173
174
|
|
|
174
175
|
|
|
175
176
|
@dataclass(eq=False, repr=False)
|
|
@@ -293,6 +294,8 @@ class EvaluateRequest(betterproto.Message):
|
|
|
293
294
|
betterproto.message_field(18, optional=True, group="_chat_completion_response")
|
|
294
295
|
)
|
|
295
296
|
timeout: float = betterproto.float_field(19)
|
|
297
|
+
partial: str = betterproto.string_field(20)
|
|
298
|
+
stream: bool = betterproto.bool_field(21)
|
|
296
299
|
|
|
297
300
|
|
|
298
301
|
@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
|
|
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
|
{maitai_python-1.0.33b0 → maitai_python-1.0.34b0}/maitai_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|