maitai-python 1.0.11__tar.gz → 1.0.13__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.11 → maitai_python-1.0.13}/PKG-INFO +1 -1
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_config.py +6 -1
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_inference.py +5 -2
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_maitai_client.py +2 -1
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_openai.py +9 -2
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_openai_async.py +9 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/application/__init__.py +1 -3
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/chat/__init__.py +8 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/inference/__init__.py +1 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/notification/__init__.py +2 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/session/__init__.py +4 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.0.11 → maitai_python-1.0.13}/setup.py +1 -1
- {maitai_python-1.0.11 → maitai_python-1.0.13}/README.md +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_azure.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_evaluator.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_openai_types.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai/_utils.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.0.11 → maitai_python-1.0.13}/setup.cfg +0 -0
|
@@ -5,12 +5,13 @@ import requests
|
|
|
5
5
|
from maitai._config_listener_thread import ConfigListenerThread
|
|
6
6
|
from maitai_common.config import config_service
|
|
7
7
|
from maitai_gen.application import Application
|
|
8
|
+
from maitai_gen.chat import ChatCompletionAuth
|
|
8
9
|
from maitai_gen.config import Config as ActionConfig
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class Config:
|
|
12
13
|
maitai_host = os.environ.get("MAITAI_HOST", 'https://api.trymaitai.ai')
|
|
13
|
-
maitai_ws = os.environ.get("MAITAI_WS", 'wss://
|
|
14
|
+
maitai_ws = os.environ.get("MAITAI_WS", 'wss://09hidyy627.execute-api.us-west-2.amazonaws.com/production')
|
|
14
15
|
|
|
15
16
|
def __init__(self):
|
|
16
17
|
self._api_key = None
|
|
@@ -20,6 +21,10 @@ class Config:
|
|
|
20
21
|
self.config_listener_thread = None
|
|
21
22
|
self._application_action_configs: dict[str, dict[str, ActionConfig]] = {}
|
|
22
23
|
self.initialized = False
|
|
24
|
+
self.auth_info = ChatCompletionAuth(
|
|
25
|
+
openai_api_key=os.environ.get("OPENAI_API_KEY"),
|
|
26
|
+
groq_api_key=os.environ.get("GROQ_API_KEY"),
|
|
27
|
+
)
|
|
23
28
|
|
|
24
29
|
@property
|
|
25
30
|
def api_key(self):
|
|
@@ -13,6 +13,11 @@ from maitai_gen.chat import ChatCompletionChunk, ChatCompletionParams, ChatCompl
|
|
|
13
13
|
from maitai_gen.inference import InferenceStreamResponse
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class InferenceException(Exception):
|
|
17
|
+
def __init__(self, msg: str):
|
|
18
|
+
super().__init__(msg)
|
|
19
|
+
|
|
20
|
+
|
|
16
21
|
class Inference(MaitaiClient):
|
|
17
22
|
|
|
18
23
|
def __init__(self):
|
|
@@ -66,8 +71,6 @@ class Inference(MaitaiClient):
|
|
|
66
71
|
if response.status_code != 200:
|
|
67
72
|
print(f"Failed to send inference request. Status code: {response.status_code}. Error: {response.text}")
|
|
68
73
|
return
|
|
69
|
-
else:
|
|
70
|
-
print(f"Successfully sent inference request. Status code: {response.status_code}")
|
|
71
74
|
try:
|
|
72
75
|
for line in response.iter_lines():
|
|
73
76
|
if line:
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
import threading
|
|
4
4
|
|
|
5
5
|
from maitai_gen.chat import ChatCompletionParams, ChatCompletionRequest
|
|
6
|
-
|
|
6
|
+
from maitai._config import config
|
|
7
7
|
|
|
8
8
|
class MaitaiClient:
|
|
9
9
|
MAITAI_HOST = os.environ.get("MAITAI_HOST", 'https://api.trymaitai.ai')
|
|
@@ -45,4 +45,5 @@ class MaitaiClient:
|
|
|
45
45
|
infer_request.apply_corrections = apply_corrections
|
|
46
46
|
infer_request.params = completion_params
|
|
47
47
|
infer_request.evaluation_enabled = evaluation_enabled
|
|
48
|
+
infer_request.auth_info = config.auth_info
|
|
48
49
|
return infer_request
|
|
@@ -8,6 +8,7 @@ import openai.types.chat as openai_chat_types
|
|
|
8
8
|
import maitai
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._evaluator import Evaluator
|
|
11
|
+
from maitai._inference import InferenceException
|
|
11
12
|
from maitai._openai_types import Body, Headers, Query
|
|
12
13
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
13
14
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
@@ -37,6 +38,8 @@ class MaitaiOpenAIClient:
|
|
|
37
38
|
):
|
|
38
39
|
if maitai_api_key:
|
|
39
40
|
config.initialize(maitai_api_key)
|
|
41
|
+
if api_key:
|
|
42
|
+
config.auth_info.override_api_key = api_key
|
|
40
43
|
self.client = openai.OpenAI(
|
|
41
44
|
api_key=api_key,
|
|
42
45
|
organization=organization,
|
|
@@ -109,8 +112,6 @@ class Completions:
|
|
|
109
112
|
raise ValueError("server_side_inference must be true to apply_corrections")
|
|
110
113
|
if apply_corrections is True and evaluation_enabled is False:
|
|
111
114
|
raise ValueError("evaluations must be enabled to apply_corrections")
|
|
112
|
-
if self.client is None:
|
|
113
|
-
self.client = openai.OpenAI()
|
|
114
115
|
maitai_config = config.get_application_action_config(application_ref_name, action_type)
|
|
115
116
|
if server_side_inference is None:
|
|
116
117
|
server_side_inference = maitai_config.inference_location == InferenceLocations.SERVER
|
|
@@ -165,9 +166,13 @@ class Completions:
|
|
|
165
166
|
# ChatCompletion only
|
|
166
167
|
chat_completion: Optional[ChatCompletionResponse] = None
|
|
167
168
|
for resp in response:
|
|
169
|
+
if resp.error:
|
|
170
|
+
raise InferenceException(resp.error)
|
|
168
171
|
return resp.chat_completion_response
|
|
169
172
|
return chat_completion
|
|
170
173
|
else:
|
|
174
|
+
if self.client is None:
|
|
175
|
+
self.client = openai.OpenAI()
|
|
171
176
|
response = self.client.chat.completions.create(
|
|
172
177
|
messages=messages,
|
|
173
178
|
model=model,
|
|
@@ -276,6 +281,8 @@ def _process_openai_stream(session_id: Union[str, int],
|
|
|
276
281
|
|
|
277
282
|
def _process_inference_stream(stream: Iterable[InferenceStreamResponse]) -> Iterable[ChatCompletionChunk]:
|
|
278
283
|
for infer_resp in stream:
|
|
284
|
+
if infer_resp.error:
|
|
285
|
+
raise InferenceException(infer_resp.error)
|
|
279
286
|
chunk = infer_resp.chat_completion_chunk
|
|
280
287
|
if chunk is not None:
|
|
281
288
|
yield chunk
|
|
@@ -8,6 +8,7 @@ import openai.types.chat as openai_chat_types
|
|
|
8
8
|
import maitai
|
|
9
9
|
from maitai._config import config
|
|
10
10
|
from maitai._evaluator import Evaluator
|
|
11
|
+
from maitai._inference import InferenceException
|
|
11
12
|
from maitai._openai_types import Body, Headers, Query
|
|
12
13
|
from maitai._utils import convert_open_ai_chat_completion_chunk, convert_openai_chat_completion, get_chat_completion_params, required_args
|
|
13
14
|
from maitai_common.utils.proto_utils import openai_messages_to_proto
|
|
@@ -38,6 +39,8 @@ class MaitaiAsyncOpenAIClient:
|
|
|
38
39
|
):
|
|
39
40
|
if maitai_api_key:
|
|
40
41
|
config.initialize(maitai_api_key)
|
|
42
|
+
if api_key:
|
|
43
|
+
config.auth_info.override_api_key = api_key
|
|
41
44
|
self.client = openai.AsyncClient(
|
|
42
45
|
api_key=api_key,
|
|
43
46
|
organization=organization,
|
|
@@ -169,9 +172,13 @@ class AsyncCompletions:
|
|
|
169
172
|
# ChatCompletion only
|
|
170
173
|
chat_completion: Optional[ChatCompletionResponse] = None
|
|
171
174
|
async for resp in response:
|
|
175
|
+
if resp.error:
|
|
176
|
+
raise InferenceException(resp.error)
|
|
172
177
|
return resp.chat_completion_response
|
|
173
178
|
return chat_completion
|
|
174
179
|
else:
|
|
180
|
+
if self.client is None:
|
|
181
|
+
self.client = openai.OpenAI()
|
|
175
182
|
response = await self.client.chat.completions.create(
|
|
176
183
|
messages=messages,
|
|
177
184
|
model=model,
|
|
@@ -280,6 +287,8 @@ async def _process_async_openai_stream(session_id: Union[str, int],
|
|
|
280
287
|
|
|
281
288
|
async def _process_inference_stream_async(stream: AsyncIterable[InferenceStreamResponse]) -> AsyncIterable[ChatCompletionChunk]:
|
|
282
289
|
async for infer_resp in stream:
|
|
290
|
+
if infer_resp.error:
|
|
291
|
+
raise InferenceException(infer_resp.error)
|
|
283
292
|
chunk = infer_resp.chat_completion_chunk
|
|
284
293
|
if chunk is not None:
|
|
285
294
|
yield chunk
|
|
@@ -41,9 +41,7 @@ class Application(betterproto.Message):
|
|
|
41
41
|
company_id: int = betterproto.int64_field(5)
|
|
42
42
|
application_objective: "ApplicationObjective" = betterproto.message_field(6)
|
|
43
43
|
state: str = betterproto.string_field(7)
|
|
44
|
-
meta:
|
|
45
|
-
8, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
46
|
-
)
|
|
44
|
+
meta: "_config__.Config" = betterproto.message_field(8)
|
|
47
45
|
action_types: List["ApplicationAction"] = betterproto.message_field(9)
|
|
48
46
|
|
|
49
47
|
|
|
@@ -44,6 +44,14 @@ class ChatCompletionRequest(betterproto.Message):
|
|
|
44
44
|
date_created: int = betterproto.int64_field(9)
|
|
45
45
|
request_id: str = betterproto.string_field(10)
|
|
46
46
|
evaluation_enabled: bool = betterproto.bool_field(11)
|
|
47
|
+
auth_info: "ChatCompletionAuth" = betterproto.message_field(12)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(eq=False, repr=False)
|
|
51
|
+
class ChatCompletionAuth(betterproto.Message):
|
|
52
|
+
openai_api_key: str = betterproto.string_field(1)
|
|
53
|
+
groq_api_key: str = betterproto.string_field(2)
|
|
54
|
+
override_api_key: str = betterproto.string_field(3)
|
|
47
55
|
|
|
48
56
|
|
|
49
57
|
@dataclass(eq=False, repr=False)
|
|
@@ -20,6 +20,8 @@ class Notification(betterproto.Message):
|
|
|
20
20
|
meta: Dict[str, str] = betterproto.map_field(
|
|
21
21
|
7, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
22
22
|
)
|
|
23
|
+
application_id: int = betterproto.int64_field(8)
|
|
24
|
+
session_id: str = betterproto.string_field(9)
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
@dataclass(eq=False, repr=False)
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
7
|
from typing import (
|
|
8
|
+
Dict,
|
|
8
9
|
List,
|
|
9
10
|
Optional,
|
|
10
11
|
)
|
|
@@ -32,6 +33,9 @@ class Session(betterproto.Message):
|
|
|
32
33
|
fully_corrected: bool = betterproto.bool_field(6)
|
|
33
34
|
summary: str = betterproto.string_field(7)
|
|
34
35
|
feedback: "SessionFeedback" = betterproto.enum_field(8)
|
|
36
|
+
reviewer: Dict[str, str] = betterproto.map_field(
|
|
37
|
+
9, betterproto.TYPE_STRING, betterproto.TYPE_STRING
|
|
38
|
+
)
|
|
35
39
|
|
|
36
40
|
|
|
37
41
|
@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
|
{maitai_python-1.0.11 → maitai_python-1.0.13}/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
|