maitai-python 1.1.41b0__tar.gz → 1.1.43__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.1.41b0 → maitai_python-1.1.43}/PKG-INFO +1 -1
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_config.py +10 -20
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_inference.py +128 -41
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/version.py +1 -1
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/annotation/__init__.py +2 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/chat/__init__.py +4 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/README.md +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_azure.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_context.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_evaluator.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_maitai.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_maitai_async.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_types.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/_utils.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/backtest/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/billing/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/metric/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/model.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/rates/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/setup.cfg +0 -0
- {maitai_python-1.1.41b0 → maitai_python-1.1.43}/setup.py +0 -0
|
@@ -126,7 +126,6 @@ class Config:
|
|
|
126
126
|
self.api_key = api_key
|
|
127
127
|
self.initialized = True
|
|
128
128
|
try:
|
|
129
|
-
self._initialize_company()
|
|
130
129
|
self.refresh_applications()
|
|
131
130
|
self._initialize_websocket()
|
|
132
131
|
self._start_refresh_timer()
|
|
@@ -138,7 +137,9 @@ class Config:
|
|
|
138
137
|
self.initialized = False
|
|
139
138
|
if retry < 5:
|
|
140
139
|
t = threading.Timer(
|
|
141
|
-
interval=2**retry,
|
|
140
|
+
interval=2**retry,
|
|
141
|
+
function=self.initialize,
|
|
142
|
+
args=(api_key, retry + 1),
|
|
142
143
|
)
|
|
143
144
|
t.daemon = True
|
|
144
145
|
t.start()
|
|
@@ -170,25 +171,9 @@ class Config:
|
|
|
170
171
|
action_type, config_service.get_default_config()
|
|
171
172
|
)
|
|
172
173
|
|
|
173
|
-
def _initialize_company(self):
|
|
174
|
-
host = self.maitai_host
|
|
175
|
-
url = f"{host}/company/"
|
|
176
|
-
headers = {
|
|
177
|
-
"Content-Type": "application/json",
|
|
178
|
-
"x-api-key": self.api_key,
|
|
179
|
-
"x-client-version": version,
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
response = self._session.get(url, headers=headers, timeout=15)
|
|
183
|
-
self._session.close()
|
|
184
|
-
if response.status_code != 200:
|
|
185
|
-
raise Exception(f"Failed to initialize Maitai client: {response.text}")
|
|
186
|
-
|
|
187
|
-
self._company_id = response.json().get("id")
|
|
188
|
-
|
|
189
174
|
def refresh_applications(self):
|
|
190
175
|
host = self.maitai_host
|
|
191
|
-
url = f"{host}/
|
|
176
|
+
url = f"{host}/config/init_sdk"
|
|
192
177
|
headers = {
|
|
193
178
|
"Content-Type": "application/json",
|
|
194
179
|
"x-api-key": self.api_key,
|
|
@@ -199,9 +184,14 @@ class Config:
|
|
|
199
184
|
self._session.close()
|
|
200
185
|
if response.status_code != 200:
|
|
201
186
|
raise Exception(f"Failed to initialize Maitai client: {response.text}")
|
|
187
|
+
response_json = response.json()
|
|
202
188
|
applications = [
|
|
203
|
-
Application().from_dict(app_json)
|
|
189
|
+
Application().from_dict(app_json)
|
|
190
|
+
for app_json in response_json["applications"]
|
|
204
191
|
]
|
|
192
|
+
self._company_id = response_json.get("company_id")
|
|
193
|
+
if not self._company_id:
|
|
194
|
+
raise Exception("Company ID not found in response")
|
|
205
195
|
return self.store_application_metadata(applications)
|
|
206
196
|
|
|
207
197
|
def store_application_metadata(self, applications: List[Application]):
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import json
|
|
2
3
|
import traceback
|
|
3
4
|
from typing import AsyncIterable, Iterable, Optional
|
|
@@ -36,6 +37,7 @@ class InferenceWarning(Warning):
|
|
|
36
37
|
|
|
37
38
|
class Inference(MaitaiClient):
|
|
38
39
|
_session = None
|
|
40
|
+
_async_session = None
|
|
39
41
|
|
|
40
42
|
def __init__(self):
|
|
41
43
|
super().__init__()
|
|
@@ -47,7 +49,7 @@ class Inference(MaitaiClient):
|
|
|
47
49
|
if evaluate_callback:
|
|
48
50
|
q = ChunkQueue()
|
|
49
51
|
cls.run_async(
|
|
50
|
-
cls.
|
|
52
|
+
cls.send_inference_request_async_fresh_session(
|
|
51
53
|
request_dict,
|
|
52
54
|
chunk_queue=q,
|
|
53
55
|
timeout=timeout,
|
|
@@ -161,49 +163,48 @@ class Inference(MaitaiClient):
|
|
|
161
163
|
"x-client-version": version,
|
|
162
164
|
}
|
|
163
165
|
try:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
166
|
+
if cls._async_session is None:
|
|
167
|
+
cls._async_session = aiohttp.ClientSession(
|
|
168
|
+
connector=aiohttp.TCPConnector(ssl=False, limit=100),
|
|
169
|
+
timeout=ClientTimeout(timeout) if timeout else None,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
async with cls._async_session.post(
|
|
173
|
+
url, headers=headers, data=json.dumps(request_dict)
|
|
174
|
+
) as response:
|
|
175
|
+
if response.status != 200:
|
|
176
|
+
error_text = await response.text()
|
|
177
|
+
cls.log_error(error_text, url)
|
|
178
|
+
exception = MaitaiConnectionError(
|
|
179
|
+
f"Failed to send inference request. Status code: {response.status}. Error: {error_text}"
|
|
180
|
+
)
|
|
181
|
+
if chunk_queue:
|
|
182
|
+
chunk_queue.put(exception)
|
|
183
|
+
if async_chunk_queue:
|
|
184
|
+
await async_chunk_queue.put(exception)
|
|
185
|
+
return
|
|
186
|
+
async for line in response.content:
|
|
187
|
+
if line:
|
|
188
|
+
inference_response: InferenceStreamResponse = (
|
|
189
|
+
InferenceStreamResponse().from_json(line)
|
|
176
190
|
)
|
|
191
|
+
if inference_response.keep_alive:
|
|
192
|
+
continue
|
|
177
193
|
if chunk_queue:
|
|
178
|
-
chunk_queue.put(
|
|
194
|
+
chunk_queue.put(inference_response)
|
|
179
195
|
if async_chunk_queue:
|
|
180
|
-
await async_chunk_queue.put(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
await async_chunk_queue.put(inference_response)
|
|
193
|
-
if (
|
|
194
|
-
inference_response.evaluate_response
|
|
195
|
-
and evaluation_callback
|
|
196
|
-
):
|
|
197
|
-
try:
|
|
198
|
-
evaluation_callback(
|
|
199
|
-
inference_response.evaluate_response
|
|
200
|
-
)
|
|
201
|
-
except:
|
|
202
|
-
traceback.print_exc()
|
|
203
|
-
if chunk_queue:
|
|
204
|
-
chunk_queue.put(StopIteration())
|
|
205
|
-
if async_chunk_queue:
|
|
206
|
-
await async_chunk_queue.put(StopIteration())
|
|
196
|
+
await async_chunk_queue.put(inference_response)
|
|
197
|
+
if inference_response.evaluate_response and evaluation_callback:
|
|
198
|
+
try:
|
|
199
|
+
evaluation_callback(
|
|
200
|
+
inference_response.evaluate_response
|
|
201
|
+
)
|
|
202
|
+
except:
|
|
203
|
+
traceback.print_exc()
|
|
204
|
+
if chunk_queue:
|
|
205
|
+
chunk_queue.put(StopIteration())
|
|
206
|
+
if async_chunk_queue:
|
|
207
|
+
await async_chunk_queue.put(StopIteration())
|
|
207
208
|
except Exception as e:
|
|
208
209
|
exception = MaitaiConnectionError(
|
|
209
210
|
f"Failed to send inference request: {str(e)}"
|
|
@@ -275,11 +276,97 @@ class Inference(MaitaiClient):
|
|
|
275
276
|
)
|
|
276
277
|
return cls._session
|
|
277
278
|
|
|
279
|
+
@classmethod
|
|
280
|
+
async def send_inference_request_async_fresh_session(
|
|
281
|
+
cls,
|
|
282
|
+
request_dict: dict,
|
|
283
|
+
chunk_queue: ChunkQueue = None,
|
|
284
|
+
async_chunk_queue: AsyncChunkQueue = None,
|
|
285
|
+
evaluation_callback: EvaluateCallback = None,
|
|
286
|
+
timeout=None,
|
|
287
|
+
):
|
|
288
|
+
host = config.maitai_host
|
|
289
|
+
url = f"{host}/chat/completions/serialized"
|
|
290
|
+
headers = {
|
|
291
|
+
"Content-Type": "application/json",
|
|
292
|
+
"x-api-key": config.api_key,
|
|
293
|
+
"x-client-version": version,
|
|
294
|
+
}
|
|
295
|
+
try:
|
|
296
|
+
async with aiohttp.ClientSession(
|
|
297
|
+
connector=aiohttp.TCPConnector(ssl=False),
|
|
298
|
+
timeout=ClientTimeout(timeout) if timeout else None,
|
|
299
|
+
) as session:
|
|
300
|
+
async with session.post(
|
|
301
|
+
url, headers=headers, data=json.dumps(request_dict)
|
|
302
|
+
) as response:
|
|
303
|
+
if response.status != 200:
|
|
304
|
+
error_text = await response.text()
|
|
305
|
+
cls.log_error(error_text, url)
|
|
306
|
+
exception = MaitaiConnectionError(
|
|
307
|
+
f"Failed to send inference request. Status code: {response.status}. Error: {error_text}"
|
|
308
|
+
)
|
|
309
|
+
if chunk_queue:
|
|
310
|
+
chunk_queue.put(exception)
|
|
311
|
+
if async_chunk_queue:
|
|
312
|
+
await async_chunk_queue.put(exception)
|
|
313
|
+
return
|
|
314
|
+
async for line in response.content:
|
|
315
|
+
if line:
|
|
316
|
+
inference_response: InferenceStreamResponse = (
|
|
317
|
+
InferenceStreamResponse().from_json(line)
|
|
318
|
+
)
|
|
319
|
+
if inference_response.keep_alive:
|
|
320
|
+
continue
|
|
321
|
+
if chunk_queue:
|
|
322
|
+
chunk_queue.put(inference_response)
|
|
323
|
+
if async_chunk_queue:
|
|
324
|
+
await async_chunk_queue.put(inference_response)
|
|
325
|
+
if (
|
|
326
|
+
inference_response.evaluate_response
|
|
327
|
+
and evaluation_callback
|
|
328
|
+
):
|
|
329
|
+
try:
|
|
330
|
+
evaluation_callback(
|
|
331
|
+
inference_response.evaluate_response
|
|
332
|
+
)
|
|
333
|
+
except:
|
|
334
|
+
traceback.print_exc()
|
|
335
|
+
if chunk_queue:
|
|
336
|
+
chunk_queue.put(StopIteration())
|
|
337
|
+
if async_chunk_queue:
|
|
338
|
+
await async_chunk_queue.put(StopIteration())
|
|
339
|
+
except Exception as e:
|
|
340
|
+
exception = MaitaiConnectionError(
|
|
341
|
+
f"Failed to send inference request: {str(e)}"
|
|
342
|
+
)
|
|
343
|
+
await cls.increment_error(str(e), url)
|
|
344
|
+
if chunk_queue:
|
|
345
|
+
chunk_queue.put(exception)
|
|
346
|
+
if async_chunk_queue:
|
|
347
|
+
await async_chunk_queue.put(exception)
|
|
348
|
+
|
|
278
349
|
@classmethod
|
|
279
350
|
def close_session(cls):
|
|
280
351
|
if cls._session:
|
|
281
352
|
cls._session.close()
|
|
282
353
|
cls._session = None
|
|
283
354
|
|
|
355
|
+
@classmethod
|
|
356
|
+
async def close_async_session(cls):
|
|
357
|
+
if cls._async_session:
|
|
358
|
+
await cls._async_session.close()
|
|
359
|
+
cls._async_session = None
|
|
360
|
+
|
|
284
361
|
def __del__(self):
|
|
285
362
|
self.close_session()
|
|
363
|
+
self.run_async(self.close_async_session())
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
import atexit
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
@atexit.register
|
|
370
|
+
def cleanup():
|
|
371
|
+
asyncio.run(Inference.close_async_session())
|
|
372
|
+
Inference.close_session()
|
|
@@ -51,6 +51,8 @@ class AnnotationSession(betterproto.Message):
|
|
|
51
51
|
class FinetuningData(betterproto.Message):
|
|
52
52
|
messages: List["_chat__.ChatMessage"] = betterproto.message_field(1)
|
|
53
53
|
tools: List["_chat__.Tool"] = betterproto.message_field(2)
|
|
54
|
+
request_id: str = betterproto.string_field(3)
|
|
55
|
+
session_id: str = betterproto.string_field(4)
|
|
54
56
|
|
|
55
57
|
|
|
56
58
|
@dataclass(eq=False, repr=False)
|
|
@@ -400,6 +400,10 @@ class EvaluateResponse(betterproto.Message):
|
|
|
400
400
|
reference_id: str = betterproto.string_field(9)
|
|
401
401
|
id: int = betterproto.int64_field(10)
|
|
402
402
|
date_created: int = betterproto.int64_field(11)
|
|
403
|
+
correction: str = betterproto.string_field(12)
|
|
404
|
+
meta: Dict[str, str] = betterproto.map_field(
|
|
405
|
+
13, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
406
|
+
)
|
|
403
407
|
|
|
404
408
|
|
|
405
409
|
@dataclass(eq=False, repr=False)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maitai_python-1.1.41b0 → maitai_python-1.1.43}/maitai_common/processes/websocket_listener_thread.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|