maitai-python 1.0.27__tar.gz → 1.0.27b0__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.27 → maitai_python-1.0.27b0}/PKG-INFO +2 -2
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/README.md +1 -1
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_evaluator.py +10 -10
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_inference.py +13 -8
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_maitai_client.py +2 -2
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_openai.py +22 -11
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_openai_async.py +22 -11
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/version.py +1 -1
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/application/__init__.py +4 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/inference/__init__.py +1 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_python.egg-info/PKG-INFO +2 -2
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_azure.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_config.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_openai_types.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai/_utils.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/chat/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/setup.cfg +0 -0
- {maitai_python-1.0.27 → maitai_python-1.0.27b0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: maitai-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.27b0
|
|
4
4
|
Summary: Maitai SDK for Python
|
|
5
5
|
Home-page: https://docs.trymaitai.ai
|
|
6
6
|
Author: Maitai
|
|
@@ -59,7 +59,7 @@ response = openai.chat.completions.create(
|
|
|
59
59
|
messages=messages,
|
|
60
60
|
model="gpt-4",
|
|
61
61
|
session_id="YOUR_SESSION_ID",
|
|
62
|
-
|
|
62
|
+
intent="NUMBER_GENERATOR",
|
|
63
63
|
application_ref_name="YOUR_APPLICATION_REF_NAME",
|
|
64
64
|
)
|
|
65
65
|
```
|
|
@@ -29,7 +29,7 @@ class Evaluator(MaitaiClient):
|
|
|
29
29
|
super().__init__()
|
|
30
30
|
|
|
31
31
|
@classmethod
|
|
32
|
-
async def evaluate_async(cls, session_id, reference_id,
|
|
32
|
+
async def evaluate_async(cls, session_id, reference_id, intent, content, content_type=None, application_id=None, application_ref_name=None, callback=None, completion_params: ChatCompletionParams = None,
|
|
33
33
|
chat_completion_response: ChatCompletionResponse = None, chat_completion_chunk: ChatCompletionChunk = None):
|
|
34
34
|
if content_type is None:
|
|
35
35
|
content_type = _get_content_type(content)
|
|
@@ -37,9 +37,9 @@ class Evaluator(MaitaiClient):
|
|
|
37
37
|
raise Exception('Unable to automatically determine content_type')
|
|
38
38
|
if application_id is None and application_ref_name is None:
|
|
39
39
|
raise Exception('application_id or application_ref_name must be provided')
|
|
40
|
-
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id,
|
|
40
|
+
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id, intent, content_type, content)
|
|
41
41
|
if completion_params is not None:
|
|
42
|
-
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id,
|
|
42
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, True, completion_params, callback)
|
|
43
43
|
if chat_completion_chunk is not None:
|
|
44
44
|
chat_completion_response = chat_completion_chunk_to_response(chat_completion_chunk, content)
|
|
45
45
|
eval_request.chat_completion_response = chat_completion_response
|
|
@@ -47,7 +47,7 @@ class Evaluator(MaitaiClient):
|
|
|
47
47
|
await asyncio.create_task(cls.send_evaluation_request_async(eval_request, callback))
|
|
48
48
|
|
|
49
49
|
@classmethod
|
|
50
|
-
def evaluate(cls, session_id, reference_id,
|
|
50
|
+
def evaluate(cls, session_id, reference_id, intent, content, content_type=None, application_id=None, application_ref_name=None, callback=None, partial=None, completion_params: ChatCompletionParams = None,
|
|
51
51
|
chat_completion_response: ChatCompletionResponse = None, chat_completion_chunk: ChatCompletionChunk = None):
|
|
52
52
|
if content_type is None:
|
|
53
53
|
content_type = _get_content_type(content, partial)
|
|
@@ -55,9 +55,9 @@ class Evaluator(MaitaiClient):
|
|
|
55
55
|
raise Exception('Unable to automatically determine content_type')
|
|
56
56
|
if application_id is None and application_ref_name is None:
|
|
57
57
|
raise Exception('application_id or application_ref_name must be provided')
|
|
58
|
-
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id,
|
|
58
|
+
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id, intent, content_type, content, partial=partial)
|
|
59
59
|
if completion_params is not None:
|
|
60
|
-
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id,
|
|
60
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, True, completion_params, callback)
|
|
61
61
|
if chat_completion_chunk is not None:
|
|
62
62
|
chat_completion_response = chat_completion_chunk_to_response(chat_completion_chunk, content)
|
|
63
63
|
eval_request.chat_completion_response = chat_completion_response
|
|
@@ -65,14 +65,14 @@ class Evaluator(MaitaiClient):
|
|
|
65
65
|
cls.run_async(cls.send_evaluation_request_async(eval_request, callback))
|
|
66
66
|
|
|
67
67
|
@classmethod
|
|
68
|
-
def stream_correction(cls, session_id, reference_id,
|
|
69
|
-
eval_request: EvaluateRequest = cls.create_eval_request(None, application_ref_name, session_id, reference_id,
|
|
68
|
+
def stream_correction(cls, session_id, reference_id, intent, content_type, content, application_ref_name, partial, fault_description, sentinel_id):
|
|
69
|
+
eval_request: EvaluateRequest = cls.create_eval_request(None, application_ref_name, session_id, reference_id, intent, content_type, content, partial=partial,
|
|
70
70
|
fault_description=fault_description)
|
|
71
71
|
eval_request.sentinel_id = sentinel_id
|
|
72
72
|
return cls.send_stream_correction_request(eval_request)
|
|
73
73
|
|
|
74
74
|
@classmethod
|
|
75
|
-
def create_eval_request(cls, application_id, application_ref_name, session_id, reference_id,
|
|
75
|
+
def create_eval_request(cls, application_id, application_ref_name, session_id, reference_id, intent,
|
|
76
76
|
content_type, content, partial=None, fault_description=None, chat_completion_response=None):
|
|
77
77
|
eval_request: EvaluateRequest = EvaluateRequest()
|
|
78
78
|
eval_request.evaluation_content_type = content_type
|
|
@@ -89,7 +89,7 @@ class Evaluator(MaitaiClient):
|
|
|
89
89
|
eval_request.application_ref_name = application_ref_name
|
|
90
90
|
eval_request.session_id = session_id
|
|
91
91
|
eval_request.reference_id = reference_id
|
|
92
|
-
eval_request.action_type =
|
|
92
|
+
eval_request.action_type = intent
|
|
93
93
|
if fault_description:
|
|
94
94
|
eval_request.fault_description = fault_description
|
|
95
95
|
return eval_request
|
|
@@ -19,15 +19,20 @@ class InferenceException(Exception):
|
|
|
19
19
|
super().__init__(msg)
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
class InferenceWarning(Warning):
|
|
23
|
+
def __init__(self, *args, **kwargs):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
22
27
|
class Inference(MaitaiClient):
|
|
23
28
|
|
|
24
29
|
def __init__(self):
|
|
25
30
|
super().__init__()
|
|
26
31
|
|
|
27
32
|
@classmethod
|
|
28
|
-
def infer(cls, session_id, reference_id,
|
|
33
|
+
def infer(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool, evaluation_enabled: bool, evaluate_callback: EvaluateCallback = None,
|
|
29
34
|
timeout=None) -> Iterable[InferenceStreamResponse]:
|
|
30
|
-
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id,
|
|
35
|
+
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback)
|
|
31
36
|
if evaluate_callback:
|
|
32
37
|
q = ChunkQueue()
|
|
33
38
|
cls.run_async(cls.send_inference_request_async(chat_request, chunk_queue=q, evaluation_callback=evaluate_callback))
|
|
@@ -36,27 +41,27 @@ class Inference(MaitaiClient):
|
|
|
36
41
|
return cls.send_inference_request(chat_request)
|
|
37
42
|
|
|
38
43
|
@classmethod
|
|
39
|
-
async def infer_async(cls, session_id, reference_id,
|
|
44
|
+
async def infer_async(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, apply_corrections: bool, evaluation_enabled: bool,
|
|
40
45
|
evaluate_callback: EvaluateCallback = None,
|
|
41
46
|
timeout=None) -> AsyncIterable[InferenceStreamResponse]:
|
|
42
|
-
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id,
|
|
47
|
+
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback)
|
|
43
48
|
q = AsyncChunkQueue()
|
|
44
49
|
cls.run_async(cls.send_inference_request_async(chat_request, async_chunk_queue=q, evaluation_callback=evaluate_callback))
|
|
45
50
|
return QueueIterable(q, timeout=timeout)
|
|
46
51
|
|
|
47
52
|
@classmethod
|
|
48
|
-
def create_chat_storage_request(cls, session_id, reference_id,
|
|
53
|
+
def create_chat_storage_request(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, chat_completion_response: Optional[ChatCompletionResponse],
|
|
49
54
|
final_chunk: Optional[ChatCompletionChunk], content: str):
|
|
50
|
-
inference_request = cls.create_inference_request(application_ref_name, session_id, reference_id,
|
|
55
|
+
inference_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, False, completion_params, None)
|
|
51
56
|
if final_chunk:
|
|
52
57
|
chat_completion_response = chat_completion_chunk_to_response(final_chunk, content)
|
|
53
58
|
|
|
54
59
|
return ChatStorageRequest(chat_completion_request=inference_request, chat_completion_response=chat_completion_response)
|
|
55
60
|
|
|
56
61
|
@classmethod
|
|
57
|
-
def store_chat_response(cls, session_id, reference_id,
|
|
62
|
+
def store_chat_response(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, chat_completion_response: Optional[ChatCompletionResponse],
|
|
58
63
|
final_chunk: Optional[ChatCompletionChunk], content: str):
|
|
59
|
-
chat_storage_request = cls.create_chat_storage_request(session_id, reference_id,
|
|
64
|
+
chat_storage_request = cls.create_chat_storage_request(session_id, reference_id, intent, application_ref_name, completion_params, chat_completion_response, final_chunk, content)
|
|
60
65
|
cls.run_async(cls.send_storage_request_async(chat_storage_request))
|
|
61
66
|
|
|
62
67
|
@classmethod
|
|
@@ -37,12 +37,12 @@ class MaitaiClient:
|
|
|
37
37
|
threading.Thread(target=run).start()
|
|
38
38
|
|
|
39
39
|
@classmethod
|
|
40
|
-
def create_inference_request(cls, application_ref_name, session_id, reference_id,
|
|
40
|
+
def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback):
|
|
41
41
|
infer_request: ChatCompletionRequest = ChatCompletionRequest()
|
|
42
42
|
infer_request.application_ref_name = application_ref_name
|
|
43
43
|
infer_request.reference_id = reference_id
|
|
44
44
|
infer_request.session_id = session_id
|
|
45
|
-
infer_request.action_type =
|
|
45
|
+
infer_request.action_type = intent
|
|
46
46
|
infer_request.apply_corrections = apply_corrections
|
|
47
47
|
infer_request.params = completion_params
|
|
48
48
|
infer_request.evaluation_enabled = evaluation_enabled
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from typing import Dict, Iterable, List, Mapping, Optional, Union
|
|
2
3
|
|
|
3
4
|
import httpx
|
|
@@ -9,7 +10,7 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
9
10
|
import maitai
|
|
10
11
|
from maitai._config import config
|
|
11
12
|
from maitai._evaluator import Evaluator
|
|
12
|
-
from maitai._inference import InferenceException
|
|
13
|
+
from maitai._inference import InferenceException, InferenceWarning
|
|
13
14
|
from maitai._openai_types import Body, Headers, Query
|
|
14
15
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
15
16
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
@@ -72,15 +73,19 @@ class Completions:
|
|
|
72
73
|
self.client = client
|
|
73
74
|
|
|
74
75
|
@required_args(["session_id", "action_type", "application_ref_name", "messages"],
|
|
76
|
+
["session_id", "intent", "application_ref_name", "messages"],
|
|
75
77
|
["session_id", "action_type", "application_ref_name", "messages", "model"],
|
|
76
|
-
["session_id", "
|
|
78
|
+
["session_id", "intent", "application_ref_name", "messages", "model"],
|
|
79
|
+
["session_id", "action_type", "application_ref_name", "messages", "model", "stream"],
|
|
80
|
+
["session_id", "intent", "application_ref_name", "messages", "model", "stream"])
|
|
77
81
|
def create(
|
|
78
82
|
self,
|
|
79
83
|
*,
|
|
80
84
|
# Maitai Arguments
|
|
81
85
|
session_id: Union[str, int] = None,
|
|
82
86
|
reference_id: Union[str, int, None] = None,
|
|
83
|
-
|
|
87
|
+
intent: str = None,
|
|
88
|
+
action_type: str = None, # DEPRECATED
|
|
84
89
|
application_ref_name: str = None,
|
|
85
90
|
callback: Optional[EvaluateCallback] = None,
|
|
86
91
|
server_side_inference: bool = None,
|
|
@@ -119,7 +124,9 @@ class Completions:
|
|
|
119
124
|
raise ValueError("server_side_inference must be true to apply_corrections")
|
|
120
125
|
if apply_corrections is True and evaluation_enabled is False:
|
|
121
126
|
raise ValueError("evaluations must be enabled to apply_corrections")
|
|
122
|
-
|
|
127
|
+
if not intent and action_type:
|
|
128
|
+
intent = action_type
|
|
129
|
+
maitai_config = config.get_application_action_config(application_ref_name, intent)
|
|
123
130
|
if server_side_inference is None:
|
|
124
131
|
server_side_inference = maitai_config.inference_location == InferenceLocations.SERVER
|
|
125
132
|
if evaluation_enabled is None:
|
|
@@ -173,12 +180,14 @@ class Completions:
|
|
|
173
180
|
response_timeout = None
|
|
174
181
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
175
182
|
response_timeout = timeout
|
|
176
|
-
response = maitai.Inference.infer(session_id, reference_id,
|
|
183
|
+
response = maitai.Inference.infer(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout)
|
|
177
184
|
if stream:
|
|
178
185
|
return _process_inference_stream(response)
|
|
179
186
|
# ChatCompletion only
|
|
180
187
|
chat_completion: Optional[ChatCompletionResponse] = None
|
|
181
188
|
for resp in response:
|
|
189
|
+
if resp.warning:
|
|
190
|
+
warnings.warn(resp.warning, InferenceWarning)
|
|
182
191
|
if resp.error:
|
|
183
192
|
raise InferenceException(resp.error)
|
|
184
193
|
return resp.chat_completion_response
|
|
@@ -215,7 +224,7 @@ class Completions:
|
|
|
215
224
|
|
|
216
225
|
)
|
|
217
226
|
if stream:
|
|
218
|
-
return _process_openai_stream(session_id, reference_id,
|
|
227
|
+
return _process_openai_stream(session_id, reference_id, intent, application_ref_name, messages, response, evaluation_enabled, completion_params, callback)
|
|
219
228
|
else:
|
|
220
229
|
maitai_completion = convert_openai_chat_completion(response)
|
|
221
230
|
proto_messages = openai_messages_to_proto(messages)
|
|
@@ -225,7 +234,7 @@ class Completions:
|
|
|
225
234
|
maitai.Evaluator.evaluate(
|
|
226
235
|
session_id=session_id,
|
|
227
236
|
reference_id=reference_id,
|
|
228
|
-
|
|
237
|
+
intent=intent,
|
|
229
238
|
content_type=EvaluationContentType.MESSAGE,
|
|
230
239
|
content=proto_messages,
|
|
231
240
|
application_ref_name=application_ref_name,
|
|
@@ -237,7 +246,7 @@ class Completions:
|
|
|
237
246
|
maitai.Inference.store_chat_response(
|
|
238
247
|
session_id=session_id,
|
|
239
248
|
reference_id=reference_id,
|
|
240
|
-
|
|
249
|
+
intent=intent,
|
|
241
250
|
application_ref_name=application_ref_name,
|
|
242
251
|
chat_completion_response=maitai_completion,
|
|
243
252
|
completion_params=completion_params,
|
|
@@ -249,7 +258,7 @@ class Completions:
|
|
|
249
258
|
|
|
250
259
|
def _process_openai_stream(session_id: Union[str, int],
|
|
251
260
|
reference_id: Union[str, int, None],
|
|
252
|
-
|
|
261
|
+
intent: str,
|
|
253
262
|
application_ref_name: str,
|
|
254
263
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
255
264
|
stream: openai.Stream[openai_chat_types.ChatCompletionChunk],
|
|
@@ -270,7 +279,7 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
270
279
|
Evaluator.evaluate(
|
|
271
280
|
session_id=session_id,
|
|
272
281
|
reference_id=reference_id,
|
|
273
|
-
|
|
282
|
+
intent=intent,
|
|
274
283
|
content_type=EvaluationContentType.MESSAGE,
|
|
275
284
|
content=proto_messages,
|
|
276
285
|
application_ref_name=application_ref_name,
|
|
@@ -282,7 +291,7 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
282
291
|
maitai.Inference.store_chat_response(
|
|
283
292
|
session_id=session_id,
|
|
284
293
|
reference_id=reference_id,
|
|
285
|
-
|
|
294
|
+
intent=intent,
|
|
286
295
|
application_ref_name=application_ref_name,
|
|
287
296
|
completion_params=chat_completion_params,
|
|
288
297
|
final_chunk=maitai_chunk,
|
|
@@ -294,6 +303,8 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
294
303
|
|
|
295
304
|
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[ChatCompletionChunk]:
|
|
296
305
|
for infer_resp in stream:
|
|
306
|
+
if infer_resp.warning:
|
|
307
|
+
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
297
308
|
if infer_resp.error:
|
|
298
309
|
raise InferenceException(infer_resp.error)
|
|
299
310
|
chunk = infer_resp.chat_completion_chunk
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from typing import AsyncIterable, Dict, Iterable, List, Mapping, Optional, Union
|
|
2
3
|
|
|
3
4
|
import httpx
|
|
@@ -9,7 +10,7 @@ from openai.types.chat import ChatCompletionStreamOptionsParam
|
|
|
9
10
|
import maitai
|
|
10
11
|
from maitai._config import config
|
|
11
12
|
from maitai._evaluator import Evaluator
|
|
12
|
-
from maitai._inference import InferenceException
|
|
13
|
+
from maitai._inference import InferenceException, InferenceWarning
|
|
13
14
|
from maitai._openai_types import Body, Headers, Query
|
|
14
15
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
15
16
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
@@ -76,15 +77,19 @@ class AsyncCompletions:
|
|
|
76
77
|
self.client = client
|
|
77
78
|
|
|
78
79
|
@required_args(["session_id", "action_type", "application_ref_name", "messages"],
|
|
80
|
+
["session_id", "intent", "application_ref_name", "messages"],
|
|
79
81
|
["session_id", "action_type", "application_ref_name", "messages", "model"],
|
|
80
|
-
["session_id", "
|
|
82
|
+
["session_id", "intent", "application_ref_name", "messages", "model"],
|
|
83
|
+
["session_id", "action_type", "application_ref_name", "messages", "model", "stream"],
|
|
84
|
+
["session_id", "intent", "application_ref_name", "messages", "model", "stream"])
|
|
81
85
|
async def create(
|
|
82
86
|
self,
|
|
83
87
|
*,
|
|
84
88
|
# Maitai Arguments
|
|
85
89
|
session_id: Union[str, int] = None,
|
|
86
90
|
reference_id: Union[str, int, None] = None,
|
|
87
|
-
|
|
91
|
+
intent: str = None,
|
|
92
|
+
action_type: str = None, # DEPRECATED
|
|
88
93
|
application_ref_name: str = None,
|
|
89
94
|
callback: Optional[EvaluateCallback] = None,
|
|
90
95
|
server_side_inference: bool = None,
|
|
@@ -124,7 +129,9 @@ class AsyncCompletions:
|
|
|
124
129
|
raise ValueError("server_side_inference must be true to apply_corrections")
|
|
125
130
|
if apply_corrections is True and evaluation_enabled is False:
|
|
126
131
|
raise ValueError("evaluations must be enabled to apply_corrections")
|
|
127
|
-
|
|
132
|
+
if action_type and not intent:
|
|
133
|
+
intent = action_type
|
|
134
|
+
maitai_config = config.get_application_action_config(application_ref_name, intent)
|
|
128
135
|
if server_side_inference is None:
|
|
129
136
|
server_side_inference = maitai_config.inference_location == InferenceLocations.SERVER
|
|
130
137
|
if evaluation_enabled is None:
|
|
@@ -179,12 +186,14 @@ class AsyncCompletions:
|
|
|
179
186
|
response_timeout = None
|
|
180
187
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
181
188
|
response_timeout = timeout
|
|
182
|
-
response = await maitai.Inference.infer_async(session_id, reference_id,
|
|
189
|
+
response = await maitai.Inference.infer_async(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout)
|
|
183
190
|
if stream:
|
|
184
191
|
return _process_inference_stream_async(response)
|
|
185
192
|
# ChatCompletion only
|
|
186
193
|
chat_completion: Optional[ChatCompletionResponse] = None
|
|
187
194
|
async for resp in response:
|
|
195
|
+
if resp.warning:
|
|
196
|
+
warnings.warn(resp.warning, InferenceWarning)
|
|
188
197
|
if resp.error:
|
|
189
198
|
raise InferenceException(resp.error)
|
|
190
199
|
return resp.chat_completion_response
|
|
@@ -221,7 +230,7 @@ class AsyncCompletions:
|
|
|
221
230
|
|
|
222
231
|
)
|
|
223
232
|
if stream:
|
|
224
|
-
return _process_async_openai_stream(session_id, reference_id,
|
|
233
|
+
return _process_async_openai_stream(session_id, reference_id, intent, application_ref_name, messages, response, evaluation_enabled, completion_params, callback)
|
|
225
234
|
else:
|
|
226
235
|
maitai_completion = convert_openai_chat_completion(response)
|
|
227
236
|
proto_messages = openai_messages_to_proto(messages)
|
|
@@ -231,7 +240,7 @@ class AsyncCompletions:
|
|
|
231
240
|
await maitai.Evaluator.evaluate_async(
|
|
232
241
|
session_id=session_id,
|
|
233
242
|
reference_id=reference_id,
|
|
234
|
-
|
|
243
|
+
intent=intent,
|
|
235
244
|
content_type=EvaluationContentType.MESSAGE,
|
|
236
245
|
content=proto_messages,
|
|
237
246
|
application_ref_name=application_ref_name,
|
|
@@ -243,7 +252,7 @@ class AsyncCompletions:
|
|
|
243
252
|
maitai.Inference.store_chat_response(
|
|
244
253
|
session_id=session_id,
|
|
245
254
|
reference_id=reference_id,
|
|
246
|
-
|
|
255
|
+
intent=intent,
|
|
247
256
|
application_ref_name=application_ref_name,
|
|
248
257
|
chat_completion_response=maitai_completion,
|
|
249
258
|
completion_params=completion_params,
|
|
@@ -255,7 +264,7 @@ class AsyncCompletions:
|
|
|
255
264
|
|
|
256
265
|
async def _process_async_openai_stream(session_id: Union[str, int],
|
|
257
266
|
reference_id: Union[str, int, None],
|
|
258
|
-
|
|
267
|
+
intent: str,
|
|
259
268
|
application_ref_name: str,
|
|
260
269
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
261
270
|
stream: openai.AsyncStream[openai_chat_types.ChatCompletionChunk],
|
|
@@ -276,7 +285,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
276
285
|
await Evaluator.evaluate_async(
|
|
277
286
|
session_id=session_id,
|
|
278
287
|
reference_id=reference_id,
|
|
279
|
-
|
|
288
|
+
intent=intent,
|
|
280
289
|
content_type=EvaluationContentType.MESSAGE,
|
|
281
290
|
content=proto_messages,
|
|
282
291
|
application_ref_name=application_ref_name,
|
|
@@ -288,7 +297,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
288
297
|
maitai.Inference.store_chat_response(
|
|
289
298
|
session_id=session_id,
|
|
290
299
|
reference_id=reference_id,
|
|
291
|
-
|
|
300
|
+
intent=intent,
|
|
292
301
|
application_ref_name=application_ref_name,
|
|
293
302
|
completion_params=chat_completion_params,
|
|
294
303
|
final_chunk=maitai_chunk,
|
|
@@ -300,6 +309,8 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
300
309
|
|
|
301
310
|
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[ChatCompletionChunk]:
|
|
302
311
|
async for infer_resp in stream:
|
|
312
|
+
if infer_resp.warning:
|
|
313
|
+
warnings.warn(infer_resp.warning, InferenceWarning)
|
|
303
314
|
if infer_resp.error:
|
|
304
315
|
raise InferenceException(infer_resp.error)
|
|
305
316
|
chunk = infer_resp.chat_completion_chunk
|
|
@@ -30,6 +30,10 @@ class ApplicationContext(betterproto.Message):
|
|
|
30
30
|
date_created: int = betterproto.int64_field(2)
|
|
31
31
|
application_id: int = betterproto.int64_field(3)
|
|
32
32
|
context_body: str = betterproto.string_field(4)
|
|
33
|
+
context_type: str = betterproto.string_field(5)
|
|
34
|
+
context_path: str = betterproto.string_field(6)
|
|
35
|
+
reference: str = betterproto.string_field(7)
|
|
36
|
+
description: str = betterproto.string_field(8)
|
|
33
37
|
|
|
34
38
|
|
|
35
39
|
@dataclass(eq=False, repr=False)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: maitai-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.27b0
|
|
4
4
|
Summary: Maitai SDK for Python
|
|
5
5
|
Home-page: https://docs.trymaitai.ai
|
|
6
6
|
Author: Maitai
|
|
@@ -59,7 +59,7 @@ response = openai.chat.completions.create(
|
|
|
59
59
|
messages=messages,
|
|
60
60
|
model="gpt-4",
|
|
61
61
|
session_id="YOUR_SESSION_ID",
|
|
62
|
-
|
|
62
|
+
intent="NUMBER_GENERATOR",
|
|
63
63
|
application_ref_name="YOUR_APPLICATION_REF_NAME",
|
|
64
64
|
)
|
|
65
65
|
```
|
|
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.27 → maitai_python-1.0.27b0}/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
|