maitai-python 1.2.24__tar.gz → 1.2.26__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.2.24 → maitai_python-1.2.26}/PKG-INFO +1 -1
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_inference.py +6 -2
- maitai_python-1.2.26/maitai/_maitai.py +196 -0
- maitai_python-1.2.26/maitai/_maitai_async.py +195 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_maitai_client.py +4 -41
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_utils.py +14 -7
- maitai_python-1.2.26/maitai/models/agent.py +26 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/application.py +12 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/chat.py +1 -1
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/config.py +10 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_common/config/config_service.py +2 -1
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_common/version.py +1 -1
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_python.egg-info/SOURCES.txt +1 -0
- maitai_python-1.2.24/maitai/_maitai.py +0 -722
- maitai_python-1.2.24/maitai/_maitai_async.py +0 -725
- {maitai_python-1.2.24 → maitai_python-1.2.26}/README.md +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/__init__.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_config.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_config_listener.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_context.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_evaluator.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_pydantic.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/_types.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/exceptions.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/__init__.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/event.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/inference.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/key.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/metric.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/models/sentinel.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_common/__init__.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/setup.cfg +0 -0
- {maitai_python-1.2.24 → maitai_python-1.2.26}/setup.py +0 -0
|
@@ -322,7 +322,9 @@ class Inference(MaitaiClient):
|
|
|
322
322
|
}
|
|
323
323
|
try:
|
|
324
324
|
client = self.get_client()
|
|
325
|
-
return client.put(
|
|
325
|
+
return client.put(
|
|
326
|
+
url, headers=headers, timeout=10, json=metric.model_dump()
|
|
327
|
+
)
|
|
326
328
|
except:
|
|
327
329
|
pass
|
|
328
330
|
|
|
@@ -338,7 +340,9 @@ class Inference(MaitaiClient):
|
|
|
338
340
|
}
|
|
339
341
|
try:
|
|
340
342
|
client = await self.get_async_client()
|
|
341
|
-
return await client.put(
|
|
343
|
+
return await client.put(
|
|
344
|
+
url, headers=headers, timeout=10, json=metric.model_dump()
|
|
345
|
+
)
|
|
342
346
|
except:
|
|
343
347
|
pass
|
|
344
348
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from typing import Mapping, Optional, Union
|
|
4
|
+
|
|
5
|
+
import groq
|
|
6
|
+
import httpx
|
|
7
|
+
import openai
|
|
8
|
+
|
|
9
|
+
from maitai._config import config
|
|
10
|
+
from maitai.chat._completions import Completions
|
|
11
|
+
from maitai.models.chat import AzureParams, ClientParams
|
|
12
|
+
from maitai.models.key import Key
|
|
13
|
+
from maitai.transcriptions._transcriptions import Transcriptions
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger("maitai")
|
|
16
|
+
|
|
17
|
+
DEFAULT_MAX_RETRIES = 2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Maitai:
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
*,
|
|
24
|
+
maitai_api_key: Optional[str] = None,
|
|
25
|
+
api_key: Optional[str] = None,
|
|
26
|
+
openai_api_key: Optional[str] = None,
|
|
27
|
+
groq_api_key: Optional[str] = None,
|
|
28
|
+
anthropic_api_key: Optional[str] = None,
|
|
29
|
+
cerebras_api_key: Optional[str] = None,
|
|
30
|
+
azure_api_key: Optional[str] = None,
|
|
31
|
+
sambanova_api_key: Optional[str] = None,
|
|
32
|
+
gemini_api_key: Optional[str] = None,
|
|
33
|
+
deepseek_api_key: Optional[str] = None,
|
|
34
|
+
azure_deployment: Optional[str] = None,
|
|
35
|
+
azure_api_version: Optional[str] = None,
|
|
36
|
+
azure_endpoint: Optional[str] = None,
|
|
37
|
+
organization: Optional[str] = None,
|
|
38
|
+
project: Optional[str] = None,
|
|
39
|
+
base_url: Union[str, httpx.URL, None] = None,
|
|
40
|
+
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
41
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
42
|
+
default_headers: Optional[Mapping[str, str]] = None,
|
|
43
|
+
default_query: Optional[Mapping[str, object]] = None,
|
|
44
|
+
http_client: Optional[httpx.Client] = None,
|
|
45
|
+
_strict_response_validation: bool = False,
|
|
46
|
+
):
|
|
47
|
+
if not maitai_api_key:
|
|
48
|
+
maitai_api_key = os.environ.get("MAITAI_API_KEY")
|
|
49
|
+
if maitai_api_key:
|
|
50
|
+
config.initialize(maitai_api_key)
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"MAITAI_API_KEY has not been set. Either set via environment variable or pass it directly into the client."
|
|
54
|
+
)
|
|
55
|
+
if api_key:
|
|
56
|
+
raise ValueError(
|
|
57
|
+
"api_key is deprecated. Use provider specific keys instead. Supported variables: openai_api_key, groq_api_key, anthropic_api_key, cerebras_api_key, azure_api_key, sambanova_api_key, gemini_api_key, deepseek_api_key"
|
|
58
|
+
)
|
|
59
|
+
if openai_api_key:
|
|
60
|
+
if not config.auth_keys.openai_api_key:
|
|
61
|
+
config.auth_keys.openai_api_key = Key(
|
|
62
|
+
key_value=openai_api_key,
|
|
63
|
+
)
|
|
64
|
+
else:
|
|
65
|
+
config.auth_keys.openai_api_key.key_value = openai_api_key
|
|
66
|
+
if groq_api_key:
|
|
67
|
+
if not config.auth_keys.groq_api_key:
|
|
68
|
+
config.auth_keys.groq_api_key = Key(
|
|
69
|
+
key_value=groq_api_key,
|
|
70
|
+
)
|
|
71
|
+
else:
|
|
72
|
+
config.auth_keys.groq_api_key.key_value = groq_api_key
|
|
73
|
+
if anthropic_api_key:
|
|
74
|
+
if not config.auth_keys.anthropic_api_key:
|
|
75
|
+
config.auth_keys.anthropic_api_key = Key(
|
|
76
|
+
key_value=anthropic_api_key,
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
config.auth_keys.anthropic_api_key.key_value = anthropic_api_key
|
|
80
|
+
if cerebras_api_key:
|
|
81
|
+
if not config.auth_keys.cerebras_api_key:
|
|
82
|
+
config.auth_keys.cerebras_api_key = Key(
|
|
83
|
+
key_value=cerebras_api_key,
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
config.auth_keys.cerebras_api_key.key_value = cerebras_api_key
|
|
87
|
+
if azure_api_key:
|
|
88
|
+
if not config.auth_keys.azure_api_key:
|
|
89
|
+
config.auth_keys.azure_api_key = Key(
|
|
90
|
+
key_value=azure_api_key,
|
|
91
|
+
)
|
|
92
|
+
else:
|
|
93
|
+
config.auth_keys.azure_api_key.key_value = azure_api_key
|
|
94
|
+
if sambanova_api_key:
|
|
95
|
+
if not config.auth_keys.sambanova_api_key:
|
|
96
|
+
config.auth_keys.sambanova_api_key = Key(
|
|
97
|
+
key_value=sambanova_api_key,
|
|
98
|
+
)
|
|
99
|
+
else:
|
|
100
|
+
config.auth_keys.sambanova_api_key.key_value = sambanova_api_key
|
|
101
|
+
if gemini_api_key:
|
|
102
|
+
if not config.auth_keys.gemini_api_key:
|
|
103
|
+
config.auth_keys.gemini_api_key = Key(
|
|
104
|
+
key_value=gemini_api_key,
|
|
105
|
+
)
|
|
106
|
+
else:
|
|
107
|
+
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
108
|
+
if deepseek_api_key:
|
|
109
|
+
if not config.auth_keys.deepseek_api_key:
|
|
110
|
+
config.auth_keys.deepseek_api_key = Key(
|
|
111
|
+
key_value=deepseek_api_key,
|
|
112
|
+
)
|
|
113
|
+
else:
|
|
114
|
+
config.auth_keys.deepseek_api_key.key_value = deepseek_api_key
|
|
115
|
+
self._openai_client = None
|
|
116
|
+
self._groq_client = None
|
|
117
|
+
azure_params = None
|
|
118
|
+
if azure_api_key:
|
|
119
|
+
azure_params = AzureParams(
|
|
120
|
+
endpoint=azure_endpoint,
|
|
121
|
+
deployment=azure_deployment,
|
|
122
|
+
api_version=azure_api_version,
|
|
123
|
+
)
|
|
124
|
+
self._openai_client = openai.AzureOpenAI( # type: ignore
|
|
125
|
+
azure_endpoint=azure_endpoint,
|
|
126
|
+
azure_deployment=azure_deployment,
|
|
127
|
+
api_key=azure_api_key,
|
|
128
|
+
api_version=azure_api_version,
|
|
129
|
+
organization=organization,
|
|
130
|
+
project=project,
|
|
131
|
+
base_url=base_url,
|
|
132
|
+
timeout=timeout,
|
|
133
|
+
max_retries=max_retries,
|
|
134
|
+
default_headers=default_headers,
|
|
135
|
+
default_query=default_query,
|
|
136
|
+
http_client=http_client,
|
|
137
|
+
_strict_response_validation=_strict_response_validation,
|
|
138
|
+
)
|
|
139
|
+
elif openai_api_key or os.environ.get("OPENAI_API_KEY"):
|
|
140
|
+
self._openai_client = openai.OpenAI(
|
|
141
|
+
api_key=openai_api_key or os.environ.get("OPENAI_API_KEY"),
|
|
142
|
+
organization=organization,
|
|
143
|
+
project=project,
|
|
144
|
+
base_url=base_url,
|
|
145
|
+
timeout=timeout,
|
|
146
|
+
max_retries=max_retries,
|
|
147
|
+
default_headers=default_headers,
|
|
148
|
+
default_query=default_query,
|
|
149
|
+
http_client=http_client,
|
|
150
|
+
_strict_response_validation=_strict_response_validation,
|
|
151
|
+
)
|
|
152
|
+
if groq_api_key or config.auth_keys.groq_api_key:
|
|
153
|
+
|
|
154
|
+
self._groq_client = groq.Groq(
|
|
155
|
+
api_key=groq_api_key
|
|
156
|
+
or (
|
|
157
|
+
config.auth_keys.groq_api_key.key_value
|
|
158
|
+
if config.auth_keys.groq_api_key
|
|
159
|
+
else None
|
|
160
|
+
),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
client_params = None
|
|
164
|
+
if base_url or default_headers or default_query:
|
|
165
|
+
client_param_dict = {}
|
|
166
|
+
if base_url:
|
|
167
|
+
client_param_dict["base_url"] = base_url
|
|
168
|
+
if default_headers:
|
|
169
|
+
client_param_dict["default_headers"] = default_headers
|
|
170
|
+
if default_query:
|
|
171
|
+
client_param_dict["default_query"] = default_query
|
|
172
|
+
if azure_params:
|
|
173
|
+
client_param_dict["azure_params"] = azure_params
|
|
174
|
+
client_params = ClientParams(**client_param_dict)
|
|
175
|
+
self.chat = Chat(self._openai_client, self._groq_client, client_params)
|
|
176
|
+
self.audio = Audio(self._openai_client, self._groq_client, client_params)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class Chat:
|
|
180
|
+
def __init__(
|
|
181
|
+
self,
|
|
182
|
+
openai_client=None,
|
|
183
|
+
groq_client=None,
|
|
184
|
+
client_params: Optional[ClientParams] = None,
|
|
185
|
+
):
|
|
186
|
+
self.completions = Completions(openai_client, groq_client, client_params)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class Audio:
|
|
190
|
+
def __init__(
|
|
191
|
+
self,
|
|
192
|
+
openai_client=None,
|
|
193
|
+
groq_client=None,
|
|
194
|
+
client_params: Optional[ClientParams] = None,
|
|
195
|
+
):
|
|
196
|
+
self.transcriptions = Transcriptions(openai_client)
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from typing import Mapping, Optional, Union
|
|
4
|
+
|
|
5
|
+
import groq
|
|
6
|
+
import httpx
|
|
7
|
+
import openai
|
|
8
|
+
|
|
9
|
+
from maitai._config import config
|
|
10
|
+
from maitai.chat._completions_async import AsyncCompletions
|
|
11
|
+
from maitai.models.chat import AzureParams, ClientParams
|
|
12
|
+
from maitai.models.key import Key
|
|
13
|
+
from maitai.transcriptions._transcriptions_async import AsyncTranscriptions
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger("maitai")
|
|
16
|
+
|
|
17
|
+
DEFAULT_MAX_RETRIES = 2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MaitaiAsync:
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
*,
|
|
24
|
+
maitai_api_key: Optional[str] = None,
|
|
25
|
+
api_key: Optional[str] = None,
|
|
26
|
+
openai_api_key: Optional[str] = None,
|
|
27
|
+
groq_api_key: Optional[str] = None,
|
|
28
|
+
anthropic_api_key: Optional[str] = None,
|
|
29
|
+
cerebras_api_key: Optional[str] = None,
|
|
30
|
+
sambanova_api_key: Optional[str] = None,
|
|
31
|
+
gemini_api_key: Optional[str] = None,
|
|
32
|
+
deepseek_api_key: Optional[str] = None,
|
|
33
|
+
azure_api_key: Optional[str] = None,
|
|
34
|
+
azure_deployment: Optional[str] = None,
|
|
35
|
+
azure_api_version: Optional[str] = None,
|
|
36
|
+
azure_endpoint: Optional[str] = None,
|
|
37
|
+
organization: Optional[str] = None,
|
|
38
|
+
project: Optional[str] = None,
|
|
39
|
+
base_url: Union[str, httpx.URL, None] = None,
|
|
40
|
+
timeout: Union[float, httpx.Timeout, None, openai.NotGiven] = openai.NOT_GIVEN,
|
|
41
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
42
|
+
default_headers: Optional[Mapping[str, str]] = None,
|
|
43
|
+
default_query: Optional[Mapping[str, object]] = None,
|
|
44
|
+
http_client: Optional[httpx.AsyncClient] = None,
|
|
45
|
+
_strict_response_validation: bool = False,
|
|
46
|
+
):
|
|
47
|
+
if not maitai_api_key:
|
|
48
|
+
maitai_api_key = os.environ.get("MAITAI_API_KEY")
|
|
49
|
+
if maitai_api_key:
|
|
50
|
+
config.initialize(maitai_api_key)
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"MAITAI_API_KEY has not been set. Either set via environment variable or pass it directly into the client."
|
|
54
|
+
)
|
|
55
|
+
if api_key:
|
|
56
|
+
raise ValueError(
|
|
57
|
+
"api_key is deprecated. Use provider specific keys instead. Supported variables: openai_api_key, groq_api_key, anthropic_api_key, cerebras_api_key, azure_api_key, sambanova_api_key, gemini_api_key"
|
|
58
|
+
)
|
|
59
|
+
if openai_api_key:
|
|
60
|
+
if not config.auth_keys.openai_api_key:
|
|
61
|
+
config.auth_keys.openai_api_key = Key(
|
|
62
|
+
key_value=openai_api_key,
|
|
63
|
+
)
|
|
64
|
+
else:
|
|
65
|
+
config.auth_keys.openai_api_key.key_value = openai_api_key
|
|
66
|
+
if groq_api_key:
|
|
67
|
+
if not config.auth_keys.groq_api_key:
|
|
68
|
+
config.auth_keys.groq_api_key = Key(
|
|
69
|
+
key_value=groq_api_key,
|
|
70
|
+
)
|
|
71
|
+
else:
|
|
72
|
+
config.auth_keys.groq_api_key.key_value = groq_api_key
|
|
73
|
+
if anthropic_api_key:
|
|
74
|
+
if not config.auth_keys.anthropic_api_key:
|
|
75
|
+
config.auth_keys.anthropic_api_key = Key(
|
|
76
|
+
key_value=anthropic_api_key,
|
|
77
|
+
)
|
|
78
|
+
else:
|
|
79
|
+
config.auth_keys.anthropic_api_key.key_value = anthropic_api_key
|
|
80
|
+
if cerebras_api_key:
|
|
81
|
+
if not config.auth_keys.cerebras_api_key:
|
|
82
|
+
config.auth_keys.cerebras_api_key = Key(
|
|
83
|
+
key_value=cerebras_api_key,
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
config.auth_keys.cerebras_api_key.key_value = cerebras_api_key
|
|
87
|
+
if azure_api_key:
|
|
88
|
+
if not config.auth_keys.azure_api_key:
|
|
89
|
+
config.auth_keys.azure_api_key = Key(
|
|
90
|
+
key_value=azure_api_key,
|
|
91
|
+
)
|
|
92
|
+
else:
|
|
93
|
+
config.auth_keys.azure_api_key.key_value = azure_api_key
|
|
94
|
+
if sambanova_api_key:
|
|
95
|
+
if not config.auth_keys.sambanova_api_key:
|
|
96
|
+
config.auth_keys.sambanova_api_key = Key(
|
|
97
|
+
key_value=sambanova_api_key,
|
|
98
|
+
)
|
|
99
|
+
else:
|
|
100
|
+
config.auth_keys.sambanova_api_key.key_value = sambanova_api_key
|
|
101
|
+
if gemini_api_key:
|
|
102
|
+
if not config.auth_keys.gemini_api_key:
|
|
103
|
+
config.auth_keys.gemini_api_key = Key(
|
|
104
|
+
key_value=gemini_api_key,
|
|
105
|
+
)
|
|
106
|
+
else:
|
|
107
|
+
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
108
|
+
if deepseek_api_key:
|
|
109
|
+
if not config.auth_keys.deepseek_api_key:
|
|
110
|
+
config.auth_keys.deepseek_api_key = Key(
|
|
111
|
+
key_value=deepseek_api_key,
|
|
112
|
+
)
|
|
113
|
+
else:
|
|
114
|
+
config.auth_keys.deepseek_api_key.key_value = deepseek_api_key
|
|
115
|
+
self._openai_client = None
|
|
116
|
+
self._groq_client = None
|
|
117
|
+
azure_params = None
|
|
118
|
+
if azure_api_key:
|
|
119
|
+
azure_params = AzureParams(
|
|
120
|
+
endpoint=azure_endpoint,
|
|
121
|
+
deployment=azure_deployment,
|
|
122
|
+
api_version=azure_api_version,
|
|
123
|
+
)
|
|
124
|
+
self._openai_client = openai.AsyncAzureOpenAI( # type: ignore
|
|
125
|
+
azure_endpoint=azure_endpoint,
|
|
126
|
+
azure_deployment=azure_deployment,
|
|
127
|
+
api_key=azure_api_key,
|
|
128
|
+
api_version=azure_api_version,
|
|
129
|
+
organization=organization,
|
|
130
|
+
project=project,
|
|
131
|
+
base_url=base_url,
|
|
132
|
+
timeout=timeout,
|
|
133
|
+
max_retries=max_retries,
|
|
134
|
+
default_headers=default_headers,
|
|
135
|
+
default_query=default_query,
|
|
136
|
+
http_client=http_client,
|
|
137
|
+
_strict_response_validation=_strict_response_validation,
|
|
138
|
+
)
|
|
139
|
+
elif openai_api_key or os.environ.get("OPENAI_API_KEY"):
|
|
140
|
+
self._openai_client = openai.AsyncClient(
|
|
141
|
+
api_key=openai_api_key or os.environ.get("OPENAI_API_KEY"),
|
|
142
|
+
organization=organization,
|
|
143
|
+
project=project,
|
|
144
|
+
base_url=base_url,
|
|
145
|
+
timeout=timeout,
|
|
146
|
+
max_retries=max_retries,
|
|
147
|
+
default_headers=default_headers,
|
|
148
|
+
default_query=default_query,
|
|
149
|
+
http_client=http_client,
|
|
150
|
+
_strict_response_validation=_strict_response_validation,
|
|
151
|
+
)
|
|
152
|
+
if groq_api_key or config.auth_keys.groq_api_key:
|
|
153
|
+
self._groq_client = groq.AsyncGroq(
|
|
154
|
+
api_key=groq_api_key
|
|
155
|
+
or (
|
|
156
|
+
config.auth_keys.groq_api_key.key_value
|
|
157
|
+
if config.auth_keys.groq_api_key
|
|
158
|
+
else None
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
client_params = None
|
|
163
|
+
if base_url or default_headers or default_query:
|
|
164
|
+
client_param_dict = {}
|
|
165
|
+
if base_url:
|
|
166
|
+
client_param_dict["base_url"] = base_url
|
|
167
|
+
if default_headers:
|
|
168
|
+
client_param_dict["default_headers"] = default_headers
|
|
169
|
+
if default_query:
|
|
170
|
+
client_param_dict["default_query"] = default_query
|
|
171
|
+
if azure_params:
|
|
172
|
+
client_param_dict["azure_params"] = azure_params
|
|
173
|
+
client_params = ClientParams(**client_param_dict)
|
|
174
|
+
self.chat = AsyncChat(self._openai_client, self._groq_client, client_params)
|
|
175
|
+
self.audio = AsyncAudio(self._openai_client, self._groq_client, client_params)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class AsyncChat:
|
|
179
|
+
def __init__(
|
|
180
|
+
self,
|
|
181
|
+
openai_client=None,
|
|
182
|
+
groq_client=None,
|
|
183
|
+
client_params: Optional[ClientParams] = None,
|
|
184
|
+
):
|
|
185
|
+
self.completions = AsyncCompletions(openai_client, groq_client, client_params)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
class AsyncAudio:
|
|
189
|
+
def __init__(
|
|
190
|
+
self,
|
|
191
|
+
openai_client=None,
|
|
192
|
+
groq_client=None,
|
|
193
|
+
client_params: Optional[ClientParams] = None,
|
|
194
|
+
):
|
|
195
|
+
self.transcriptions = AsyncTranscriptions(openai_client)
|
|
@@ -43,30 +43,6 @@ def _get_aws_instance_metadata(url, timeout=2):
|
|
|
43
43
|
return None
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
def _get_gcp_instance_metadata(url, timeout=2):
|
|
47
|
-
try:
|
|
48
|
-
headers = {"Metadata-Flavor": "Google"}
|
|
49
|
-
with httpx.Client() as client:
|
|
50
|
-
response = client.get(url, headers=headers, timeout=timeout)
|
|
51
|
-
response.raise_for_status()
|
|
52
|
-
return response.text
|
|
53
|
-
except Exception:
|
|
54
|
-
return None
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _get_azure_instance_metadata(timeout=2):
|
|
58
|
-
try:
|
|
59
|
-
headers = {"Metadata": "true"}
|
|
60
|
-
url = "http://169.254.169.254/metadata/instance/compute?api-version=2021-02-01"
|
|
61
|
-
with httpx.Client() as client:
|
|
62
|
-
response = client.get(url, headers=headers, timeout=timeout)
|
|
63
|
-
response.raise_for_status()
|
|
64
|
-
data = response.json()
|
|
65
|
-
return data.get("location")
|
|
66
|
-
except Exception:
|
|
67
|
-
return None
|
|
68
|
-
|
|
69
|
-
|
|
70
46
|
def _determine_maitai_host():
|
|
71
47
|
if maitai_host := os.environ.get("MAITAI_HOST"):
|
|
72
48
|
return maitai_host.rstrip("/")
|
|
@@ -79,21 +55,6 @@ def _determine_maitai_host():
|
|
|
79
55
|
):
|
|
80
56
|
return "https://api.aws.us-west-2.trymaitai.ai"
|
|
81
57
|
|
|
82
|
-
gcp_zone = _get_gcp_instance_metadata(
|
|
83
|
-
"http://metadata.google.internal/computeMetadata/v1/instance/zone"
|
|
84
|
-
)
|
|
85
|
-
if gcp_zone:
|
|
86
|
-
if "us-west1" in gcp_zone:
|
|
87
|
-
return "https://api.gcp.us-west1.trymaitai.ai"
|
|
88
|
-
# elif "us-central1" in gcp_zone:
|
|
89
|
-
# return "https://api.gcp.us-central1.trymaitai.ai"
|
|
90
|
-
elif "us-south1" in gcp_zone:
|
|
91
|
-
return "https://api.gcp.us-south1.trymaitai.ai"
|
|
92
|
-
|
|
93
|
-
azure_region = _get_azure_instance_metadata()
|
|
94
|
-
if azure_region == "westus2":
|
|
95
|
-
return "https://api.azure.westus2.trymaitai.ai"
|
|
96
|
-
|
|
97
58
|
return "https://api.trymaitai.ai"
|
|
98
59
|
|
|
99
60
|
|
|
@@ -109,7 +70,7 @@ class MaitaiClient:
|
|
|
109
70
|
if self._client is None:
|
|
110
71
|
self._client = httpx.Client(
|
|
111
72
|
**CLIENT_SETTINGS,
|
|
112
|
-
transport=httpx.HTTPTransport(retries=DEFAULT_MAX_RETRIES),
|
|
73
|
+
transport=httpx.HTTPTransport(retries=DEFAULT_MAX_RETRIES, http2=True),
|
|
113
74
|
)
|
|
114
75
|
return self._client
|
|
115
76
|
|
|
@@ -117,7 +78,9 @@ class MaitaiClient:
|
|
|
117
78
|
if self._async_client is None:
|
|
118
79
|
self._async_client = httpx.AsyncClient(
|
|
119
80
|
**CLIENT_SETTINGS,
|
|
120
|
-
transport=httpx.AsyncHTTPTransport(
|
|
81
|
+
transport=httpx.AsyncHTTPTransport(
|
|
82
|
+
retries=DEFAULT_MAX_RETRIES, http2=True
|
|
83
|
+
),
|
|
121
84
|
)
|
|
122
85
|
return self._async_client
|
|
123
86
|
|
|
@@ -24,7 +24,7 @@ from maitai._pydantic import (
|
|
|
24
24
|
is_dataclass_like_type,
|
|
25
25
|
to_strict_json_schema,
|
|
26
26
|
)
|
|
27
|
-
from maitai._types import ToolFunction
|
|
27
|
+
from maitai._types import Headers, ToolFunction
|
|
28
28
|
from maitai.tools import Tools
|
|
29
29
|
from maitai_common.version import version
|
|
30
30
|
|
|
@@ -34,7 +34,7 @@ CallableT = TypeVar("CallableT", bound=Callable[..., Any])
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def type_to_response_format_param(response_format):
|
|
37
|
-
json_schema_type: type[pydantic.BaseModel]
|
|
37
|
+
json_schema_type: Union[type[pydantic.BaseModel], pydantic.TypeAdapter[Any]]
|
|
38
38
|
|
|
39
39
|
if is_basemodel_type(response_format):
|
|
40
40
|
name = response_format.__name__
|
|
@@ -146,7 +146,7 @@ def convert_open_ai_chat_completion_chunk(
|
|
|
146
146
|
def get_chat_completion_params(
|
|
147
147
|
*,
|
|
148
148
|
messages: Iterable[openai_types.ChatCompletionMessageParam],
|
|
149
|
-
model: Union[str, ChatModel],
|
|
149
|
+
model: Union[str, ChatModel, openai.NotGiven] = openai.NOT_GIVEN,
|
|
150
150
|
frequency_penalty: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
151
151
|
logit_bias: Union[Optional[Dict[str, int]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
152
152
|
logprobs: Union[Optional[bool], openai.NotGiven] = openai.NOT_GIVEN,
|
|
@@ -157,10 +157,11 @@ def get_chat_completion_params(
|
|
|
157
157
|
openai_types.completion_create_params.ResponseFormat,
|
|
158
158
|
chat_types.ResponseFormat,
|
|
159
159
|
openai.NotGiven,
|
|
160
|
+
dict[str, Any],
|
|
160
161
|
] = openai.NOT_GIVEN,
|
|
161
162
|
seed: Union[Optional[int], openai.NotGiven] = openai.NOT_GIVEN,
|
|
162
163
|
stop: Union[Union[Optional[str], List[str]], openai.NotGiven] = openai.NOT_GIVEN,
|
|
163
|
-
stream:
|
|
164
|
+
stream: Union[bool, openai.NotGiven, None] = openai.NOT_GIVEN,
|
|
164
165
|
stream_options: Union[
|
|
165
166
|
Optional[openai_types.ChatCompletionStreamOptionsParam], openai.NotGiven
|
|
166
167
|
] = openai.NOT_GIVEN,
|
|
@@ -169,6 +170,7 @@ def get_chat_completion_params(
|
|
|
169
170
|
openai_types.ChatCompletionToolChoiceOptionParam, openai.NotGiven
|
|
170
171
|
] = openai.NOT_GIVEN,
|
|
171
172
|
tools: Union[
|
|
173
|
+
Tools,
|
|
172
174
|
Iterable[Union[openai_types.ChatCompletionToolParam, ToolFunction]],
|
|
173
175
|
openai.NotGiven,
|
|
174
176
|
] = openai.NOT_GIVEN,
|
|
@@ -176,8 +178,10 @@ def get_chat_completion_params(
|
|
|
176
178
|
top_p: Union[Optional[float], openai.NotGiven] = openai.NOT_GIVEN,
|
|
177
179
|
user: Union[str, openai.NotGiven] = openai.NOT_GIVEN,
|
|
178
180
|
parallel_tool_calls: Union[bool, openai.NotGiven] = openai.NOT_GIVEN,
|
|
179
|
-
reasoning_effort:
|
|
180
|
-
extra_headers:
|
|
181
|
+
reasoning_effort: Union[str, openai.NotGiven, None] = openai.NOT_GIVEN,
|
|
182
|
+
extra_headers: Union[
|
|
183
|
+
None, Headers, Dict[str, str], openai.NotGiven
|
|
184
|
+
] = openai.NOT_GIVEN,
|
|
181
185
|
) -> Dict[str, Any]:
|
|
182
186
|
params = {
|
|
183
187
|
"messages": [msg for msg in messages],
|
|
@@ -308,7 +312,10 @@ def convert_params_to_groq(params: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
308
312
|
del params["reasoning_effort"]
|
|
309
313
|
if "stream_options" in params:
|
|
310
314
|
del params["stream_options"]
|
|
311
|
-
if
|
|
315
|
+
if (
|
|
316
|
+
params.get("max_tokens", openai.NOT_GIVEN) == openai.NOT_GIVEN
|
|
317
|
+
or params.get("max_tokens", 0) <= 0
|
|
318
|
+
):
|
|
312
319
|
## max_tokens must be positive
|
|
313
320
|
params["max_tokens"] = 1000
|
|
314
321
|
to_del = []
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# codegen: frontend, sdk
|
|
2
|
+
from typing import Any, Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Agent(BaseModel):
|
|
8
|
+
id: Optional[int] = -1
|
|
9
|
+
date_created: Optional[float] = 0
|
|
10
|
+
application_id: int
|
|
11
|
+
agent_name: str
|
|
12
|
+
description: Optional[str] = None
|
|
13
|
+
meta: Dict[str, Any] = Field(default_factory=dict)
|
|
14
|
+
state: str = "ENABLED"
|
|
15
|
+
|
|
16
|
+
# Additional fields from joins (not in database schema)
|
|
17
|
+
intents: List["ApplicationAction"] = Field(default_factory=list)
|
|
18
|
+
conversation_count: Optional[int] = 0
|
|
19
|
+
intent_count: Optional[int] = 0
|
|
20
|
+
application_name: Optional[str] = None # For joins with application table
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Import here to avoid circular imports
|
|
24
|
+
from maitai.models.application import ApplicationAction
|
|
25
|
+
|
|
26
|
+
Agent.model_rebuild()
|
|
@@ -24,6 +24,8 @@ class ApplicationAction(BaseModel):
|
|
|
24
24
|
prompt: Optional[str] = None
|
|
25
25
|
request_count: Optional[int] = 0
|
|
26
26
|
intent_group_id: Optional[int] = -1
|
|
27
|
+
agent_id: Optional[int] = None # New field for agent relationship
|
|
28
|
+
agent_name: Optional[str] = None # For joins with agent table
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
class Application(BaseModel):
|
|
@@ -39,6 +41,10 @@ class Application(BaseModel):
|
|
|
39
41
|
last_activity: Optional[int] = 0
|
|
40
42
|
fault_notifications: Optional[bool] = False
|
|
41
43
|
session_summaries: Optional[bool] = False
|
|
44
|
+
agents: List["Agent"] = Field(
|
|
45
|
+
default_factory=list
|
|
46
|
+
) # New field for agent relationship
|
|
47
|
+
agent_count: Optional[int] = 0 # Derived field for agent count
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
class ApplicationContext(BaseModel):
|
|
@@ -50,3 +56,9 @@ class ApplicationContext(BaseModel):
|
|
|
50
56
|
context_type: Optional[str] = "TEXT"
|
|
51
57
|
reference: Optional[str] = None
|
|
52
58
|
description: Optional[str] = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# Import here to avoid circular imports
|
|
62
|
+
from maitai.models.agent import Agent
|
|
63
|
+
|
|
64
|
+
Application.model_rebuild()
|
|
@@ -181,7 +181,7 @@ class ChatCompletionRequest(BaseModel):
|
|
|
181
181
|
safe_mode: Optional[bool] = Field(default=False)
|
|
182
182
|
preserve_model_alias: Optional[bool] = False
|
|
183
183
|
fallback_config: Optional[config.FallbackConfig] = None
|
|
184
|
-
request_type: Literal["PROD", "RERUN", "SYNTHETIC"] = "PROD"
|
|
184
|
+
request_type: Literal["PROD", "RERUN", "SYNTHETIC", "MANUAL"] = "PROD"
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
class FunctionCall(BaseModel):
|
|
@@ -59,3 +59,13 @@ class ModelConfig(BaseModel):
|
|
|
59
59
|
server_models: List[str] = Field(default_factory=list)
|
|
60
60
|
default_client_model: str
|
|
61
61
|
model_prompts: Optional[Dict[str, str]] = Field(default={})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Endpoint(BaseModel):
|
|
65
|
+
id: int = -1
|
|
66
|
+
cloud: str = ""
|
|
67
|
+
region: str = ""
|
|
68
|
+
address: str = ""
|
|
69
|
+
environment: str = ""
|
|
70
|
+
company_id: int = -1
|
|
71
|
+
default: bool = False
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
if os.environ.get("MAITAI_ENV") in ["prod", "staging", "development", "test"]:
|
|
4
5
|
from maitai_models.config import Config, InferenceLocations
|
|
5
6
|
else:
|
|
6
7
|
from maitai.models.config import Config, InferenceLocations
|