maitai-python 1.2.22__py3-none-any.whl → 1.2.23__py3-none-any.whl
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/_config.py +13 -0
- maitai/_evaluator.py +0 -6
- maitai/_inference.py +4 -0
- maitai/_maitai.py +80 -43
- maitai/_maitai_async.py +82 -42
- maitai/_maitai_client.py +6 -0
- maitai/_utils.py +14 -0
- maitai/models/chat.py +1 -0
- maitai_common/version.py +1 -1
- {maitai_python-1.2.22.dist-info → maitai_python-1.2.23.dist-info}/METADATA +2 -1
- {maitai_python-1.2.22.dist-info → maitai_python-1.2.23.dist-info}/RECORD +13 -13
- {maitai_python-1.2.22.dist-info → maitai_python-1.2.23.dist-info}/WHEEL +1 -1
- {maitai_python-1.2.22.dist-info → maitai_python-1.2.23.dist-info}/top_level.txt +0 -0
maitai/_config.py
CHANGED
|
@@ -31,6 +31,7 @@ class Config(MaitaiClient):
|
|
|
31
31
|
cerebras_api_key=Key(id=-1, key_value=os.environ.get("CEREBRAS_API_KEY")),
|
|
32
32
|
sambanova_api_key=Key(id=-1, key_value=os.environ.get("SAMBANOVA_API_KEY")),
|
|
33
33
|
gemini_api_key=Key(id=-1, key_value=os.environ.get("GEMINI_API_KEY")),
|
|
34
|
+
azure_api_key=Key(id=-1, key_value=os.environ.get("AZURE_API_KEY")),
|
|
34
35
|
)
|
|
35
36
|
self.refresh_interval = 30 * 60 # 30 minutes in seconds
|
|
36
37
|
|
|
@@ -65,6 +66,18 @@ class Config(MaitaiClient):
|
|
|
65
66
|
if not self._company_id:
|
|
66
67
|
raise Exception("Company ID not found in response")
|
|
67
68
|
|
|
69
|
+
# Process API keys from the response
|
|
70
|
+
if "api_keys" in response_json:
|
|
71
|
+
api_keys = response_json["api_keys"]
|
|
72
|
+
# Update Groq API key if provided
|
|
73
|
+
for key_name, key_value in api_keys.items():
|
|
74
|
+
if key_value and hasattr(self.auth_keys, f"{key_name}_api_key"):
|
|
75
|
+
setattr(
|
|
76
|
+
self.auth_keys,
|
|
77
|
+
f"{key_name}_api_key",
|
|
78
|
+
Key(id=-1, key_value=key_value),
|
|
79
|
+
)
|
|
80
|
+
|
|
68
81
|
self.store_application_metadata(applications)
|
|
69
82
|
|
|
70
83
|
def initialize(self, api_key, retry=0):
|
maitai/_evaluator.py
CHANGED
|
@@ -233,9 +233,6 @@ class Evaluator(MaitaiClient):
|
|
|
233
233
|
response = client.post(url, headers=headers, json=eval_request)
|
|
234
234
|
if response.status_code != 200:
|
|
235
235
|
error_text = response.text
|
|
236
|
-
logger.error(
|
|
237
|
-
f"Failed to send evaluation request. Status code: {response.status_code}. Error: {error_text}"
|
|
238
|
-
)
|
|
239
236
|
self.log_error(config.api_key, error_text, url)
|
|
240
237
|
result = response.content
|
|
241
238
|
except Exception as e:
|
|
@@ -268,9 +265,6 @@ class Evaluator(MaitaiClient):
|
|
|
268
265
|
response = await client.post(url, headers=headers, json=eval_request)
|
|
269
266
|
if response.status_code != 200:
|
|
270
267
|
error_text = response.text
|
|
271
|
-
logger.error(
|
|
272
|
-
f"Failed to send evaluation request. Status code: {response.status_code}. Error: {error_text}"
|
|
273
|
-
)
|
|
274
268
|
await self.log_error_async(config.api_key, error_text, url)
|
|
275
269
|
return None
|
|
276
270
|
result = response.content
|
maitai/_inference.py
CHANGED
|
@@ -312,6 +312,8 @@ class Inference(MaitaiClient):
|
|
|
312
312
|
|
|
313
313
|
def _store_request_timing_data(self, metric: RequestTimingMetric):
|
|
314
314
|
host = config.maitai_host
|
|
315
|
+
if "/batch" in host:
|
|
316
|
+
host = host.replace("/batch", "")
|
|
315
317
|
url = f"{host}/metrics/timing"
|
|
316
318
|
headers = {
|
|
317
319
|
"Content-Type": "application/json",
|
|
@@ -326,6 +328,8 @@ class Inference(MaitaiClient):
|
|
|
326
328
|
|
|
327
329
|
async def send_request_timing_data_async(self, metric: RequestTimingMetric):
|
|
328
330
|
host = config.maitai_host
|
|
331
|
+
if "/batch" in host:
|
|
332
|
+
host = host.replace("/batch", "")
|
|
329
333
|
url = f"{host}/metrics/timing"
|
|
330
334
|
headers = {
|
|
331
335
|
"Content-Type": "application/json",
|
maitai/_maitai.py
CHANGED
|
@@ -6,6 +6,7 @@ import uuid
|
|
|
6
6
|
import warnings
|
|
7
7
|
from typing import Dict, Iterable, List, Mapping, Optional, Union
|
|
8
8
|
|
|
9
|
+
import groq
|
|
9
10
|
import httpx
|
|
10
11
|
import openai
|
|
11
12
|
import openai.types as openai_types
|
|
@@ -27,6 +28,7 @@ from maitai._types import (
|
|
|
27
28
|
from maitai._utils import (
|
|
28
29
|
convert_open_ai_chat_completion_chunk,
|
|
29
30
|
convert_openai_chat_completion,
|
|
31
|
+
convert_params_to_groq,
|
|
30
32
|
get_chat_completion_params,
|
|
31
33
|
required_args,
|
|
32
34
|
type_to_response_format_param,
|
|
@@ -140,7 +142,8 @@ class Maitai:
|
|
|
140
142
|
)
|
|
141
143
|
else:
|
|
142
144
|
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
143
|
-
self.
|
|
145
|
+
self._openai_client = None
|
|
146
|
+
self._groq_client = None
|
|
144
147
|
azure_params = None
|
|
145
148
|
if azure_api_key:
|
|
146
149
|
azure_params = AzureParams(
|
|
@@ -148,7 +151,7 @@ class Maitai:
|
|
|
148
151
|
deployment=azure_deployment,
|
|
149
152
|
api_version=azure_api_version,
|
|
150
153
|
)
|
|
151
|
-
self.
|
|
154
|
+
self._openai_client = openai.AzureOpenAI(
|
|
152
155
|
azure_endpoint=azure_endpoint,
|
|
153
156
|
azure_deployment=azure_deployment,
|
|
154
157
|
api_key=azure_api_key,
|
|
@@ -164,7 +167,7 @@ class Maitai:
|
|
|
164
167
|
_strict_response_validation=_strict_response_validation,
|
|
165
168
|
)
|
|
166
169
|
elif openai_api_key or os.environ.get("OPENAI_API_KEY"):
|
|
167
|
-
self.
|
|
170
|
+
self._openai_client = openai.OpenAI(
|
|
168
171
|
api_key=openai_api_key or os.environ.get("OPENAI_API_KEY"),
|
|
169
172
|
organization=organization,
|
|
170
173
|
project=project,
|
|
@@ -176,6 +179,11 @@ class Maitai:
|
|
|
176
179
|
http_client=http_client,
|
|
177
180
|
_strict_response_validation=_strict_response_validation,
|
|
178
181
|
)
|
|
182
|
+
if groq_api_key or config.auth_keys.groq_api_key:
|
|
183
|
+
self._groq_client = groq.Groq(
|
|
184
|
+
api_key=groq_api_key or config.auth_keys.groq_api_key.key_value,
|
|
185
|
+
)
|
|
186
|
+
|
|
179
187
|
client_params = None
|
|
180
188
|
if base_url or default_headers or default_query:
|
|
181
189
|
client_params = ClientParams(
|
|
@@ -184,21 +192,25 @@ class Maitai:
|
|
|
184
192
|
default_query=default_query or {},
|
|
185
193
|
azure_params=azure_params,
|
|
186
194
|
)
|
|
187
|
-
self.chat = Chat(self.
|
|
195
|
+
self.chat = Chat(self._openai_client, self._groq_client, client_params)
|
|
188
196
|
|
|
189
197
|
|
|
190
198
|
class Chat:
|
|
191
|
-
def __init__(
|
|
192
|
-
self
|
|
199
|
+
def __init__(
|
|
200
|
+
self, openai_client=None, groq_client=None, client_params: ClientParams = None
|
|
201
|
+
):
|
|
202
|
+
self.completions = Completions(openai_client, groq_client, client_params)
|
|
193
203
|
|
|
194
204
|
|
|
195
205
|
class Completions:
|
|
196
206
|
def __init__(
|
|
197
207
|
self,
|
|
198
|
-
|
|
208
|
+
openai_client: Optional[openai.Client] = None,
|
|
209
|
+
groq_client: Optional[groq.Groq] = None,
|
|
199
210
|
client_params: Optional[ClientParams] = None,
|
|
200
211
|
):
|
|
201
|
-
self.
|
|
212
|
+
self._openai_client = openai_client
|
|
213
|
+
self._groq_client = groq_client
|
|
202
214
|
self._client_params = client_params or ClientParams()
|
|
203
215
|
self.evaluator = Evaluator()
|
|
204
216
|
self.inference = Inference()
|
|
@@ -470,14 +482,67 @@ class Completions:
|
|
|
470
482
|
logger.warning("Maitai issue, retrying on client side")
|
|
471
483
|
server_side_inference = False
|
|
472
484
|
if not server_side_inference:
|
|
485
|
+
local_params = {
|
|
486
|
+
"messages": messages,
|
|
487
|
+
"model": model,
|
|
488
|
+
"frequency_penalty": frequency_penalty,
|
|
489
|
+
"function_call": function_call,
|
|
490
|
+
"functions": functions,
|
|
491
|
+
"logit_bias": logit_bias,
|
|
492
|
+
"logprobs": logprobs,
|
|
493
|
+
"max_tokens": max_tokens,
|
|
494
|
+
"n": n,
|
|
495
|
+
"presence_penalty": presence_penalty,
|
|
496
|
+
"reasoning_effort": reasoning_effort,
|
|
497
|
+
"response_format": response_format,
|
|
498
|
+
"seed": seed,
|
|
499
|
+
"stop": stop,
|
|
500
|
+
"stream": stream,
|
|
501
|
+
"stream_options": stream_options,
|
|
502
|
+
"temperature": temperature,
|
|
503
|
+
"tool_choice": tool_choice,
|
|
504
|
+
"tools": tools,
|
|
505
|
+
"top_logprobs": top_logprobs,
|
|
506
|
+
"top_p": top_p,
|
|
507
|
+
"user": user,
|
|
508
|
+
"extra_headers": extra_headers,
|
|
509
|
+
"extra_query": extra_query,
|
|
510
|
+
"extra_body": extra_body,
|
|
511
|
+
"timeout": timeout,
|
|
512
|
+
"parallel_tool_calls": parallel_tool_calls,
|
|
513
|
+
}
|
|
514
|
+
groq_model = False
|
|
515
|
+
if "groq:" in model or "maitai:" in model or "llama" in model:
|
|
516
|
+
groq_model = True
|
|
517
|
+
model = model.replace("groq:", "").replace("maitai:", "")
|
|
473
518
|
if "openai:" in model:
|
|
474
519
|
model = model.replace("openai:", "")
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
520
|
+
|
|
521
|
+
if groq_model:
|
|
522
|
+
if self._groq_client is None:
|
|
523
|
+
if (
|
|
524
|
+
not config.auth_keys.groq_api_key
|
|
525
|
+
or not config.auth_keys.groq_api_key.key_value
|
|
526
|
+
):
|
|
527
|
+
raise ValueError(
|
|
528
|
+
"Groq API key is required for Groq models but was not provided"
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
self._groq_client = groq.Groq(
|
|
532
|
+
api_key=config.auth_keys.groq_api_key.key_value,
|
|
533
|
+
)
|
|
534
|
+
client_to_use = self._groq_client
|
|
535
|
+
local_params = convert_params_to_groq(local_params)
|
|
536
|
+
else:
|
|
537
|
+
if self._openai_client is None:
|
|
538
|
+
self._openai_client = openai.OpenAI(
|
|
539
|
+
api_key=config.auth_keys.openai_api_key.key_value,
|
|
540
|
+
default_headers=self._client_params.default_headers or None,
|
|
541
|
+
default_query=self._client_params.default_query or None,
|
|
542
|
+
base_url=self._client_params.base_url or None,
|
|
543
|
+
)
|
|
544
|
+
client_to_use = self._openai_client
|
|
545
|
+
|
|
481
546
|
if hasattr(response_format, "model_json_schema"):
|
|
482
547
|
response_format = {
|
|
483
548
|
"type": "json_schema",
|
|
@@ -486,35 +551,7 @@ class Completions:
|
|
|
486
551
|
if isinstance(tools, Tools):
|
|
487
552
|
tools = tools.get_tool_definitions()
|
|
488
553
|
|
|
489
|
-
response =
|
|
490
|
-
messages=messages,
|
|
491
|
-
model=model,
|
|
492
|
-
frequency_penalty=frequency_penalty,
|
|
493
|
-
function_call=function_call,
|
|
494
|
-
functions=functions,
|
|
495
|
-
logit_bias=logit_bias,
|
|
496
|
-
logprobs=logprobs,
|
|
497
|
-
max_tokens=max_tokens,
|
|
498
|
-
n=n,
|
|
499
|
-
presence_penalty=presence_penalty,
|
|
500
|
-
reasoning_effort=reasoning_effort,
|
|
501
|
-
response_format=response_format,
|
|
502
|
-
seed=seed,
|
|
503
|
-
stop=stop,
|
|
504
|
-
stream=stream,
|
|
505
|
-
stream_options=stream_options,
|
|
506
|
-
temperature=temperature,
|
|
507
|
-
tool_choice=tool_choice,
|
|
508
|
-
tools=tools,
|
|
509
|
-
top_logprobs=top_logprobs,
|
|
510
|
-
top_p=top_p,
|
|
511
|
-
user=user,
|
|
512
|
-
extra_headers=extra_headers,
|
|
513
|
-
extra_query=extra_query,
|
|
514
|
-
extra_body=extra_body,
|
|
515
|
-
timeout=timeout,
|
|
516
|
-
parallel_tool_calls=parallel_tool_calls,
|
|
517
|
-
)
|
|
554
|
+
response = client_to_use.chat.completions.create(**local_params)
|
|
518
555
|
if stream:
|
|
519
556
|
return self._process_openai_stream(
|
|
520
557
|
session_id,
|
maitai/_maitai_async.py
CHANGED
|
@@ -6,6 +6,7 @@ import uuid
|
|
|
6
6
|
import warnings
|
|
7
7
|
from typing import AsyncIterable, Dict, Iterable, List, Mapping, Optional, Union
|
|
8
8
|
|
|
9
|
+
import groq
|
|
9
10
|
import httpx
|
|
10
11
|
import openai
|
|
11
12
|
import openai.types as openai_types
|
|
@@ -27,6 +28,7 @@ from maitai._types import (
|
|
|
27
28
|
from maitai._utils import (
|
|
28
29
|
convert_open_ai_chat_completion_chunk,
|
|
29
30
|
convert_openai_chat_completion,
|
|
31
|
+
convert_params_to_groq,
|
|
30
32
|
get_chat_completion_params,
|
|
31
33
|
required_args,
|
|
32
34
|
type_to_response_format_param,
|
|
@@ -135,7 +137,8 @@ class MaitaiAsync:
|
|
|
135
137
|
)
|
|
136
138
|
else:
|
|
137
139
|
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
138
|
-
self.
|
|
140
|
+
self._openai_client = None
|
|
141
|
+
self._groq_client = None
|
|
139
142
|
azure_params = None
|
|
140
143
|
if azure_api_key:
|
|
141
144
|
azure_params = AzureParams(
|
|
@@ -143,7 +146,7 @@ class MaitaiAsync:
|
|
|
143
146
|
deployment=azure_deployment,
|
|
144
147
|
api_version=azure_api_version,
|
|
145
148
|
)
|
|
146
|
-
self.
|
|
149
|
+
self._openai_client = openai.AsyncAzureOpenAI(
|
|
147
150
|
azure_endpoint=azure_endpoint,
|
|
148
151
|
azure_deployment=azure_deployment,
|
|
149
152
|
api_key=azure_api_key,
|
|
@@ -159,7 +162,7 @@ class MaitaiAsync:
|
|
|
159
162
|
_strict_response_validation=_strict_response_validation,
|
|
160
163
|
)
|
|
161
164
|
elif openai_api_key or os.environ.get("OPENAI_API_KEY"):
|
|
162
|
-
self.
|
|
165
|
+
self._openai_client = openai.AsyncClient(
|
|
163
166
|
api_key=openai_api_key or os.environ.get("OPENAI_API_KEY"),
|
|
164
167
|
organization=organization,
|
|
165
168
|
project=project,
|
|
@@ -171,6 +174,10 @@ class MaitaiAsync:
|
|
|
171
174
|
http_client=http_client,
|
|
172
175
|
_strict_response_validation=_strict_response_validation,
|
|
173
176
|
)
|
|
177
|
+
if groq_api_key or config.auth_keys.groq_api_key:
|
|
178
|
+
self._groq_client = groq.AsyncGroq(
|
|
179
|
+
api_key=groq_api_key or config.auth_keys.groq_api_key.key_value,
|
|
180
|
+
)
|
|
174
181
|
|
|
175
182
|
client_params = None
|
|
176
183
|
if base_url or default_headers or default_query:
|
|
@@ -180,25 +187,28 @@ class MaitaiAsync:
|
|
|
180
187
|
default_query=default_query or {},
|
|
181
188
|
azure_params=azure_params,
|
|
182
189
|
)
|
|
183
|
-
self.chat = AsyncChat(self.
|
|
190
|
+
self.chat = AsyncChat(self._openai_client, self._groq_client, client_params)
|
|
184
191
|
|
|
185
192
|
|
|
186
193
|
class AsyncChat:
|
|
187
194
|
def __init__(
|
|
188
195
|
self,
|
|
189
|
-
|
|
196
|
+
openai_client=None,
|
|
197
|
+
groq_client=None,
|
|
190
198
|
client_params: ClientParams = None,
|
|
191
199
|
):
|
|
192
|
-
self.completions = AsyncCompletions(
|
|
200
|
+
self.completions = AsyncCompletions(openai_client, groq_client, client_params)
|
|
193
201
|
|
|
194
202
|
|
|
195
203
|
class AsyncCompletions:
|
|
196
204
|
def __init__(
|
|
197
205
|
self,
|
|
198
|
-
|
|
206
|
+
openai_client: Optional[openai.AsyncClient] = None,
|
|
207
|
+
groq_client: Optional[groq.AsyncGroq] = None,
|
|
199
208
|
client_params: Optional[ClientParams] = None,
|
|
200
209
|
):
|
|
201
|
-
self.
|
|
210
|
+
self._openai_client = openai_client
|
|
211
|
+
self._groq_client = groq_client
|
|
202
212
|
self._client_params = client_params or ClientParams()
|
|
203
213
|
self.inference_client = Inference()
|
|
204
214
|
self.evaluator = Evaluator()
|
|
@@ -470,47 +480,77 @@ class AsyncCompletions:
|
|
|
470
480
|
logger.warning("Maitai issue, retrying on client side")
|
|
471
481
|
server_side_inference = False
|
|
472
482
|
if not server_side_inference:
|
|
483
|
+
local_params = {
|
|
484
|
+
"messages": messages,
|
|
485
|
+
"model": model,
|
|
486
|
+
"frequency_penalty": frequency_penalty,
|
|
487
|
+
"function_call": function_call,
|
|
488
|
+
"functions": functions,
|
|
489
|
+
"logit_bias": logit_bias,
|
|
490
|
+
"logprobs": logprobs,
|
|
491
|
+
"max_tokens": max_tokens,
|
|
492
|
+
"n": n,
|
|
493
|
+
"presence_penalty": presence_penalty,
|
|
494
|
+
"reasoning_effort": reasoning_effort,
|
|
495
|
+
"response_format": response_format,
|
|
496
|
+
"seed": seed,
|
|
497
|
+
"stop": stop,
|
|
498
|
+
"stream": stream,
|
|
499
|
+
"stream_options": stream_options,
|
|
500
|
+
"temperature": temperature,
|
|
501
|
+
"tool_choice": tool_choice,
|
|
502
|
+
"tools": tools,
|
|
503
|
+
"top_logprobs": top_logprobs,
|
|
504
|
+
"top_p": top_p,
|
|
505
|
+
"user": user,
|
|
506
|
+
"extra_headers": extra_headers,
|
|
507
|
+
"extra_query": extra_query,
|
|
508
|
+
"extra_body": extra_body,
|
|
509
|
+
"timeout": timeout,
|
|
510
|
+
"parallel_tool_calls": parallel_tool_calls,
|
|
511
|
+
}
|
|
512
|
+
groq_model = False
|
|
513
|
+
if "groq:" in model or "maitai:" in model or "llama" in model:
|
|
514
|
+
groq_model = True
|
|
515
|
+
model = model.replace("groq:", "").replace("maitai:", "")
|
|
473
516
|
if "openai:" in model:
|
|
474
517
|
model = model.replace("openai:", "")
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
518
|
+
|
|
519
|
+
if groq_model:
|
|
520
|
+
if self._groq_client is None:
|
|
521
|
+
if (
|
|
522
|
+
not config.auth_keys.groq_api_key
|
|
523
|
+
or not config.auth_keys.groq_api_key.key_value
|
|
524
|
+
):
|
|
525
|
+
raise ValueError(
|
|
526
|
+
"Groq API key is required for Groq models but was not provided"
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
self._groq_client = groq.AsyncGroq(
|
|
530
|
+
api_key=config.auth_keys.groq_api_key.key_value,
|
|
531
|
+
)
|
|
532
|
+
client_to_use = self._groq_client
|
|
533
|
+
local_params = convert_params_to_groq(local_params)
|
|
534
|
+
else:
|
|
535
|
+
if self._openai_client is None:
|
|
536
|
+
self._openai_client = openai.AsyncOpenAI(
|
|
537
|
+
api_key=config.auth_keys.openai_api_key.key_value,
|
|
538
|
+
default_headers=self._client_params.default_headers or None,
|
|
539
|
+
default_query=self._client_params.default_query or None,
|
|
540
|
+
base_url=self._client_params.base_url or None,
|
|
541
|
+
)
|
|
542
|
+
client_to_use = self._openai_client
|
|
543
|
+
|
|
481
544
|
if hasattr(response_format, "model_json_schema"):
|
|
482
545
|
response_format = {
|
|
483
546
|
"type": "json_schema",
|
|
484
547
|
"json_schema": type_to_response_format_param(response_format),
|
|
485
548
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
functions=functions,
|
|
492
|
-
logit_bias=logit_bias,
|
|
493
|
-
logprobs=logprobs,
|
|
494
|
-
max_tokens=max_tokens,
|
|
495
|
-
n=n,
|
|
496
|
-
presence_penalty=presence_penalty,
|
|
497
|
-
reasoning_effort=reasoning_effort,
|
|
498
|
-
response_format=response_format,
|
|
499
|
-
seed=seed,
|
|
500
|
-
stop=stop,
|
|
501
|
-
stream=stream,
|
|
502
|
-
stream_options=stream_options,
|
|
503
|
-
temperature=temperature,
|
|
504
|
-
tool_choice=tool_choice,
|
|
505
|
-
tools=tools,
|
|
506
|
-
top_logprobs=top_logprobs,
|
|
507
|
-
top_p=top_p,
|
|
508
|
-
user=user,
|
|
509
|
-
extra_headers=extra_headers,
|
|
510
|
-
extra_query=extra_query,
|
|
511
|
-
extra_body=extra_body,
|
|
512
|
-
timeout=timeout,
|
|
513
|
-
parallel_tool_calls=parallel_tool_calls,
|
|
549
|
+
if isinstance(tools, Tools):
|
|
550
|
+
tools = tools.get_tool_definitions()
|
|
551
|
+
|
|
552
|
+
response = await client_to_use.chat.completions.create(
|
|
553
|
+
**local_params,
|
|
514
554
|
)
|
|
515
555
|
if stream:
|
|
516
556
|
return self._process_async_openai_stream(
|
maitai/_maitai_client.py
CHANGED
|
@@ -149,6 +149,8 @@ class MaitaiClient:
|
|
|
149
149
|
|
|
150
150
|
def _log_error(self, api_key: str, error: str, path: str):
|
|
151
151
|
host = self.maitai_host
|
|
152
|
+
if "/batch" in host:
|
|
153
|
+
host = host.replace("/batch", "")
|
|
152
154
|
url = f"{host}/metrics/increment/python_sdk_error"
|
|
153
155
|
headers = {
|
|
154
156
|
"Content-Type": "application/json",
|
|
@@ -168,6 +170,8 @@ class MaitaiClient:
|
|
|
168
170
|
|
|
169
171
|
async def log_error_async(self, api_key: str, error: str, path: str):
|
|
170
172
|
host = self.maitai_host
|
|
173
|
+
if "/batch" in host:
|
|
174
|
+
host = host.replace("/batch", "")
|
|
171
175
|
url = f"{host}/metrics/increment/python_sdk_error"
|
|
172
176
|
headers = {
|
|
173
177
|
"Content-Type": "application/json",
|
|
@@ -187,6 +191,8 @@ class MaitaiClient:
|
|
|
187
191
|
|
|
188
192
|
def init_sdk(self, api_key: str, host: str):
|
|
189
193
|
"""Initialize the SDK and warm up connections."""
|
|
194
|
+
if "/batch" in host:
|
|
195
|
+
host = host.replace("/batch", "")
|
|
190
196
|
url = f"{host}/config/init_sdk"
|
|
191
197
|
headers = {
|
|
192
198
|
"Content-Type": "application/json",
|
maitai/_utils.py
CHANGED
|
@@ -301,3 +301,17 @@ def chat_completion_chunk_to_response(
|
|
|
301
301
|
)
|
|
302
302
|
)
|
|
303
303
|
return chat_completion_response
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def convert_params_to_groq(params: Dict[str, Any]) -> Dict[str, Any]:
|
|
307
|
+
if "reasoning_effort" in params:
|
|
308
|
+
del params["reasoning_effort"]
|
|
309
|
+
if "stream_options" in params:
|
|
310
|
+
del params["stream_options"]
|
|
311
|
+
to_del = []
|
|
312
|
+
for key, item in params.items():
|
|
313
|
+
if item == openai.NOT_GIVEN:
|
|
314
|
+
to_del.append(key)
|
|
315
|
+
for key in to_del:
|
|
316
|
+
del params[key]
|
|
317
|
+
return params
|
maitai/models/chat.py
CHANGED
|
@@ -49,6 +49,7 @@ class Property(BaseModel):
|
|
|
49
49
|
description: Optional[str] = None
|
|
50
50
|
items: Optional["FunctionParameters"] = None
|
|
51
51
|
anyOf: Optional[List["Property"]] = None
|
|
52
|
+
enum: List[str] = Field(default_factory=list)
|
|
52
53
|
|
|
53
54
|
def model_dump(self, **kwargs):
|
|
54
55
|
kwargs.setdefault("exclude_none", True)
|
maitai_common/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: maitai-python
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.23
|
|
4
4
|
Summary: Maitai SDK for Python
|
|
5
5
|
Home-page: https://docs.trymaitai.ai
|
|
6
6
|
Author: Maitai
|
|
@@ -14,6 +14,7 @@ Requires-Dist: httpx[http2]
|
|
|
14
14
|
Requires-Dist: websocket-client
|
|
15
15
|
Requires-Dist: pyhumps
|
|
16
16
|
Requires-Dist: pydantic>=2.0.0
|
|
17
|
+
Requires-Dist: groq
|
|
17
18
|
Dynamic: author
|
|
18
19
|
Dynamic: author-email
|
|
19
20
|
Dynamic: classifier
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
maitai/__init__.py,sha256=UocvQ1455PnA27V1S6vk3yc_BysjTgLGbwfdMF2eL0A,336
|
|
2
|
-
maitai/_config.py,sha256=
|
|
2
|
+
maitai/_config.py,sha256=Rp7dy_g9ZsMsXWvXV52OSRmkBmA6NbNAAPYwKZ6kf-4,7625
|
|
3
3
|
maitai/_config_listener.py,sha256=FhjV84Pugy5h0mlbCSaanKZ4aVpINaEKzMNQmdZhRj4,5140
|
|
4
4
|
maitai/_context.py,sha256=qyxCww-02qvLpJ7dRG_eOkZI2UaCOgLtqkASlb7QbZU,2470
|
|
5
|
-
maitai/_evaluator.py,sha256
|
|
6
|
-
maitai/_inference.py,sha256=
|
|
7
|
-
maitai/_maitai.py,sha256=
|
|
8
|
-
maitai/_maitai_async.py,sha256=
|
|
9
|
-
maitai/_maitai_client.py,sha256=
|
|
5
|
+
maitai/_evaluator.py,sha256=JDcb6xFjUHE28VyGrHxgwD4LVdeDuuOioQd9ZMmOXkI,11363
|
|
6
|
+
maitai/_inference.py,sha256=fcapXkBYv1BLmJQ9vRl8p5tFwnM1ojVRz2X7TZLukPY,12735
|
|
7
|
+
maitai/_maitai.py,sha256=VxgZwBChcFnlTK4bSRMTzSWZsq1z5FQtrCTiEEXlG5E,30179
|
|
8
|
+
maitai/_maitai_async.py,sha256=wzi3dBhLPD4Jkn8N29mVtdudye8lMzCjKGIcj-zQlUs,30442
|
|
9
|
+
maitai/_maitai_client.py,sha256=NmsOYdk2VpDQPuyAZACo7V387ZkEwZZPkpubr3BVs5Q,6392
|
|
10
10
|
maitai/_pydantic.py,sha256=8clflOhR7-6AeLFBzmsYO0aaQSAkp8KMuxsrYwPthaA,5683
|
|
11
11
|
maitai/_types.py,sha256=UL3CMIZ0bc1I6vyGcGxCusxVl-OHsTGUFY8oIBckyEs,5875
|
|
12
|
-
maitai/_utils.py,sha256=
|
|
12
|
+
maitai/_utils.py,sha256=WhVNIA8XyazovRRSCjCIz8Hh2-dKFqsaUNkgn0RVXHI,11375
|
|
13
13
|
maitai/exceptions.py,sha256=n0jwH3dhq8ewdgkCHTaaMd1GeB3EL_zulytnwqD3XUg,500
|
|
14
14
|
maitai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
maitai/models/application.py,sha256=nfddjI5gt56MkSZgvG-EZmsO3JFxpAA5mzPwVoGig10,1656
|
|
16
|
-
maitai/models/chat.py,sha256=
|
|
16
|
+
maitai/models/chat.py,sha256=gY4PHID-xg2soongY69-RGVGvZUgrfjVBLs82-Wx0_M,12881
|
|
17
17
|
maitai/models/config.py,sha256=L798kNl-To-LSzHApy_Tu8JKGJ3KkKA8lvKVTdQujXE,2017
|
|
18
18
|
maitai/models/event.py,sha256=xrwSCP-nVdFsO6F30pmYdSg9M_L1RG-0vj9e_17amEY,313
|
|
19
19
|
maitai/models/inference.py,sha256=lySiDgdsu6IdX7KG8O6orjZokeX5mR4OnLuJFJykY68,516
|
|
@@ -22,10 +22,10 @@ maitai/models/metric.py,sha256=iL1FqaJ-3ii5pgY4cGZKp0nuQVG1XnBggopazQhGN_E,451
|
|
|
22
22
|
maitai/models/sentinel.py,sha256=D1qPhV6GQDRq-JkDtm_lwSXDWFQ1kUjuCw5H6fUvsFg,1802
|
|
23
23
|
maitai/tools/__init__.py,sha256=Fo7tOLJNFbFtVN9LI8fpFUPk95lcq97Pp1TP5-2NU3s,4086
|
|
24
24
|
maitai_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
-
maitai_common/version.py,sha256=
|
|
25
|
+
maitai_common/version.py,sha256=lBJwiSrVcJS0543PYVM0tTUGdfP2afN2Wup4UpbZJeY,65
|
|
26
26
|
maitai_common/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
27
|
maitai_common/config/config_service.py,sha256=CRUz-LYyGxCaDqqkqaJ6CyhpTKr11NKux104oU__NBg,1110
|
|
28
|
-
maitai_python-1.2.
|
|
29
|
-
maitai_python-1.2.
|
|
30
|
-
maitai_python-1.2.
|
|
31
|
-
maitai_python-1.2.
|
|
28
|
+
maitai_python-1.2.23.dist-info/METADATA,sha256=5sL9veoGyeuFYoruczqIM4trMCbwmcLYQuARv97SMto,1682
|
|
29
|
+
maitai_python-1.2.23.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
|
30
|
+
maitai_python-1.2.23.dist-info/top_level.txt,sha256=3uBDd_HUkDZhdPkUjbHJpoKMT3YoYszkUeOLIxgjzUo,21
|
|
31
|
+
maitai_python-1.2.23.dist-info/RECORD,,
|
|
File without changes
|