maitai-python 1.0.36__tar.gz → 1.0.37b0__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.36 → maitai_python-1.0.37b0}/PKG-INFO +1 -1
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_inference.py +4 -4
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_maitai.py +2 -2
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_maitai_async.py +2 -1
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_maitai_client.py +3 -1
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_types.py +32 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/version.py +1 -1
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/chat/__init__.py +1 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/README.md +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_azure.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_config.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_context.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_evaluator.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai/_utils.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/setup.cfg +0 -0
- {maitai_python-1.0.36 → maitai_python-1.0.37b0}/setup.py +0 -0
|
@@ -30,9 +30,9 @@ class Inference(MaitaiClient):
|
|
|
30
30
|
|
|
31
31
|
@classmethod
|
|
32
32
|
def infer(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool, evaluation_enabled: bool, evaluate_callback: EvaluateCallback = None,
|
|
33
|
-
timeout=None, context_retrieval_enabled=False, context_query='', return_request=False, fallback_model=None) -> Iterable[InferenceStreamResponse]:
|
|
33
|
+
timeout=None, context_retrieval_enabled=False, context_query='', return_request=False, fallback_model=None, user_id: str = "") -> Iterable[InferenceStreamResponse]:
|
|
34
34
|
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback,
|
|
35
|
-
context_retrieval_enabled, context_query, return_request, fallback_model)
|
|
35
|
+
context_retrieval_enabled, context_query, return_request, fallback_model, user_id)
|
|
36
36
|
if evaluate_callback:
|
|
37
37
|
q = ChunkQueue()
|
|
38
38
|
cls.run_async(cls.send_inference_request_async(chat_request, chunk_queue=q, evaluation_callback=evaluate_callback))
|
|
@@ -42,9 +42,9 @@ class Inference(MaitaiClient):
|
|
|
42
42
|
|
|
43
43
|
@classmethod
|
|
44
44
|
async def infer_async(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool, evaluation_enabled: bool,
|
|
45
|
-
evaluate_callback: EvaluateCallback = None, timeout=None, context_retrieval_enabled=False, context_query='', fallback_model=None) -> AsyncIterable[InferenceStreamResponse]:
|
|
45
|
+
evaluate_callback: EvaluateCallback = None, timeout=None, context_retrieval_enabled=False, context_query='', fallback_model=None, user_id="") -> AsyncIterable[InferenceStreamResponse]:
|
|
46
46
|
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback,
|
|
47
|
-
context_retrieval_enabled, context_query, fallback_model)
|
|
47
|
+
context_retrieval_enabled, context_query, fallback_model, user_id)
|
|
48
48
|
q = AsyncChunkQueue()
|
|
49
49
|
cls.run_async(cls.send_inference_request_async(chat_request, async_chunk_queue=q, evaluation_callback=evaluate_callback))
|
|
50
50
|
return QueueIterable(q, timeout=timeout)
|
|
@@ -93,6 +93,7 @@ class Completions:
|
|
|
93
93
|
self,
|
|
94
94
|
*,
|
|
95
95
|
# Maitai Arguments
|
|
96
|
+
user_id: str = "",
|
|
96
97
|
session_id: Union[str, int] = None,
|
|
97
98
|
reference_id: Union[str, int, None] = None,
|
|
98
99
|
intent: str = None,
|
|
@@ -200,7 +201,7 @@ class Completions:
|
|
|
200
201
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
201
202
|
response_timeout = timeout
|
|
202
203
|
response = maitai.Inference.infer(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
|
|
203
|
-
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, return_request=return_request, fallback_model=fallback_model)
|
|
204
|
+
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, return_request=return_request, fallback_model=fallback_model, user_id=user_id)
|
|
204
205
|
if stream:
|
|
205
206
|
return _process_inference_stream(response)
|
|
206
207
|
# ChatCompletion only
|
|
@@ -332,7 +333,6 @@ def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iter
|
|
|
332
333
|
raise InferenceException(infer_resp.error)
|
|
333
334
|
chunk = infer_resp.chat_completion_chunk
|
|
334
335
|
if chunk is not None:
|
|
335
|
-
print(chunk)
|
|
336
336
|
yield MaitaiChunk(chunk)
|
|
337
337
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
338
338
|
return
|
|
@@ -94,6 +94,7 @@ class AsyncCompletions:
|
|
|
94
94
|
self,
|
|
95
95
|
*,
|
|
96
96
|
# Maitai Arguments
|
|
97
|
+
user_id: str = "",
|
|
97
98
|
session_id: Union[str, int] = None,
|
|
98
99
|
reference_id: Union[str, int, None] = None,
|
|
99
100
|
intent: str = None,
|
|
@@ -201,7 +202,7 @@ class AsyncCompletions:
|
|
|
201
202
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
202
203
|
response_timeout = timeout
|
|
203
204
|
response = await maitai.Inference.infer_async(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
|
|
204
|
-
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, fallback_model=fallback_model)
|
|
205
|
+
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query, fallback_model=fallback_model, user_id=user_id)
|
|
205
206
|
if stream:
|
|
206
207
|
return _process_inference_stream_async(response)
|
|
207
208
|
# ChatCompletion only
|
|
@@ -35,7 +35,8 @@ class MaitaiClient:
|
|
|
35
35
|
threading.Thread(target=run).start()
|
|
36
36
|
|
|
37
37
|
@classmethod
|
|
38
|
-
def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback=None,
|
|
38
|
+
def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback=None,
|
|
39
|
+
context_retrieval_enabled=False, context_query=None, return_request=False, fallback_model=None, user_id=""):
|
|
39
40
|
infer_request: ChatCompletionRequest = ChatCompletionRequest()
|
|
40
41
|
infer_request.application_ref_name = application_ref_name
|
|
41
42
|
infer_request.reference_id = reference_id
|
|
@@ -50,4 +51,5 @@ class MaitaiClient:
|
|
|
50
51
|
infer_request.context_query = context_query
|
|
51
52
|
infer_request.return_request = return_request
|
|
52
53
|
infer_request.fallback_model = fallback_model
|
|
54
|
+
infer_request.user_id = user_id
|
|
53
55
|
return infer_request
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
from datetime import datetime
|
|
1
2
|
from typing import Mapping, Union
|
|
2
3
|
|
|
4
|
+
import openai.types.chat as openai_chat_types
|
|
3
5
|
from betterproto import Casing
|
|
4
6
|
from typing_extensions import Literal
|
|
5
7
|
|
|
@@ -27,6 +29,27 @@ class MaitaiChunk(ChatCompletionChunk):
|
|
|
27
29
|
def model_dump_json(self):
|
|
28
30
|
return self.to_pydict(casing=Casing.SNAKE)
|
|
29
31
|
|
|
32
|
+
def openai_dump_json(self):
|
|
33
|
+
data = self.to_pydict(casing=Casing.SNAKE)
|
|
34
|
+
if not data.get("choices"):
|
|
35
|
+
data["choices"] = []
|
|
36
|
+
if not data.get("created"):
|
|
37
|
+
data["created"] = int(datetime.utcnow().timestamp())
|
|
38
|
+
for i, choice in enumerate(data.get("choices")):
|
|
39
|
+
if choice.get("finish_reason") == "end_turn":
|
|
40
|
+
choice["finish_reason"] = "stop"
|
|
41
|
+
if not choice.get("index"):
|
|
42
|
+
choice["index"] = i
|
|
43
|
+
if not choice.get("delta"):
|
|
44
|
+
choice["delta"] = {
|
|
45
|
+
}
|
|
46
|
+
if data.get("usage"):
|
|
47
|
+
if not data["usage"].get("prompt_tokens"):
|
|
48
|
+
data["usage"]["prompt_tokens"] = 0
|
|
49
|
+
if not data["usage"].get("completion_tokens"):
|
|
50
|
+
data["usage"]["completion_tokens"] = 0
|
|
51
|
+
return openai_chat_types.ChatCompletionChunk(**data).model_dump_json()
|
|
52
|
+
|
|
30
53
|
|
|
31
54
|
class MaitaiCompletion(ChatCompletionResponse):
|
|
32
55
|
def __init__(self, chat_completion_response: ChatCompletionResponse = None):
|
|
@@ -38,3 +61,12 @@ class MaitaiCompletion(ChatCompletionResponse):
|
|
|
38
61
|
|
|
39
62
|
def model_dump_json(self):
|
|
40
63
|
return self.to_pydict(casing=Casing.SNAKE)
|
|
64
|
+
|
|
65
|
+
def openai_dump_json(self):
|
|
66
|
+
data = self.to_pydict(casing=Casing.SNAKE)
|
|
67
|
+
for i, choice in enumerate(data.get("choices")):
|
|
68
|
+
if not choice.get("index"):
|
|
69
|
+
choice["index"] = i
|
|
70
|
+
if choice.get("finish_reason") == "end_turn":
|
|
71
|
+
choice["finish_reason"] = "stop"
|
|
72
|
+
return openai_chat_types.ChatCompletion(**data).model_dump_json()
|
|
@@ -69,6 +69,7 @@ class ChatCompletionRequest(betterproto.Message):
|
|
|
69
69
|
context: str = betterproto.string_field(19)
|
|
70
70
|
return_request: bool = betterproto.bool_field(20)
|
|
71
71
|
fallback_model: str = betterproto.string_field(21)
|
|
72
|
+
user_id: str = betterproto.string_field(22)
|
|
72
73
|
|
|
73
74
|
|
|
74
75
|
@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
|
{maitai_python-1.0.36 → maitai_python-1.0.37b0}/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
|