maitai-python 1.0.5__tar.gz → 1.0.7__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.5 → maitai_python-1.0.7}/PKG-INFO +1 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/__init__.py +0 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_config.py +6 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_evaluator.py +20 -5
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_inference.py +35 -17
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_maitai_client.py +14 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_openai.py +66 -38
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_openai_async.py +63 -37
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_utils.py +9 -29
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/config/config_service.py +13 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/processes/io_thread.py +2 -1
- maitai_python-1.0.5/maitai/_types.py → maitai_python-1.0.7/maitai_common/utils/types.py +9 -8
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/chat/__init__.py +17 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/session/__init__.py +16 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_python.egg-info/SOURCES.txt +1 -2
- {maitai_python-1.0.5 → maitai_python-1.0.7}/setup.py +1 -1
- maitai_python-1.0.5/maitai_common/processes/stream_evaluation_thread.py +0 -23
- {maitai_python-1.0.5 → maitai_python-1.0.7}/README.md +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_azure.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai/_openai_types.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.5 → maitai_python-1.0.7}/setup.cfg +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
|
-
import maitai._types as types
|
|
4
3
|
from maitai._azure import MaitaiAsyncAzureOpenAIClient as AsyncAzureOpenAI, MaitaiAzureOpenAIClient as AzureOpenAI
|
|
5
4
|
from maitai._evaluator import Evaluator as Evaluator
|
|
6
5
|
from maitai._inference import Inference as Inference
|
|
@@ -19,11 +19,15 @@ class Config:
|
|
|
19
19
|
self.websocket_listener_thread = None
|
|
20
20
|
self.config_listener_thread = None
|
|
21
21
|
self._application_action_configs: dict[str, dict[str, ActionConfig]] = {}
|
|
22
|
+
self.initialized = False
|
|
22
23
|
|
|
23
24
|
@property
|
|
24
25
|
def api_key(self):
|
|
25
26
|
if self._api_key is None:
|
|
26
|
-
|
|
27
|
+
if self.initialized:
|
|
28
|
+
raise ValueError("Maitai API Key has not been set")
|
|
29
|
+
else:
|
|
30
|
+
self.initialize(api_key=os.environ.get("MAITAI_API_KEY"))
|
|
27
31
|
return self._api_key
|
|
28
32
|
|
|
29
33
|
@api_key.setter
|
|
@@ -35,6 +39,7 @@ class Config:
|
|
|
35
39
|
self._initialize_company()
|
|
36
40
|
self.refresh_applications()
|
|
37
41
|
self._initialize_websocket()
|
|
42
|
+
self.initialized = True
|
|
38
43
|
|
|
39
44
|
def get_application(self, application_ref_name: str) -> Application:
|
|
40
45
|
return self._applications.get(application_ref_name)
|
|
@@ -8,8 +8,9 @@ from betterproto import Casing
|
|
|
8
8
|
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._maitai_client import MaitaiClient
|
|
11
|
-
from maitai.
|
|
12
|
-
from
|
|
11
|
+
from maitai._utils import chat_completion_chunk_to_response
|
|
12
|
+
from maitai_common.utils.types import EvaluateCallback
|
|
13
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompletionResponse, EvaluateRequest, EvaluateResponse, EvaluationContentType
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def _get_content_type(content, partial=None):
|
|
@@ -27,7 +28,8 @@ class Evaluator(MaitaiClient):
|
|
|
27
28
|
super().__init__()
|
|
28
29
|
|
|
29
30
|
@classmethod
|
|
30
|
-
async def evaluate_async(cls, session_id, reference_id, action_type, content, content_type=None, application_id=None, application_ref_name=None, callback=None
|
|
31
|
+
async def evaluate_async(cls, session_id, reference_id, action_type, content, content_type=None, application_id=None, application_ref_name=None, callback=None, completion_params: ChatCompletionParams = None,
|
|
32
|
+
chat_completion_response: ChatCompletionResponse = None, chat_completion_chunk: ChatCompletionChunk = None):
|
|
31
33
|
if content_type is None:
|
|
32
34
|
content_type = _get_content_type(content)
|
|
33
35
|
if content_type is None:
|
|
@@ -35,10 +37,17 @@ class Evaluator(MaitaiClient):
|
|
|
35
37
|
if application_id is None and application_ref_name is None:
|
|
36
38
|
raise Exception('application_id or application_ref_name must be provided')
|
|
37
39
|
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id, action_type, content_type, content)
|
|
40
|
+
if completion_params is not None:
|
|
41
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, action_type, False, True, completion_params)
|
|
42
|
+
if chat_completion_chunk is not None:
|
|
43
|
+
chat_completion_response = chat_completion_chunk_to_response(chat_completion_chunk, content)
|
|
44
|
+
eval_request.chat_completion_response = chat_completion_response
|
|
45
|
+
|
|
38
46
|
await asyncio.create_task(cls.send_evaluation_request_async(eval_request, callback))
|
|
39
47
|
|
|
40
48
|
@classmethod
|
|
41
|
-
def evaluate(cls, session_id, reference_id, action_type, content, content_type=None, application_id=None, application_ref_name=None, callback=None, partial=None
|
|
49
|
+
def evaluate(cls, session_id, reference_id, action_type, content, content_type=None, application_id=None, application_ref_name=None, callback=None, partial=None, completion_params: ChatCompletionParams = None,
|
|
50
|
+
chat_completion_response: ChatCompletionResponse = None, chat_completion_chunk: ChatCompletionChunk = None):
|
|
42
51
|
if content_type is None:
|
|
43
52
|
content_type = _get_content_type(content, partial)
|
|
44
53
|
if content_type is None:
|
|
@@ -46,6 +55,12 @@ class Evaluator(MaitaiClient):
|
|
|
46
55
|
if application_id is None and application_ref_name is None:
|
|
47
56
|
raise Exception('application_id or application_ref_name must be provided')
|
|
48
57
|
eval_request: EvaluateRequest = cls.create_eval_request(application_id, application_ref_name, session_id, reference_id, action_type, content_type, content, partial=partial)
|
|
58
|
+
if completion_params is not None:
|
|
59
|
+
eval_request.chat_completion_request = cls.create_inference_request(application_ref_name, session_id, reference_id, action_type, False, True, completion_params)
|
|
60
|
+
if chat_completion_chunk is not None:
|
|
61
|
+
chat_completion_response = chat_completion_chunk_to_response(chat_completion_chunk, content)
|
|
62
|
+
eval_request.chat_completion_response = chat_completion_response
|
|
63
|
+
|
|
49
64
|
cls.run_async(cls.send_evaluation_request_async(eval_request, callback))
|
|
50
65
|
|
|
51
66
|
@classmethod
|
|
@@ -57,7 +72,7 @@ class Evaluator(MaitaiClient):
|
|
|
57
72
|
|
|
58
73
|
@classmethod
|
|
59
74
|
def create_eval_request(cls, application_id, application_ref_name, session_id, reference_id, action_type,
|
|
60
|
-
content_type, content, partial=None, fault_description=None):
|
|
75
|
+
content_type, content, partial=None, fault_description=None, chat_completion_response=None):
|
|
61
76
|
eval_request: EvaluateRequest = EvaluateRequest()
|
|
62
77
|
eval_request.evaluation_content_type = content_type
|
|
63
78
|
if content_type == EvaluationContentType.TEXT:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import traceback
|
|
2
|
-
from typing import AsyncIterable, Iterable
|
|
2
|
+
from typing import AsyncIterable, Iterable, Optional
|
|
3
3
|
|
|
4
4
|
import aiohttp
|
|
5
5
|
import requests
|
|
@@ -7,8 +7,9 @@ from betterproto import Casing
|
|
|
7
7
|
|
|
8
8
|
from maitai._config import config
|
|
9
9
|
from maitai._maitai_client import MaitaiClient
|
|
10
|
-
from maitai.
|
|
11
|
-
from
|
|
10
|
+
from maitai._utils import chat_completion_chunk_to_response
|
|
11
|
+
from maitai_common.utils.types import AsyncChunkQueue, ChunkQueue, EvaluateCallback, QueueIterable
|
|
12
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompletionRequest, ChatCompletionResponse, ChatStorageRequest
|
|
12
13
|
from maitai_gen.inference import InferenceStreamResponse
|
|
13
14
|
|
|
14
15
|
|
|
@@ -38,16 +39,19 @@ class Inference(MaitaiClient):
|
|
|
38
39
|
return QueueIterable(q, timeout=timeout)
|
|
39
40
|
|
|
40
41
|
@classmethod
|
|
41
|
-
def
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
def create_chat_storage_request(cls, session_id, reference_id, action_type, application_ref_name, completion_params: ChatCompletionParams, chat_completion_response: Optional[ChatCompletionResponse],
|
|
43
|
+
final_chunk: Optional[ChatCompletionChunk], content: str):
|
|
44
|
+
inference_request = cls.create_inference_request(application_ref_name, session_id, reference_id, action_type, False, False, completion_params)
|
|
45
|
+
if final_chunk:
|
|
46
|
+
chat_completion_response = chat_completion_chunk_to_response(final_chunk, content)
|
|
47
|
+
|
|
48
|
+
return ChatStorageRequest(chat_completion_request=inference_request, chat_completion_response=chat_completion_response)
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def store_chat_response(cls, session_id, reference_id, action_type, application_ref_name, completion_params: ChatCompletionParams, chat_completion_response: Optional[ChatCompletionResponse],
|
|
52
|
+
final_chunk: Optional[ChatCompletionChunk], content: str):
|
|
53
|
+
chat_storage_request = cls.create_chat_storage_request(session_id, reference_id, action_type, application_ref_name, completion_params, chat_completion_response, final_chunk, content)
|
|
54
|
+
cls.run_async(cls.send_storage_request_async(chat_storage_request))
|
|
51
55
|
|
|
52
56
|
@classmethod
|
|
53
57
|
def send_inference_request(cls, chat_request: ChatCompletionRequest) -> Iterable[InferenceStreamResponse]:
|
|
@@ -89,9 +93,9 @@ class Inference(MaitaiClient):
|
|
|
89
93
|
error_text = await response.text()
|
|
90
94
|
print(f"Failed to send evaluation request. Status code: {response.status}. Error: {error_text}")
|
|
91
95
|
if chunk_queue:
|
|
92
|
-
chunk_queue.put(
|
|
96
|
+
chunk_queue.put(StopIteration())
|
|
93
97
|
if async_chunk_queue:
|
|
94
|
-
await async_chunk_queue.put(
|
|
98
|
+
await async_chunk_queue.put(StopIteration())
|
|
95
99
|
return
|
|
96
100
|
async for line in response.content:
|
|
97
101
|
if line:
|
|
@@ -106,6 +110,20 @@ class Inference(MaitaiClient):
|
|
|
106
110
|
except:
|
|
107
111
|
traceback.print_exc()
|
|
108
112
|
if chunk_queue:
|
|
109
|
-
chunk_queue.put(
|
|
113
|
+
chunk_queue.put(StopIteration())
|
|
110
114
|
if async_chunk_queue:
|
|
111
|
-
await async_chunk_queue.put(
|
|
115
|
+
await async_chunk_queue.put(StopIteration())
|
|
116
|
+
|
|
117
|
+
@classmethod
|
|
118
|
+
async def send_storage_request_async(cls, chat_storage_request: ChatStorageRequest):
|
|
119
|
+
host = config.maitai_host
|
|
120
|
+
url = f'{host}/chat/completions/response'
|
|
121
|
+
headers = {
|
|
122
|
+
'Content-Type': 'application/json',
|
|
123
|
+
'x-api-key': config.api_key
|
|
124
|
+
}
|
|
125
|
+
try:
|
|
126
|
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
|
|
127
|
+
return await session.put(url, headers=headers, data=chat_storage_request.to_json(casing=Casing.SNAKE))
|
|
128
|
+
except:
|
|
129
|
+
traceback.print_exc()
|
|
@@ -2,6 +2,8 @@ import asyncio
|
|
|
2
2
|
import os
|
|
3
3
|
import threading
|
|
4
4
|
|
|
5
|
+
from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
class MaitaiClient:
|
|
7
9
|
MAITAI_HOST = os.environ.get("MAITAI_HOST", 'https://api.trymaitai.ai')
|
|
@@ -32,3 +34,15 @@ class MaitaiClient:
|
|
|
32
34
|
new_loop.close()
|
|
33
35
|
|
|
34
36
|
threading.Thread(target=run).start()
|
|
37
|
+
|
|
38
|
+
@classmethod
|
|
39
|
+
def create_inference_request(cls, application_ref_name, session_id, reference_id, action_type, apply_corrections, evaluation_enabled, completion_params: ChatCompletionParams):
|
|
40
|
+
infer_request: ChatCompletionRequest = ChatCompletionRequest()
|
|
41
|
+
infer_request.application_ref_name = application_ref_name
|
|
42
|
+
infer_request.reference_id = reference_id
|
|
43
|
+
infer_request.session_id = session_id
|
|
44
|
+
infer_request.action_type = action_type
|
|
45
|
+
infer_request.apply_corrections = apply_corrections
|
|
46
|
+
infer_request.params = completion_params
|
|
47
|
+
infer_request.evaluation_enabled = evaluation_enabled
|
|
48
|
+
return infer_request
|
|
@@ -9,10 +9,10 @@ import maitai
|
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._evaluator import Evaluator
|
|
11
11
|
from maitai._openai_types import Body, Headers, Query
|
|
12
|
-
from maitai._types import EvaluateCallback
|
|
13
12
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
14
13
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
15
|
-
from
|
|
14
|
+
from maitai_common.utils.types import EvaluateCallback
|
|
15
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompletionResponse, ChatMessage, EvaluationContentType
|
|
16
16
|
from maitai_gen.config import InferenceLocations
|
|
17
17
|
from maitai_gen.inference import InferenceStreamResponse
|
|
18
18
|
|
|
@@ -118,11 +118,11 @@ class Completions:
|
|
|
118
118
|
evaluation_enabled = maitai_config.evaluation_enabled
|
|
119
119
|
if apply_corrections is None:
|
|
120
120
|
apply_corrections = maitai_config.apply_corrections
|
|
121
|
-
if model
|
|
121
|
+
if model == openai.NOT_GIVEN:
|
|
122
122
|
model = maitai_config.model
|
|
123
123
|
if temperature == openai.NOT_GIVEN:
|
|
124
124
|
temperature = maitai_config.temperature
|
|
125
|
-
if stream
|
|
125
|
+
if stream == openai.NOT_GIVEN:
|
|
126
126
|
stream = maitai_config.streaming
|
|
127
127
|
if response_format == openai.NOT_GIVEN:
|
|
128
128
|
response_format = {"type": maitai_config.response_format}
|
|
@@ -134,28 +134,28 @@ class Completions:
|
|
|
134
134
|
max_tokens = maitai_config.max_tokens
|
|
135
135
|
if n == openai.NOT_GIVEN:
|
|
136
136
|
n = maitai_config.n
|
|
137
|
+
completion_params = get_chat_completion_params(
|
|
138
|
+
messages=messages,
|
|
139
|
+
model=model,
|
|
140
|
+
frequency_penalty=frequency_penalty,
|
|
141
|
+
logit_bias=logit_bias,
|
|
142
|
+
logprobs=logprobs,
|
|
143
|
+
max_tokens=max_tokens,
|
|
144
|
+
n=n,
|
|
145
|
+
presence_penalty=presence_penalty,
|
|
146
|
+
response_format=response_format,
|
|
147
|
+
seed=seed,
|
|
148
|
+
stop=stop,
|
|
149
|
+
stream=stream,
|
|
150
|
+
stream_options=stream_options,
|
|
151
|
+
temperature=temperature,
|
|
152
|
+
tool_choice=tool_choice,
|
|
153
|
+
tools=tools,
|
|
154
|
+
top_logprobs=top_logprobs,
|
|
155
|
+
top_p=top_p,
|
|
156
|
+
user=user,
|
|
157
|
+
)
|
|
137
158
|
if server_side_inference:
|
|
138
|
-
completion_params = get_chat_completion_params(
|
|
139
|
-
messages=messages,
|
|
140
|
-
model=model,
|
|
141
|
-
frequency_penalty=frequency_penalty,
|
|
142
|
-
logit_bias=logit_bias,
|
|
143
|
-
logprobs=logprobs,
|
|
144
|
-
max_tokens=max_tokens,
|
|
145
|
-
n=n,
|
|
146
|
-
presence_penalty=presence_penalty,
|
|
147
|
-
response_format=response_format,
|
|
148
|
-
seed=seed,
|
|
149
|
-
stop=stop,
|
|
150
|
-
stream=stream,
|
|
151
|
-
stream_options=stream_options,
|
|
152
|
-
temperature=temperature,
|
|
153
|
-
tool_choice=tool_choice,
|
|
154
|
-
tools=tools,
|
|
155
|
-
top_logprobs=top_logprobs,
|
|
156
|
-
top_p=top_p,
|
|
157
|
-
user=user,
|
|
158
|
-
)
|
|
159
159
|
response_timeout = None
|
|
160
160
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
161
161
|
response_timeout = timeout
|
|
@@ -197,7 +197,7 @@ class Completions:
|
|
|
197
197
|
|
|
198
198
|
)
|
|
199
199
|
if stream:
|
|
200
|
-
return _process_openai_stream(session_id, reference_id, action_type, application_ref_name, messages, response, evaluation_enabled, callback)
|
|
200
|
+
return _process_openai_stream(session_id, reference_id, action_type, application_ref_name, messages, response, evaluation_enabled, completion_params, callback)
|
|
201
201
|
else:
|
|
202
202
|
maitai_completion = convert_openai_chat_completion(response)
|
|
203
203
|
proto_messages = openai_messages_to_proto(messages)
|
|
@@ -212,6 +212,19 @@ class Completions:
|
|
|
212
212
|
content=proto_messages,
|
|
213
213
|
application_ref_name=application_ref_name,
|
|
214
214
|
callback=callback,
|
|
215
|
+
chat_completion_response=maitai_completion,
|
|
216
|
+
completion_params=completion_params,
|
|
217
|
+
)
|
|
218
|
+
else:
|
|
219
|
+
maitai.Inference.store_chat_response(
|
|
220
|
+
session_id=session_id,
|
|
221
|
+
reference_id=reference_id,
|
|
222
|
+
action_type=action_type,
|
|
223
|
+
application_ref_name=application_ref_name,
|
|
224
|
+
chat_completion_response=maitai_completion,
|
|
225
|
+
completion_params=completion_params,
|
|
226
|
+
final_chunk=None,
|
|
227
|
+
content=""
|
|
215
228
|
)
|
|
216
229
|
return maitai_completion
|
|
217
230
|
|
|
@@ -223,7 +236,8 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
223
236
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
224
237
|
stream: openai.Stream[openai_chat_types.ChatCompletionChunk],
|
|
225
238
|
evaluation_enabled: bool,
|
|
226
|
-
|
|
239
|
+
chat_completion_params: ChatCompletionParams,
|
|
240
|
+
callback: Optional[EvaluateCallback] = None, ) -> Iterable[ChatCompletionChunk]:
|
|
227
241
|
full_body = ""
|
|
228
242
|
proto_messages = openai_messages_to_proto(messages)
|
|
229
243
|
for chunk in stream:
|
|
@@ -232,17 +246,31 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
232
246
|
if content is not None:
|
|
233
247
|
full_body += content
|
|
234
248
|
yield maitai_chunk
|
|
235
|
-
if maitai_chunk.choices[0].finish_reason
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
249
|
+
if maitai_chunk.choices[0].finish_reason:
|
|
250
|
+
if evaluation_enabled:
|
|
251
|
+
proto_messages.append(ChatMessage(role="assistant", content=full_body))
|
|
252
|
+
Evaluator.evaluate(
|
|
253
|
+
session_id=session_id,
|
|
254
|
+
reference_id=reference_id,
|
|
255
|
+
action_type=action_type,
|
|
256
|
+
content_type=EvaluationContentType.MESSAGE,
|
|
257
|
+
content=proto_messages,
|
|
258
|
+
application_ref_name=application_ref_name,
|
|
259
|
+
callback=callback,
|
|
260
|
+
chat_completion_chunk=maitai_chunk,
|
|
261
|
+
completion_params=chat_completion_params,
|
|
262
|
+
)
|
|
263
|
+
else:
|
|
264
|
+
maitai.Inference.store_chat_response(
|
|
265
|
+
session_id=session_id,
|
|
266
|
+
reference_id=reference_id,
|
|
267
|
+
action_type=action_type,
|
|
268
|
+
application_ref_name=application_ref_name,
|
|
269
|
+
completion_params=chat_completion_params,
|
|
270
|
+
final_chunk=maitai_chunk,
|
|
271
|
+
content=full_body,
|
|
272
|
+
chat_completion_response=None,
|
|
273
|
+
)
|
|
246
274
|
return
|
|
247
275
|
|
|
248
276
|
|
|
@@ -9,10 +9,10 @@ import maitai
|
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._evaluator import Evaluator
|
|
11
11
|
from maitai._openai_types import Body, Headers, Query
|
|
12
|
-
from maitai._types import EvaluateCallback
|
|
13
12
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
14
13
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
15
|
-
from
|
|
14
|
+
from maitai_common.utils.types import EvaluateCallback
|
|
15
|
+
from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompletionResponse, ChatMessage, EvaluationContentType
|
|
16
16
|
from maitai_gen.config import InferenceLocations
|
|
17
17
|
from maitai_gen.inference import InferenceStreamResponse
|
|
18
18
|
|
|
@@ -121,11 +121,11 @@ class AsyncCompletions:
|
|
|
121
121
|
evaluation_enabled = maitai_config.evaluation_enabled
|
|
122
122
|
if apply_corrections is None:
|
|
123
123
|
apply_corrections = maitai_config.apply_corrections
|
|
124
|
-
if model
|
|
124
|
+
if model == openai.NOT_GIVEN:
|
|
125
125
|
model = maitai_config.model
|
|
126
126
|
if temperature == openai.NOT_GIVEN:
|
|
127
127
|
temperature = maitai_config.temperature
|
|
128
|
-
if stream
|
|
128
|
+
if stream == openai.NOT_GIVEN:
|
|
129
129
|
stream = maitai_config.streaming
|
|
130
130
|
if response_format == openai.NOT_GIVEN:
|
|
131
131
|
response_format = {"type": maitai_config.response_format}
|
|
@@ -138,28 +138,28 @@ class AsyncCompletions:
|
|
|
138
138
|
if n == openai.NOT_GIVEN:
|
|
139
139
|
n = maitai_config.n
|
|
140
140
|
|
|
141
|
+
completion_params = get_chat_completion_params(
|
|
142
|
+
messages=messages,
|
|
143
|
+
model=model,
|
|
144
|
+
frequency_penalty=frequency_penalty,
|
|
145
|
+
logit_bias=logit_bias,
|
|
146
|
+
logprobs=logprobs,
|
|
147
|
+
max_tokens=max_tokens,
|
|
148
|
+
n=n,
|
|
149
|
+
presence_penalty=presence_penalty,
|
|
150
|
+
response_format=response_format,
|
|
151
|
+
seed=seed,
|
|
152
|
+
stop=stop,
|
|
153
|
+
stream=stream,
|
|
154
|
+
stream_options=stream_options,
|
|
155
|
+
temperature=temperature,
|
|
156
|
+
tool_choice=tool_choice,
|
|
157
|
+
tools=tools,
|
|
158
|
+
top_logprobs=top_logprobs,
|
|
159
|
+
top_p=top_p,
|
|
160
|
+
user=user,
|
|
161
|
+
)
|
|
141
162
|
if server_side_inference:
|
|
142
|
-
completion_params = get_chat_completion_params(
|
|
143
|
-
messages=messages,
|
|
144
|
-
model=model,
|
|
145
|
-
frequency_penalty=frequency_penalty,
|
|
146
|
-
logit_bias=logit_bias,
|
|
147
|
-
logprobs=logprobs,
|
|
148
|
-
max_tokens=max_tokens,
|
|
149
|
-
n=n,
|
|
150
|
-
presence_penalty=presence_penalty,
|
|
151
|
-
response_format=response_format,
|
|
152
|
-
seed=seed,
|
|
153
|
-
stop=stop,
|
|
154
|
-
stream=stream,
|
|
155
|
-
stream_options=stream_options,
|
|
156
|
-
temperature=temperature,
|
|
157
|
-
tool_choice=tool_choice,
|
|
158
|
-
tools=tools,
|
|
159
|
-
top_logprobs=top_logprobs,
|
|
160
|
-
top_p=top_p,
|
|
161
|
-
user=user,
|
|
162
|
-
)
|
|
163
163
|
response_timeout = None
|
|
164
164
|
if isinstance(timeout, float) or isinstance(timeout, int):
|
|
165
165
|
response_timeout = timeout
|
|
@@ -201,7 +201,7 @@ class AsyncCompletions:
|
|
|
201
201
|
|
|
202
202
|
)
|
|
203
203
|
if stream:
|
|
204
|
-
return _process_async_openai_stream(session_id, reference_id, action_type, application_ref_name, messages, response, evaluation_enabled, callback)
|
|
204
|
+
return _process_async_openai_stream(session_id, reference_id, action_type, application_ref_name, messages, response, evaluation_enabled, completion_params, callback)
|
|
205
205
|
else:
|
|
206
206
|
maitai_completion = convert_openai_chat_completion(response)
|
|
207
207
|
proto_messages = openai_messages_to_proto(messages)
|
|
@@ -216,6 +216,19 @@ class AsyncCompletions:
|
|
|
216
216
|
content=proto_messages,
|
|
217
217
|
application_ref_name=application_ref_name,
|
|
218
218
|
callback=callback,
|
|
219
|
+
chat_completion_response=maitai_completion,
|
|
220
|
+
completion_params=completion_params,
|
|
221
|
+
)
|
|
222
|
+
else:
|
|
223
|
+
maitai.Inference.store_chat_response(
|
|
224
|
+
session_id=session_id,
|
|
225
|
+
reference_id=reference_id,
|
|
226
|
+
action_type=action_type,
|
|
227
|
+
application_ref_name=application_ref_name,
|
|
228
|
+
chat_completion_response=maitai_completion,
|
|
229
|
+
completion_params=completion_params,
|
|
230
|
+
final_chunk=None,
|
|
231
|
+
content=""
|
|
219
232
|
)
|
|
220
233
|
return maitai_completion
|
|
221
234
|
|
|
@@ -227,6 +240,7 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
227
240
|
messages: Iterable[openai_chat_types.ChatCompletionMessageParam],
|
|
228
241
|
stream: openai.AsyncStream[openai_chat_types.ChatCompletionChunk],
|
|
229
242
|
evaluation_enabled: bool,
|
|
243
|
+
chat_completion_params: ChatCompletionParams,
|
|
230
244
|
callback: Optional[EvaluateCallback] = None) -> AsyncIterable[ChatCompletionChunk]:
|
|
231
245
|
full_body = ""
|
|
232
246
|
proto_messages = openai_messages_to_proto(messages)
|
|
@@ -236,17 +250,29 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
236
250
|
if content is not None:
|
|
237
251
|
full_body += content
|
|
238
252
|
yield maitai_chunk
|
|
239
|
-
if maitai_chunk.choices[0].finish_reason
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
253
|
+
if maitai_chunk.choices[0].finish_reason:
|
|
254
|
+
if evaluation_enabled:
|
|
255
|
+
proto_messages.append(ChatMessage(role="assistant", content=full_body))
|
|
256
|
+
await Evaluator.evaluate_async(
|
|
257
|
+
session_id=session_id,
|
|
258
|
+
reference_id=reference_id,
|
|
259
|
+
action_type=action_type,
|
|
260
|
+
content_type=EvaluationContentType.MESSAGE,
|
|
261
|
+
content=proto_messages,
|
|
262
|
+
application_ref_name=application_ref_name,
|
|
263
|
+
callback=callback
|
|
264
|
+
)
|
|
265
|
+
else:
|
|
266
|
+
maitai.Inference.store_chat_response(
|
|
267
|
+
session_id=session_id,
|
|
268
|
+
reference_id=reference_id,
|
|
269
|
+
action_type=action_type,
|
|
270
|
+
application_ref_name=application_ref_name,
|
|
271
|
+
completion_params=chat_completion_params,
|
|
272
|
+
final_chunk=maitai_chunk,
|
|
273
|
+
content=full_body,
|
|
274
|
+
chat_completion_response=None,
|
|
275
|
+
)
|
|
250
276
|
return
|
|
251
277
|
|
|
252
278
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import functools
|
|
2
2
|
import inspect
|
|
3
|
-
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence,
|
|
3
|
+
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, TypeVar, Union
|
|
4
4
|
|
|
5
5
|
import openai
|
|
6
6
|
import openai.types.chat as openai_types
|
|
7
|
+
from betterproto import Casing
|
|
7
8
|
from openai.types import ChatModel
|
|
8
9
|
|
|
9
10
|
import maitai_gen.chat as chat_types
|
|
10
|
-
from maitai._evaluator import Evaluator
|
|
11
|
-
from maitai._types import EvaluateCallback
|
|
12
11
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
13
12
|
from maitai_gen.chat import ChatCompletionParams, Function, ResponseFormat, StreamOptions, Tool
|
|
14
13
|
|
|
@@ -174,29 +173,10 @@ def get_chat_completion_params(*,
|
|
|
174
173
|
return params
|
|
175
174
|
|
|
176
175
|
|
|
177
|
-
def
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
callback: Optional[EvaluateCallback]) -> Tuple[str, Optional[chat_types.ChatCompletionChunk]]:
|
|
185
|
-
content = maitai_chunk.choices[0].delta.content
|
|
186
|
-
if content is not None:
|
|
187
|
-
full_body += content
|
|
188
|
-
if maitai_chunk.choices[0].finish_reason:
|
|
189
|
-
proto_messages.append(chat_types.ChatMessage(role="assistant", content=full_body))
|
|
190
|
-
maitai_eval = Evaluator.evaluate(
|
|
191
|
-
session_id=session_id,
|
|
192
|
-
reference_id=reference_id,
|
|
193
|
-
action_type=action_type,
|
|
194
|
-
content_type=chat_types.EvaluationContentType.MESSAGE,
|
|
195
|
-
content=proto_messages,
|
|
196
|
-
application_ref_name=application_ref_name,
|
|
197
|
-
callback=callback
|
|
198
|
-
)
|
|
199
|
-
if not callback:
|
|
200
|
-
maitai_chunk.evaluate_response = maitai_eval
|
|
201
|
-
return full_body, maitai_chunk
|
|
202
|
-
return full_body, None
|
|
176
|
+
def chat_completion_chunk_to_response(final_chunk: chat_types.ChatCompletionChunk, content: Union[str, List[chat_types.ChatMessage]]):
|
|
177
|
+
chat_completion_response = chat_types.ChatCompletionResponse().from_dict(final_chunk.to_dict(casing=Casing.SNAKE))
|
|
178
|
+
if isinstance(content, str):
|
|
179
|
+
chat_completion_response.choices[0].message = chat_types.ChatMessage(role='assistant', content=content)
|
|
180
|
+
if isinstance(content, List):
|
|
181
|
+
chat_completion_response.choices[0].message = content[-1]
|
|
182
|
+
return chat_completion_response
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
from maitai_gen.config import Config, InferenceLocations
|
|
2
2
|
|
|
3
3
|
# TODO consider finding a source of truth where we don't need to deploy everytime a new model comes out
|
|
4
|
+
SERVER_PROVIDERS = ["groq", "openai"]
|
|
5
|
+
CLIENT_PROVIDERS = ["openai"]
|
|
6
|
+
|
|
4
7
|
MODELS = {
|
|
5
8
|
"llama3-70b-8192": "groq",
|
|
9
|
+
"llama3-8b-8192": "groq",
|
|
6
10
|
"gpt-4o": "openai",
|
|
7
11
|
"gpt-4o-2024-05-13": "openai",
|
|
8
12
|
"gpt-4-turbo": "openai",
|
|
@@ -47,5 +51,13 @@ def get_model_provider(model_name: str):
|
|
|
47
51
|
return MODELS[model_name]
|
|
48
52
|
|
|
49
53
|
|
|
54
|
+
def get_models(providers):
|
|
55
|
+
models = []
|
|
56
|
+
for model_name, provider in MODELS.items():
|
|
57
|
+
if provider in providers:
|
|
58
|
+
models.append(model_name)
|
|
59
|
+
return models
|
|
60
|
+
|
|
61
|
+
|
|
50
62
|
def get_available_models():
|
|
51
|
-
return {"
|
|
63
|
+
return {"all_models": list(MODELS.keys()), "client_models": get_models(CLIENT_PROVIDERS), "server_models": get_models(SERVER_PROVIDERS)}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import threading
|
|
2
2
|
import time
|
|
3
|
+
import traceback
|
|
3
4
|
from threading import Thread
|
|
4
5
|
|
|
5
6
|
|
|
@@ -32,7 +33,7 @@ class IOThread(Thread):
|
|
|
32
33
|
try:
|
|
33
34
|
self.process()
|
|
34
35
|
except Exception as e:
|
|
35
|
-
self.print(e, f'[{self.child_name}] Exception hit processing')
|
|
36
|
+
self.print(e, f'[{self.child_name}] Exception hit processing', traceback.format_exc())
|
|
36
37
|
finally:
|
|
37
38
|
self.is_running = False
|
|
38
39
|
|
|
@@ -5,14 +5,14 @@ from typing import Callable, Union
|
|
|
5
5
|
import maitai_gen.chat as chat_types
|
|
6
6
|
from maitai_gen.chat import *
|
|
7
7
|
|
|
8
|
-
ChunkQueue = queue.Queue[Union[chat_types.ChatCompletionChunk,
|
|
9
|
-
AsyncChunkQueue = asyncio.Queue[Union[chat_types.ChatCompletionChunk,
|
|
8
|
+
ChunkQueue = queue.Queue[Union[chat_types.ChatCompletionChunk, StopIteration, Exception]]
|
|
9
|
+
AsyncChunkQueue = asyncio.Queue[Union[chat_types.ChatCompletionChunk, StopIteration, Exception]]
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class QueueIterable:
|
|
13
13
|
def __init__(self, chunk_queue: Union[ChunkQueue, AsyncChunkQueue], timeout=None) -> None:
|
|
14
14
|
self.queue = chunk_queue
|
|
15
|
-
self.done = False
|
|
15
|
+
self.done = False
|
|
16
16
|
self.timeout = timeout
|
|
17
17
|
|
|
18
18
|
def __aiter__(self):
|
|
@@ -24,14 +24,15 @@ class QueueIterable:
|
|
|
24
24
|
return self
|
|
25
25
|
|
|
26
26
|
def __next__(self) -> chat_types.ChatCompletionChunk:
|
|
27
|
-
"""Waits for the next item from the queue or raises StopIteration if "done"."""
|
|
28
27
|
while not self.done:
|
|
29
28
|
try:
|
|
30
29
|
# Wait for an item from the queue, block if necessary
|
|
31
30
|
item = self.queue.get(timeout=self.timeout) # Wait for 10 seconds, adjust as needed
|
|
32
|
-
if item
|
|
31
|
+
if isinstance(item, StopIteration):
|
|
33
32
|
self.done = True # Set done to True to prevent further blocking
|
|
34
33
|
raise StopIteration
|
|
34
|
+
elif isinstance(item, Exception):
|
|
35
|
+
raise item
|
|
35
36
|
return item
|
|
36
37
|
except queue.Empty:
|
|
37
38
|
print("Queue timed out")
|
|
@@ -40,7 +41,6 @@ class QueueIterable:
|
|
|
40
41
|
raise StopIteration
|
|
41
42
|
|
|
42
43
|
async def __anext__(self) -> chat_types.ChatCompletionChunk:
|
|
43
|
-
"""Waits for the next item from the queue or raises StopAsyncIteration if "done"."""
|
|
44
44
|
if self.done:
|
|
45
45
|
raise StopAsyncIteration
|
|
46
46
|
|
|
@@ -51,10 +51,11 @@ class QueueIterable:
|
|
|
51
51
|
else:
|
|
52
52
|
item = await self.queue.get()
|
|
53
53
|
|
|
54
|
-
if item
|
|
54
|
+
if isinstance(item, StopIteration):
|
|
55
55
|
self.done = True # Set done to True to prevent further blocking
|
|
56
56
|
raise StopAsyncIteration
|
|
57
|
-
|
|
57
|
+
elif isinstance(item, Exception):
|
|
58
|
+
raise item
|
|
58
59
|
return item
|
|
59
60
|
|
|
60
61
|
except asyncio.TimeoutError:
|
|
@@ -189,6 +189,13 @@ class LogPropsContent(betterproto.Message):
|
|
|
189
189
|
top_logprobs: List["LogProbs"] = betterproto.message_field(4)
|
|
190
190
|
|
|
191
191
|
|
|
192
|
+
@dataclass(eq=False, repr=False)
|
|
193
|
+
class ChatStorageRequest(betterproto.Message):
|
|
194
|
+
chat_completion_request: "ChatCompletionRequest" = betterproto.message_field(1)
|
|
195
|
+
chat_completion_response: "ChatCompletionResponse" = betterproto.message_field(2)
|
|
196
|
+
evaluate_request: "EvaluateRequest" = betterproto.message_field(3)
|
|
197
|
+
|
|
198
|
+
|
|
192
199
|
@dataclass(eq=False, repr=False)
|
|
193
200
|
class EvaluateRequest(betterproto.Message):
|
|
194
201
|
id: int = betterproto.int64_field(1)
|
|
@@ -209,6 +216,12 @@ class EvaluateRequest(betterproto.Message):
|
|
|
209
216
|
request_id: str = betterproto.string_field(14)
|
|
210
217
|
sentinel_id: int = betterproto.int64_field(15)
|
|
211
218
|
fault_description: str = betterproto.string_field(16)
|
|
219
|
+
chat_completion_request: Optional["ChatCompletionRequest"] = (
|
|
220
|
+
betterproto.message_field(17, optional=True, group="_chat_completion_request")
|
|
221
|
+
)
|
|
222
|
+
chat_completion_response: Optional["ChatCompletionResponse"] = (
|
|
223
|
+
betterproto.message_field(18, optional=True, group="_chat_completion_response")
|
|
224
|
+
)
|
|
212
225
|
|
|
213
226
|
|
|
214
227
|
@dataclass(eq=False, repr=False)
|
|
@@ -234,6 +247,10 @@ class EvaluateResponse(betterproto.Message):
|
|
|
234
247
|
request_id: int = betterproto.int64_field(5)
|
|
235
248
|
evaluation_results: List["EvaluateResult"] = betterproto.message_field(6)
|
|
236
249
|
evaluation_request_id: str = betterproto.string_field(7)
|
|
250
|
+
evaluation_request: Optional["EvaluateRequest"] = betterproto.message_field(
|
|
251
|
+
8, optional=True, group="_evaluation_request"
|
|
252
|
+
)
|
|
253
|
+
evaluate_summary: str = betterproto.string_field(9)
|
|
237
254
|
|
|
238
255
|
|
|
239
256
|
class EvaluationServiceStub(betterproto.ServiceStub):
|
|
@@ -4,19 +4,34 @@
|
|
|
4
4
|
# This file has been @generated
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import (
|
|
8
|
+
List,
|
|
9
|
+
Optional,
|
|
10
|
+
)
|
|
8
11
|
|
|
9
12
|
import betterproto
|
|
10
13
|
|
|
11
14
|
from .. import chat as _chat__
|
|
12
15
|
|
|
13
16
|
|
|
17
|
+
class SessionFeedback(betterproto.Enum):
|
|
18
|
+
PENDING = 0
|
|
19
|
+
CORRECT = 1
|
|
20
|
+
INCORRECT = 2
|
|
21
|
+
|
|
22
|
+
|
|
14
23
|
@dataclass(eq=False, repr=False)
|
|
15
24
|
class Session(betterproto.Message):
|
|
16
25
|
session_id: str = betterproto.string_field(1)
|
|
17
26
|
date_created: int = betterproto.int64_field(2)
|
|
18
27
|
application_id: int = betterproto.int64_field(3)
|
|
19
28
|
eval_requests: List["_chat__.EvaluateRequest"] = betterproto.message_field(4)
|
|
29
|
+
application_name: Optional[str] = betterproto.string_field(
|
|
30
|
+
5, optional=True, group="_application_name"
|
|
31
|
+
)
|
|
32
|
+
fully_corrected: bool = betterproto.bool_field(6)
|
|
33
|
+
summary: str = betterproto.string_field(7)
|
|
34
|
+
feedback: "SessionFeedback" = betterproto.enum_field(8)
|
|
20
35
|
|
|
21
36
|
|
|
22
37
|
@dataclass(eq=False, repr=False)
|
|
@@ -10,17 +10,16 @@ maitai/_maitai_client.py
|
|
|
10
10
|
maitai/_openai.py
|
|
11
11
|
maitai/_openai_async.py
|
|
12
12
|
maitai/_openai_types.py
|
|
13
|
-
maitai/_types.py
|
|
14
13
|
maitai/_utils.py
|
|
15
14
|
maitai_common/__init__.py
|
|
16
15
|
maitai_common/config/__init__.py
|
|
17
16
|
maitai_common/config/config_service.py
|
|
18
17
|
maitai_common/processes/__init__.py
|
|
19
18
|
maitai_common/processes/io_thread.py
|
|
20
|
-
maitai_common/processes/stream_evaluation_thread.py
|
|
21
19
|
maitai_common/processes/websocket_listener_thread.py
|
|
22
20
|
maitai_common/utils/__init__.py
|
|
23
21
|
maitai_common/utils/proto_utils.py
|
|
22
|
+
maitai_common/utils/types.py
|
|
24
23
|
maitai_gen/__init__.py
|
|
25
24
|
maitai_gen/application/__init__.py
|
|
26
25
|
maitai_gen/chat/__init__.py
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import maitai
|
|
2
|
-
from maitai_common.processes.io_thread import IOThread
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class StreamEvaluationThread(IOThread):
|
|
6
|
-
def __init__(self):
|
|
7
|
-
super(StreamEvaluationThread, self).__init__(interval=0.01)
|
|
8
|
-
self.input = []
|
|
9
|
-
self.output = []
|
|
10
|
-
|
|
11
|
-
def process(self):
|
|
12
|
-
if len(self.input) == 0:
|
|
13
|
-
return
|
|
14
|
-
input_list = self.input
|
|
15
|
-
self.input = []
|
|
16
|
-
session_id, reference_id, action_type, content_type, proto_messages, application_ref_name, partial = input_list.pop()
|
|
17
|
-
result = maitai.Evaluator.evaluate(session_id, reference_id, action_type, proto_messages, content_type=content_type, application_ref_name=application_ref_name, partial=partial)
|
|
18
|
-
if len(result.evaluation_results) > 0:
|
|
19
|
-
if result.evaluation_results[0].status == "FAULT":
|
|
20
|
-
self.output = result
|
|
21
|
-
|
|
22
|
-
def print(self, *args, **kwargs):
|
|
23
|
-
pass
|
|
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.5 → maitai_python-1.0.7}/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
|