maitai-python 1.0.29__tar.gz → 1.0.30__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.29 → maitai_python-1.0.30}/PKG-INFO +1 -1
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/__init__.py +2 -0
- maitai_python-1.0.30/maitai/_context.py +60 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_evaluator.py +2 -2
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_inference.py +5 -6
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_maitai_client.py +3 -3
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_openai.py +38 -30
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_openai_async.py +40 -31
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/config/config_service.py +1 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/version.py +1 -1
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/chat/__init__.py +2 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/config/__init__.py +1 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/session/__init__.py +0 -9
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_python.egg-info/SOURCES.txt +1 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/README.md +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_azure.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_config.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_openai_types.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai/_utils.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/setup.cfg +0 -0
- {maitai_python-1.0.29 → maitai_python-1.0.30}/setup.py +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
3
|
from maitai._azure import MaitaiAsyncAzureOpenAIClient as AsyncAzureOpenAI, MaitaiAzureOpenAIClient as AzureOpenAI
|
|
4
|
+
from maitai._context import ContextManager
|
|
4
5
|
from maitai._evaluator import Evaluator as Evaluator
|
|
5
6
|
from maitai._inference import Inference as Inference
|
|
6
7
|
from maitai._openai import Chat, MaitaiOpenAIClient as OpenAI
|
|
7
8
|
from maitai._openai_async import MaitaiAsyncOpenAIClient as AsyncOpenAI
|
|
8
9
|
|
|
9
10
|
chat = Chat()
|
|
11
|
+
context = ContextManager()
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
def initialize(api_key):
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from betterproto import Casing
|
|
5
|
+
|
|
6
|
+
from maitai._config import config
|
|
7
|
+
from maitai._utils import required_args
|
|
8
|
+
from maitai_common.version import version
|
|
9
|
+
from maitai_gen.application import ApplicationContext
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ContextManager:
|
|
13
|
+
@required_args(["application_ref_name", "reference", "context_body"],
|
|
14
|
+
["application_ref_name", "reference", "file_path"])
|
|
15
|
+
def update(self, *, application_ref_name: str, reference: str, context_body: str = '', file_path: str = ''):
|
|
16
|
+
if not reference:
|
|
17
|
+
raise ValueError("Reference is required")
|
|
18
|
+
if context_body and file_path:
|
|
19
|
+
raise ValueError("Only one of context_body and file can be specified")
|
|
20
|
+
|
|
21
|
+
context = ApplicationContext()
|
|
22
|
+
context.reference = reference
|
|
23
|
+
if file_path:
|
|
24
|
+
s3_path = self.upload_context_file(file_path).get('s3_path')
|
|
25
|
+
if not s3_path:
|
|
26
|
+
raise Exception('Failed to upload context')
|
|
27
|
+
context.context_type = 'FILE'
|
|
28
|
+
context.context_path = s3_path
|
|
29
|
+
else:
|
|
30
|
+
context.context_body = context_body
|
|
31
|
+
context.context_type = 'TEXT'
|
|
32
|
+
|
|
33
|
+
host = config.maitai_host
|
|
34
|
+
url = f'{host}/context/application'
|
|
35
|
+
headers = {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'x-api-key': config.api_key,
|
|
38
|
+
'x-client-version': version,
|
|
39
|
+
}
|
|
40
|
+
response = requests.put(url, headers=headers, data=json.dumps({
|
|
41
|
+
'application_ref_name': application_ref_name,
|
|
42
|
+
'context': context.to_pydict(casing=Casing.SNAKE),
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
if response.status_code != 200:
|
|
46
|
+
raise RuntimeError(f"Error updating context: {response.text}")
|
|
47
|
+
|
|
48
|
+
def upload_context_file(self, file_path: str):
|
|
49
|
+
host = config.maitai_host
|
|
50
|
+
url = f'{host}/context/application/file'
|
|
51
|
+
headers = {
|
|
52
|
+
'x-api-key': config.api_key,
|
|
53
|
+
'x-client-version': version,
|
|
54
|
+
}
|
|
55
|
+
with open(file_path, 'rb') as file:
|
|
56
|
+
files = {'file': file}
|
|
57
|
+
response = requests.post(url, headers=headers, files=files)
|
|
58
|
+
if response.status_code != 200:
|
|
59
|
+
raise RuntimeError(f"Error uploading context: {response.text}")
|
|
60
|
+
return response.json()
|
|
@@ -39,7 +39,7 @@ class Evaluator(MaitaiClient):
|
|
|
39
39
|
raise Exception('application_id or application_ref_name must be provided')
|
|
40
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, intent, False, True, completion_params, callback)
|
|
42
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, True, completion_params, callback, False, '')
|
|
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
|
|
@@ -57,7 +57,7 @@ class Evaluator(MaitaiClient):
|
|
|
57
57
|
raise Exception('application_id or application_ref_name must be provided')
|
|
58
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, intent, False, True, completion_params, callback)
|
|
60
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, True, completion_params, callback, False, '')
|
|
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
|
|
@@ -31,8 +31,8 @@ class Inference(MaitaiClient):
|
|
|
31
31
|
|
|
32
32
|
@classmethod
|
|
33
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,
|
|
34
|
-
timeout=None) -> Iterable[InferenceStreamResponse]:
|
|
35
|
-
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback)
|
|
34
|
+
timeout=None, context_retrieval_enabled=False, context_query='') -> Iterable[InferenceStreamResponse]:
|
|
35
|
+
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback, context_retrieval_enabled, context_query)
|
|
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,8 @@ 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,
|
|
46
|
-
|
|
47
|
-
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback)
|
|
45
|
+
evaluate_callback: EvaluateCallback = None, timeout=None, context_retrieval_enabled=False, context_query='') -> AsyncIterable[InferenceStreamResponse]:
|
|
46
|
+
chat_request: ChatCompletionRequest = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params, evaluate_callback, context_retrieval_enabled, context_query)
|
|
48
47
|
q = AsyncChunkQueue()
|
|
49
48
|
cls.run_async(cls.send_inference_request_async(chat_request, async_chunk_queue=q, evaluation_callback=evaluate_callback))
|
|
50
49
|
return QueueIterable(q, timeout=timeout)
|
|
@@ -52,7 +51,7 @@ class Inference(MaitaiClient):
|
|
|
52
51
|
@classmethod
|
|
53
52
|
def create_chat_storage_request(cls, session_id, reference_id, intent, application_ref_name, completion_params: ChatCompletionParams, chat_completion_response: Optional[ChatCompletionResponse],
|
|
54
53
|
final_chunk: Optional[ChatCompletionChunk], content: str):
|
|
55
|
-
inference_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, False, completion_params, None)
|
|
54
|
+
inference_request = cls.create_inference_request(application_ref_name, session_id, reference_id, intent, False, False, completion_params, None, False, '')
|
|
56
55
|
if final_chunk:
|
|
57
56
|
chat_completion_response = chat_completion_chunk_to_response(final_chunk, content)
|
|
58
57
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import os
|
|
3
2
|
import threading
|
|
4
3
|
|
|
5
4
|
from maitai._config import config
|
|
@@ -7,7 +6,6 @@ from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest
|
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
class MaitaiClient:
|
|
10
|
-
MAITAI_HOST = os.environ.get("MAITAI_HOST", 'https://api.trymaitai.ai')
|
|
11
9
|
|
|
12
10
|
def __init__(self):
|
|
13
11
|
super().__init__()
|
|
@@ -37,7 +35,7 @@ class MaitaiClient:
|
|
|
37
35
|
threading.Thread(target=run).start()
|
|
38
36
|
|
|
39
37
|
@classmethod
|
|
40
|
-
def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback):
|
|
38
|
+
def create_inference_request(cls, application_ref_name, session_id, reference_id, intent, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams, callback, context_retrieval_enabled, context_query):
|
|
41
39
|
infer_request: ChatCompletionRequest = ChatCompletionRequest()
|
|
42
40
|
infer_request.application_ref_name = application_ref_name
|
|
43
41
|
infer_request.reference_id = reference_id
|
|
@@ -48,4 +46,6 @@ class MaitaiClient:
|
|
|
48
46
|
infer_request.evaluation_enabled = evaluation_enabled
|
|
49
47
|
infer_request.auth_keys = config.auth_keys
|
|
50
48
|
infer_request.return_evaluation = True if callback else False
|
|
49
|
+
infer_request.context_retrieval_enabled = context_retrieval_enabled
|
|
50
|
+
infer_request.context_query = context_query
|
|
51
51
|
return infer_request
|
|
@@ -91,6 +91,8 @@ class Completions:
|
|
|
91
91
|
server_side_inference: bool = None,
|
|
92
92
|
evaluation_enabled: bool = None,
|
|
93
93
|
apply_corrections: bool = None,
|
|
94
|
+
context_retrieval_enabled: bool = None,
|
|
95
|
+
context_query: str = '',
|
|
94
96
|
# OpenAI Arguments
|
|
95
97
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
96
98
|
model: Union[str, openai_types.ChatModel, openai.NotGiven] = openai.NOT_GIVEN,
|
|
@@ -157,6 +159,8 @@ class Completions:
|
|
|
157
159
|
timeout = maitai_config.timeout
|
|
158
160
|
if stream_options == openai.NOT_GIVEN and stream:
|
|
159
161
|
stream_options = ChatCompletionStreamOptionsParam(include_usage=True)
|
|
162
|
+
if context_retrieval_enabled is None:
|
|
163
|
+
context_retrieval_enabled = maitai_config.context_retrieval_enabled
|
|
160
164
|
completion_params = get_chat_completion_params(
|
|
161
165
|
messages=messages,
|
|
162
166
|
model=model,
|
|
@@ -182,7 +186,8 @@ class Completions:
|
|
|
182
186
|
response_timeout = None
|
|
183
187
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
184
188
|
response_timeout = timeout
|
|
185
|
-
response = maitai.Inference.infer(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout
|
|
189
|
+
response = maitai.Inference.infer(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
|
|
190
|
+
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query)
|
|
186
191
|
if stream:
|
|
187
192
|
return _process_inference_stream(response)
|
|
188
193
|
# ChatCompletion only
|
|
@@ -269,38 +274,41 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
269
274
|
callback: Optional[EvaluateCallback] = None, ) -> Iterable[ChatCompletionChunk]:
|
|
270
275
|
full_body = ""
|
|
271
276
|
proto_messages = openai_messages_to_proto(messages)
|
|
277
|
+
last_chunk = None
|
|
272
278
|
for chunk in stream:
|
|
273
279
|
maitai_chunk = convert_open_ai_chat_completion_chunk(chunk)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
280
|
+
if maitai_chunk.choices:
|
|
281
|
+
last_chunk = maitai_chunk
|
|
282
|
+
content = maitai_chunk.choices[0].delta.content
|
|
283
|
+
if content is not None:
|
|
284
|
+
full_body += content
|
|
285
|
+
if maitai_chunk.usage and last_chunk is not None and not last_chunk.usage:
|
|
286
|
+
last_chunk.usage = maitai_chunk.usage
|
|
277
287
|
yield maitai_chunk
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
)
|
|
303
|
-
return
|
|
288
|
+
if evaluation_enabled:
|
|
289
|
+
proto_messages.append(ChatMessage(role="assistant", content=full_body))
|
|
290
|
+
Evaluator.evaluate(
|
|
291
|
+
session_id=session_id,
|
|
292
|
+
reference_id=reference_id,
|
|
293
|
+
intent=intent,
|
|
294
|
+
content_type=EvaluationContentType.MESSAGE,
|
|
295
|
+
content=proto_messages,
|
|
296
|
+
application_ref_name=application_ref_name,
|
|
297
|
+
callback=callback,
|
|
298
|
+
chat_completion_chunk=last_chunk,
|
|
299
|
+
completion_params=chat_completion_params,
|
|
300
|
+
)
|
|
301
|
+
else:
|
|
302
|
+
maitai.Inference.store_chat_response(
|
|
303
|
+
session_id=session_id,
|
|
304
|
+
reference_id=reference_id,
|
|
305
|
+
intent=intent,
|
|
306
|
+
application_ref_name=application_ref_name,
|
|
307
|
+
completion_params=chat_completion_params,
|
|
308
|
+
final_chunk=last_chunk,
|
|
309
|
+
content=full_body,
|
|
310
|
+
chat_completion_response=None,
|
|
311
|
+
)
|
|
304
312
|
|
|
305
313
|
|
|
306
314
|
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[ChatCompletionChunk]:
|
|
@@ -95,7 +95,8 @@ class AsyncCompletions:
|
|
|
95
95
|
server_side_inference: bool = None,
|
|
96
96
|
evaluation_enabled: bool = None,
|
|
97
97
|
apply_corrections: bool = None,
|
|
98
|
-
|
|
98
|
+
context_retrieval_enabled: bool = None,
|
|
99
|
+
context_query: str = None,
|
|
99
100
|
# OpenAI Arguments
|
|
100
101
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
101
102
|
model: Union[str, openai_types.ChatModel, openai.NotGiven] = openai.NOT_GIVEN,
|
|
@@ -162,6 +163,8 @@ class AsyncCompletions:
|
|
|
162
163
|
timeout = maitai_config.timeout
|
|
163
164
|
if stream_options == openai.NOT_GIVEN and stream:
|
|
164
165
|
stream_options = ChatCompletionStreamOptionsParam(include_usage=True)
|
|
166
|
+
if context_retrieval_enabled is None:
|
|
167
|
+
context_retrieval_enabled = maitai_config.context_retrieval_enabled
|
|
165
168
|
|
|
166
169
|
completion_params = get_chat_completion_params(
|
|
167
170
|
messages=messages,
|
|
@@ -188,7 +191,8 @@ class AsyncCompletions:
|
|
|
188
191
|
response_timeout = None
|
|
189
192
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
190
193
|
response_timeout = timeout
|
|
191
|
-
response = await maitai.Inference.infer_async(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout
|
|
194
|
+
response = await maitai.Inference.infer_async(session_id, reference_id, intent, application_ref_name, completion_params, apply_corrections, evaluation_enabled, callback, timeout=response_timeout,
|
|
195
|
+
context_retrieval_enabled=context_retrieval_enabled, context_query=context_query)
|
|
192
196
|
if stream:
|
|
193
197
|
return _process_inference_stream_async(response)
|
|
194
198
|
# ChatCompletion only
|
|
@@ -275,38 +279,43 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
275
279
|
callback: Optional[EvaluateCallback] = None) -> AsyncIterable[ChatCompletionChunk]:
|
|
276
280
|
full_body = ""
|
|
277
281
|
proto_messages = openai_messages_to_proto(messages)
|
|
282
|
+
last_chunk = None
|
|
278
283
|
async for chunk in stream:
|
|
279
284
|
maitai_chunk = convert_open_ai_chat_completion_chunk(chunk)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
285
|
+
if maitai_chunk.choices:
|
|
286
|
+
last_chunk = maitai_chunk
|
|
287
|
+
content = maitai_chunk.choices[0].delta.content
|
|
288
|
+
if content is not None:
|
|
289
|
+
full_body += content
|
|
290
|
+
if maitai_chunk.usage and last_chunk is not None and not last_chunk.usage:
|
|
291
|
+
last_chunk.usage = maitai_chunk.usage
|
|
283
292
|
yield maitai_chunk
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
293
|
+
if last_chunk is None:
|
|
294
|
+
return
|
|
295
|
+
if evaluation_enabled:
|
|
296
|
+
proto_messages.append(ChatMessage(role="assistant", content=full_body))
|
|
297
|
+
await Evaluator.evaluate_async(
|
|
298
|
+
session_id=session_id,
|
|
299
|
+
reference_id=reference_id,
|
|
300
|
+
intent=intent,
|
|
301
|
+
content_type=EvaluationContentType.MESSAGE,
|
|
302
|
+
content=proto_messages,
|
|
303
|
+
application_ref_name=application_ref_name,
|
|
304
|
+
callback=callback,
|
|
305
|
+
chat_completion_chunk=last_chunk,
|
|
306
|
+
completion_params=chat_completion_params,
|
|
307
|
+
)
|
|
308
|
+
else:
|
|
309
|
+
maitai.Inference.store_chat_response(
|
|
310
|
+
session_id=session_id,
|
|
311
|
+
reference_id=reference_id,
|
|
312
|
+
intent=intent,
|
|
313
|
+
application_ref_name=application_ref_name,
|
|
314
|
+
completion_params=chat_completion_params,
|
|
315
|
+
final_chunk=last_chunk,
|
|
316
|
+
content=full_body,
|
|
317
|
+
chat_completion_response=None,
|
|
318
|
+
)
|
|
310
319
|
|
|
311
320
|
|
|
312
321
|
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[ChatCompletionChunk]:
|
|
@@ -58,6 +58,8 @@ class ChatCompletionRequest(betterproto.Message):
|
|
|
58
58
|
error: str = betterproto.string_field(14)
|
|
59
59
|
auth_keys: "_key__.KeyMap" = betterproto.message_field(15)
|
|
60
60
|
inference_location: str = betterproto.string_field(16)
|
|
61
|
+
context_retrieval_enabled: bool = betterproto.bool_field(17)
|
|
62
|
+
context_query: str = betterproto.string_field(18)
|
|
61
63
|
|
|
62
64
|
|
|
63
65
|
@dataclass(eq=False, repr=False)
|
|
@@ -35,6 +35,7 @@ class Config(betterproto.Message):
|
|
|
35
35
|
presence_penalty: float = betterproto.double_field(15)
|
|
36
36
|
frequency_penalty: float = betterproto.double_field(16)
|
|
37
37
|
timeout: float = betterproto.double_field(17)
|
|
38
|
+
context_retrieval_enabled: bool = betterproto.bool_field(18)
|
|
38
39
|
|
|
39
40
|
|
|
40
41
|
@dataclass(eq=False, repr=False)
|
|
@@ -42,12 +42,3 @@ class Session(betterproto.Message):
|
|
|
42
42
|
)
|
|
43
43
|
timeline: List["_chat__.Turn"] = betterproto.message_field(13)
|
|
44
44
|
cost: int = betterproto.int64_field(14)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@dataclass(eq=False, repr=False)
|
|
48
|
-
class SessionContext(betterproto.Message):
|
|
49
|
-
id: int = betterproto.int64_field(1)
|
|
50
|
-
application_id: int = betterproto.int64_field(2)
|
|
51
|
-
session_id: int = betterproto.int64_field(3)
|
|
52
|
-
date_created: int = betterproto.int64_field(4)
|
|
53
|
-
context_body: str = betterproto.string_field(5)
|
|
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.29 → maitai_python-1.0.30}/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
|