maitai-python 1.1.15b1__tar.gz → 1.1.16b0__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.15b1 → maitai_python-1.1.16b0}/PKG-INFO +1 -1
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_config.py +8 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_evaluator.py +18 -11
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_inference.py +46 -30
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_maitai_client.py +30 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/version.py +1 -1
- maitai_python-1.1.16b0/maitai_gen/billing/__init__.py +23 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/chat/__init__.py +4 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/company/__init__.py +2 -1
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/sentinel/__init__.py +1 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/SOURCES.txt +1 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/README.md +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_azure.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_context.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_maitai.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_maitai_async.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_types.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/_utils.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/backtest/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/metric/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/setup.cfg +0 -0
- {maitai_python-1.1.15b1 → maitai_python-1.1.16b0}/setup.py +0 -0
|
@@ -153,5 +153,13 @@ class Config:
|
|
|
153
153
|
self.config_listener_thread.daemon = True
|
|
154
154
|
self.config_listener_thread.start()
|
|
155
155
|
|
|
156
|
+
def cleanup(self):
|
|
157
|
+
if self.config_listener_thread:
|
|
158
|
+
self.config_listener_thread.terminate()
|
|
159
|
+
self.config_listener_thread = None
|
|
160
|
+
|
|
156
161
|
|
|
157
162
|
config = Config()
|
|
163
|
+
|
|
164
|
+
import atexit
|
|
165
|
+
atexit.register(config.cleanup)
|
|
@@ -119,23 +119,29 @@ class Evaluator(MaitaiClient):
|
|
|
119
119
|
|
|
120
120
|
@classmethod
|
|
121
121
|
async def send_evaluation_request_async(cls, eval_request: EvaluateRequest, callback: EvaluateCallback = None):
|
|
122
|
+
path = "request" if callback else "submit"
|
|
123
|
+
host = config.maitai_host
|
|
124
|
+
url = f'{host}/evaluation/{path}'
|
|
125
|
+
|
|
122
126
|
async def send_request():
|
|
123
|
-
path = "request" if callback else "submit"
|
|
124
|
-
host = config.maitai_host
|
|
125
|
-
url = f'{host}/evaluation/{path}'
|
|
126
127
|
headers = {
|
|
127
128
|
'Content-Type': 'application/json',
|
|
128
129
|
'x-api-key': config.api_key,
|
|
129
130
|
'x-client-version': version,
|
|
130
131
|
}
|
|
131
|
-
|
|
132
|
-
async with
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
try:
|
|
133
|
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
|
|
134
|
+
async with session.post(url, headers=headers,
|
|
135
|
+
data=eval_request.to_json(casing=Casing.SNAKE)) as response:
|
|
136
|
+
print("received", response.status)
|
|
137
|
+
if response.status != 200:
|
|
138
|
+
error_text = await response.text()
|
|
139
|
+
cls.log_error(error_text, url)
|
|
140
|
+
print(f"Failed to send evaluation request. Status code: {response.status}. Error: {error_text}")
|
|
141
|
+
return None
|
|
142
|
+
return await response.read()
|
|
143
|
+
except Exception as e:
|
|
144
|
+
await cls.increment_error(str(e), url)
|
|
139
145
|
|
|
140
146
|
result = await send_request()
|
|
141
147
|
if result is not None:
|
|
@@ -162,6 +168,7 @@ class Evaluator(MaitaiClient):
|
|
|
162
168
|
response = requests.post(url, headers=headers, data=eval_request.to_json(casing=Casing.SNAKE), stream=True)
|
|
163
169
|
if response.status_code != 200:
|
|
164
170
|
print(f"Failed to send stream correction request. Status code: {response.status_code}. Error: {response.text}")
|
|
171
|
+
cls.log_error(response.text, url)
|
|
165
172
|
return
|
|
166
173
|
try:
|
|
167
174
|
for line in response.iter_lines():
|
|
@@ -79,9 +79,15 @@ class Inference(MaitaiClient):
|
|
|
79
79
|
'x-api-key': config.api_key,
|
|
80
80
|
'x-client-version': version,
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
try:
|
|
83
|
+
response = requests.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE), stream=True, timeout=timeout or 120)
|
|
84
|
+
if response.status_code != 200:
|
|
85
|
+
cls.log_error(response.text, url)
|
|
86
|
+
raise MaitaiConnectionError(f"Failed to send inference request. Status code: {response.status_code}. Error: {response.text}")
|
|
87
|
+
except Exception as e:
|
|
88
|
+
cls.log_error(str(e), url)
|
|
89
|
+
raise MaitaiConnectionError(f"Failed to send inference request. Error: {e}")
|
|
90
|
+
|
|
85
91
|
try:
|
|
86
92
|
for line in response.iter_lines():
|
|
87
93
|
if line:
|
|
@@ -104,34 +110,43 @@ class Inference(MaitaiClient):
|
|
|
104
110
|
'x-api-key': config.api_key,
|
|
105
111
|
'x-client-version': version,
|
|
106
112
|
}
|
|
107
|
-
|
|
108
|
-
async with
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if async_chunk_queue:
|
|
115
|
-
await async_chunk_queue.put(exception)
|
|
116
|
-
return
|
|
117
|
-
async for line in response.content:
|
|
118
|
-
if line:
|
|
119
|
-
inference_response: InferenceStreamResponse = InferenceStreamResponse().from_json(line)
|
|
120
|
-
if inference_response.keep_alive:
|
|
121
|
-
continue
|
|
113
|
+
try:
|
|
114
|
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False), timeout=ClientTimeout(timeout or 120)) as session:
|
|
115
|
+
async with session.post(url, headers=headers, data=chat_request.to_json(casing=Casing.SNAKE)) as response:
|
|
116
|
+
if response.status != 200:
|
|
117
|
+
error_text = await response.text()
|
|
118
|
+
cls.log_error(error_text, url)
|
|
119
|
+
exception = MaitaiConnectionError(f"Failed to send inference request. Status code: {response.status}. Error: {error_text}")
|
|
122
120
|
if chunk_queue:
|
|
123
|
-
chunk_queue.put(
|
|
121
|
+
chunk_queue.put(exception)
|
|
124
122
|
if async_chunk_queue:
|
|
125
|
-
await async_chunk_queue.put(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
await async_chunk_queue.put(exception)
|
|
124
|
+
return
|
|
125
|
+
async for line in response.content:
|
|
126
|
+
if line:
|
|
127
|
+
inference_response: InferenceStreamResponse = InferenceStreamResponse().from_json(line)
|
|
128
|
+
if inference_response.keep_alive:
|
|
129
|
+
continue
|
|
130
|
+
if chunk_queue:
|
|
131
|
+
chunk_queue.put(inference_response)
|
|
132
|
+
if async_chunk_queue:
|
|
133
|
+
await async_chunk_queue.put(inference_response)
|
|
134
|
+
if inference_response.evaluate_response and evaluation_callback:
|
|
135
|
+
try:
|
|
136
|
+
evaluation_callback(inference_response.evaluate_response)
|
|
137
|
+
except:
|
|
138
|
+
traceback.print_exc()
|
|
139
|
+
if chunk_queue:
|
|
140
|
+
chunk_queue.put(StopIteration())
|
|
141
|
+
if async_chunk_queue:
|
|
142
|
+
await async_chunk_queue.put(StopIteration())
|
|
143
|
+
except Exception as e:
|
|
144
|
+
exception = MaitaiConnectionError(f"Failed to send inference request: {str(e)}")
|
|
145
|
+
await cls.increment_error(str(e), url)
|
|
146
|
+
if chunk_queue:
|
|
147
|
+
chunk_queue.put(exception)
|
|
148
|
+
if async_chunk_queue:
|
|
149
|
+
await async_chunk_queue.put(exception)
|
|
135
150
|
|
|
136
151
|
@classmethod
|
|
137
152
|
async def send_storage_request_async(cls, chat_storage_request: ChatStorageRequest):
|
|
@@ -145,7 +160,8 @@ class Inference(MaitaiClient):
|
|
|
145
160
|
try:
|
|
146
161
|
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
|
|
147
162
|
return await session.put(url, headers=headers, data=chat_storage_request.to_json(casing=Casing.SNAKE))
|
|
148
|
-
except:
|
|
163
|
+
except Exception as e:
|
|
164
|
+
await cls.increment_error(str(e), url)
|
|
149
165
|
pass
|
|
150
166
|
|
|
151
167
|
@classmethod
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import json
|
|
2
3
|
import threading
|
|
3
4
|
|
|
5
|
+
import aiohttp
|
|
6
|
+
|
|
7
|
+
from maitai._config import config
|
|
8
|
+
from maitai_common.version import version
|
|
9
|
+
|
|
4
10
|
|
|
5
11
|
class MaitaiClient:
|
|
6
12
|
|
|
@@ -30,3 +36,27 @@ class MaitaiClient:
|
|
|
30
36
|
new_loop.close()
|
|
31
37
|
|
|
32
38
|
threading.Thread(target=run).start()
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def log_error(cls, error: str, path: str):
|
|
42
|
+
cls.run_async(cls.increment_error(error, path))
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
async def increment_error(cls, error: str, path: str):
|
|
46
|
+
host = config.maitai_host
|
|
47
|
+
url = f'{host}/metrics/increment/python_sdk_error'
|
|
48
|
+
headers = {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'x-api-key': config.api_key,
|
|
51
|
+
'x-client-version': version,
|
|
52
|
+
}
|
|
53
|
+
labels = {
|
|
54
|
+
"cause": error,
|
|
55
|
+
"type": "ERROR",
|
|
56
|
+
"path": path,
|
|
57
|
+
}
|
|
58
|
+
try:
|
|
59
|
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
|
|
60
|
+
return await session.put(url, headers=headers, data=json.dumps(labels))
|
|
61
|
+
except:
|
|
62
|
+
pass
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
2
|
+
# sources: billing.proto
|
|
3
|
+
# plugin: python-betterproto
|
|
4
|
+
# This file has been @generated
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Dict
|
|
8
|
+
|
|
9
|
+
import betterproto
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(eq=False, repr=False)
|
|
13
|
+
class PaymentMethod(betterproto.Message):
|
|
14
|
+
id: int = betterproto.int64_field(1)
|
|
15
|
+
company_id: int = betterproto.int64_field(2)
|
|
16
|
+
stripe_id: str = betterproto.string_field(3)
|
|
17
|
+
status: str = betterproto.string_field(4)
|
|
18
|
+
date_created: int = betterproto.int64_field(5)
|
|
19
|
+
fingerprint: str = betterproto.string_field(6)
|
|
20
|
+
meta: Dict[str, str] = betterproto.map_field(
|
|
21
|
+
7, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
22
|
+
)
|
|
23
|
+
is_default: bool = betterproto.bool_field(8)
|
|
@@ -185,6 +185,7 @@ class ChatCompletionResponse(betterproto.Message):
|
|
|
185
185
|
15, optional=True, group="_service_tier"
|
|
186
186
|
)
|
|
187
187
|
input_safety_score: float = betterproto.float_field(16)
|
|
188
|
+
fallback_reason: str = betterproto.string_field(17)
|
|
188
189
|
|
|
189
190
|
|
|
190
191
|
@dataclass(eq=False, repr=False)
|
|
@@ -253,6 +254,7 @@ class ChatCompletionChunk(betterproto.Message):
|
|
|
253
254
|
)
|
|
254
255
|
input_safety_score: float = betterproto.float_field(11)
|
|
255
256
|
request_id: str = betterproto.string_field(12)
|
|
257
|
+
fallback_reason: str = betterproto.string_field(13)
|
|
256
258
|
|
|
257
259
|
|
|
258
260
|
@dataclass(eq=False, repr=False)
|
|
@@ -347,6 +349,7 @@ class EvaluateRequest(betterproto.Message):
|
|
|
347
349
|
stream: bool = betterproto.bool_field(21)
|
|
348
350
|
apply_corrections: bool = betterproto.bool_field(22)
|
|
349
351
|
timing_metrics: "_metric__.RequestTimingMetric" = betterproto.message_field(23)
|
|
352
|
+
tools: List["Tool"] = betterproto.message_field(24)
|
|
350
353
|
|
|
351
354
|
|
|
352
355
|
@dataclass(eq=False, repr=False)
|
|
@@ -415,6 +418,7 @@ class BacktestEvaluateRequest(betterproto.Message):
|
|
|
415
418
|
request_messages: List["ChatMessage"] = betterproto.message_field(11)
|
|
416
419
|
response_message: "ChatCompletionMessage" = betterproto.message_field(12)
|
|
417
420
|
sentinels: List["_sentinel__.Sentinel"] = betterproto.message_field(13)
|
|
421
|
+
tools: List["Tool"] = betterproto.message_field(14)
|
|
418
422
|
|
|
419
423
|
|
|
420
424
|
class EvaluationServiceStub(betterproto.ServiceStub):
|
|
@@ -15,7 +15,8 @@ class Company(betterproto.Message):
|
|
|
15
15
|
date_created: int = betterproto.int64_field(2)
|
|
16
16
|
company_name: str = betterproto.string_field(3)
|
|
17
17
|
url: str = betterproto.string_field(4)
|
|
18
|
-
|
|
18
|
+
logo: str = betterproto.string_field(5)
|
|
19
19
|
meta: Dict[str, str] = betterproto.map_field(
|
|
20
20
|
6, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
21
21
|
)
|
|
22
|
+
customer_id: str = betterproto.string_field(7)
|
|
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
|
|
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.15b1 → maitai_python-1.1.16b0}/maitai_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|