maitai-python 1.2.21__tar.gz → 1.2.23__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.
Files changed (36) hide show
  1. {maitai_python-1.2.21 → maitai_python-1.2.23}/PKG-INFO +2 -1
  2. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_config.py +13 -0
  3. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_evaluator.py +0 -6
  4. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_inference.py +4 -0
  5. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_maitai.py +80 -43
  6. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_maitai_async.py +83 -42
  7. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_maitai_client.py +36 -17
  8. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_utils.py +14 -0
  9. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/chat.py +1 -0
  10. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_common/version.py +1 -1
  11. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_python.egg-info/PKG-INFO +2 -1
  12. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_python.egg-info/requires.txt +1 -0
  13. {maitai_python-1.2.21 → maitai_python-1.2.23}/setup.py +1 -0
  14. {maitai_python-1.2.21 → maitai_python-1.2.23}/README.md +0 -0
  15. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/__init__.py +0 -0
  16. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_config_listener.py +0 -0
  17. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_context.py +0 -0
  18. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_pydantic.py +0 -0
  19. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/_types.py +0 -0
  20. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/exceptions.py +0 -0
  21. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/__init__.py +0 -0
  22. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/application.py +0 -0
  23. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/config.py +0 -0
  24. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/event.py +0 -0
  25. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/inference.py +0 -0
  26. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/key.py +0 -0
  27. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/metric.py +0 -0
  28. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/models/sentinel.py +0 -0
  29. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai/tools/__init__.py +0 -0
  30. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_common/__init__.py +0 -0
  31. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_common/config/__init__.py +0 -0
  32. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_common/config/config_service.py +0 -0
  33. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_python.egg-info/SOURCES.txt +0 -0
  34. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_python.egg-info/dependency_links.txt +0 -0
  35. {maitai_python-1.2.21 → maitai_python-1.2.23}/maitai_python.egg-info/top_level.txt +0 -0
  36. {maitai_python-1.2.21 → maitai_python-1.2.23}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maitai-python
3
- Version: 1.2.21
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
@@ -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):
@@ -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
@@ -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",
@@ -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._client = None
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._client = openai.AzureOpenAI(
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._client = openai.OpenAI(
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._client, client_params)
195
+ self.chat = Chat(self._openai_client, self._groq_client, client_params)
188
196
 
189
197
 
190
198
  class Chat:
191
- def __init__(self, client=None, client_params: ClientParams = None):
192
- self.completions = Completions(client, client_params)
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
- client: Optional[openai.Client] = None,
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._client = client
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
- if self._client is None:
476
- self._client = openai.OpenAI(
477
- default_query=self._client_params.default_query or None,
478
- default_headers=self._client_params.default_headers or None,
479
- base_url=self._client_params.base_url or None,
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 = self._client.chat.completions.create(
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,
@@ -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,14 +137,16 @@ class MaitaiAsync:
135
137
  )
136
138
  else:
137
139
  config.auth_keys.gemini_api_key.key_value = gemini_api_key
138
- self._client = None
140
+ self._openai_client = None
141
+ self._groq_client = None
142
+ azure_params = None
139
143
  if azure_api_key:
140
144
  azure_params = AzureParams(
141
145
  endpoint=azure_endpoint,
142
146
  deployment=azure_deployment,
143
147
  api_version=azure_api_version,
144
148
  )
145
- self._client = openai.AsyncAzureOpenAI(
149
+ self._openai_client = openai.AsyncAzureOpenAI(
146
150
  azure_endpoint=azure_endpoint,
147
151
  azure_deployment=azure_deployment,
148
152
  api_key=azure_api_key,
@@ -158,7 +162,7 @@ class MaitaiAsync:
158
162
  _strict_response_validation=_strict_response_validation,
159
163
  )
160
164
  elif openai_api_key or os.environ.get("OPENAI_API_KEY"):
161
- self._client = openai.AsyncClient(
165
+ self._openai_client = openai.AsyncClient(
162
166
  api_key=openai_api_key or os.environ.get("OPENAI_API_KEY"),
163
167
  organization=organization,
164
168
  project=project,
@@ -170,6 +174,10 @@ class MaitaiAsync:
170
174
  http_client=http_client,
171
175
  _strict_response_validation=_strict_response_validation,
172
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
+ )
173
181
 
174
182
  client_params = None
175
183
  if base_url or default_headers or default_query:
@@ -179,25 +187,28 @@ class MaitaiAsync:
179
187
  default_query=default_query or {},
180
188
  azure_params=azure_params,
181
189
  )
182
- self.chat = AsyncChat(self._client, client_params)
190
+ self.chat = AsyncChat(self._openai_client, self._groq_client, client_params)
183
191
 
184
192
 
185
193
  class AsyncChat:
186
194
  def __init__(
187
195
  self,
188
- client=None,
196
+ openai_client=None,
197
+ groq_client=None,
189
198
  client_params: ClientParams = None,
190
199
  ):
191
- self.completions = AsyncCompletions(client, client_params)
200
+ self.completions = AsyncCompletions(openai_client, groq_client, client_params)
192
201
 
193
202
 
194
203
  class AsyncCompletions:
195
204
  def __init__(
196
205
  self,
197
- client: Optional[openai.AsyncClient] = None,
206
+ openai_client: Optional[openai.AsyncClient] = None,
207
+ groq_client: Optional[groq.AsyncGroq] = None,
198
208
  client_params: Optional[ClientParams] = None,
199
209
  ):
200
- self._client = client
210
+ self._openai_client = openai_client
211
+ self._groq_client = groq_client
201
212
  self._client_params = client_params or ClientParams()
202
213
  self.inference_client = Inference()
203
214
  self.evaluator = Evaluator()
@@ -469,47 +480,77 @@ class AsyncCompletions:
469
480
  logger.warning("Maitai issue, retrying on client side")
470
481
  server_side_inference = False
471
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:", "")
472
516
  if "openai:" in model:
473
517
  model = model.replace("openai:", "")
474
- if self._client is None:
475
- self._client = openai.AsyncOpenAI(
476
- default_headers=self._client_params.default_headers or None,
477
- default_query=self._client_params.default_query or None,
478
- base_url=self._client_params.base_url or None,
479
- )
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
+
480
544
  if hasattr(response_format, "model_json_schema"):
481
545
  response_format = {
482
546
  "type": "json_schema",
483
547
  "json_schema": type_to_response_format_param(response_format),
484
548
  }
485
- response = await self._client.chat.completions.create(
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,
549
+ if isinstance(tools, Tools):
550
+ tools = tools.get_tool_definitions()
551
+
552
+ response = await client_to_use.chat.completions.create(
553
+ **local_params,
513
554
  )
514
555
  if stream:
515
556
  return self._process_async_openai_stream(
@@ -5,6 +5,21 @@ import httpx
5
5
 
6
6
  from maitai_common.version import version
7
7
 
8
+ # Common client settings to ensure consistency
9
+ CLIENT_SETTINGS = {
10
+ "http2": True,
11
+ "limits": httpx.Limits(
12
+ max_keepalive_connections=200,
13
+ max_connections=1000,
14
+ ),
15
+ "timeout": httpx.Timeout(timeout=600, connect=5.0),
16
+ "follow_redirects": True,
17
+ }
18
+
19
+ # In _base_client.py, they define DEFAULT_MAX_RETRIES = 2
20
+ # We'll incorporate that into our transport settings
21
+ DEFAULT_MAX_RETRIES = 2
22
+
8
23
 
9
24
  def _get_aws_instance_metadata(url, timeout=2):
10
25
  try:
@@ -93,37 +108,27 @@ class MaitaiClient:
93
108
  def get_client(self):
94
109
  if self._client is None:
95
110
  self._client = httpx.Client(
96
- http2=True,
97
- limits=httpx.Limits(
98
- max_keepalive_connections=200,
99
- max_connections=1000,
100
- keepalive_expiry=300,
101
- ),
102
- transport=httpx.HTTPTransport(retries=3),
111
+ **CLIENT_SETTINGS,
112
+ transport=httpx.HTTPTransport(retries=DEFAULT_MAX_RETRIES),
103
113
  )
104
114
  return self._client
105
115
 
106
116
  async def get_async_client(self):
107
117
  if self._async_client is None:
108
118
  self._async_client = httpx.AsyncClient(
109
- http2=True,
110
- limits=httpx.Limits(
111
- max_keepalive_connections=200,
112
- max_connections=1000,
113
- keepalive_expiry=300,
114
- ),
115
- transport=httpx.AsyncHTTPTransport(retries=3),
119
+ **CLIENT_SETTINGS,
120
+ transport=httpx.AsyncHTTPTransport(retries=DEFAULT_MAX_RETRIES),
116
121
  )
117
122
  return self._async_client
118
123
 
119
124
  def cleanup(self):
120
125
  try:
121
126
  self.executor.shutdown()
122
- except Exception as e:
127
+ except Exception:
123
128
  pass
124
129
  try:
125
130
  self.close_client()
126
- except Exception as e:
131
+ except Exception:
127
132
  pass
128
133
 
129
134
  def close_client(self):
@@ -131,6 +136,11 @@ class MaitaiClient:
131
136
  self._client.close()
132
137
  self._client = None
133
138
 
139
+ async def close_async_client(self):
140
+ if self._async_client:
141
+ await self._async_client.aclose()
142
+ self._async_client = None
143
+
134
144
  def __del__(self):
135
145
  self.cleanup()
136
146
 
@@ -139,6 +149,8 @@ class MaitaiClient:
139
149
 
140
150
  def _log_error(self, api_key: str, error: str, path: str):
141
151
  host = self.maitai_host
152
+ if "/batch" in host:
153
+ host = host.replace("/batch", "")
142
154
  url = f"{host}/metrics/increment/python_sdk_error"
143
155
  headers = {
144
156
  "Content-Type": "application/json",
@@ -158,6 +170,8 @@ class MaitaiClient:
158
170
 
159
171
  async def log_error_async(self, api_key: str, error: str, path: str):
160
172
  host = self.maitai_host
173
+ if "/batch" in host:
174
+ host = host.replace("/batch", "")
161
175
  url = f"{host}/metrics/increment/python_sdk_error"
162
176
  headers = {
163
177
  "Content-Type": "application/json",
@@ -176,6 +190,9 @@ class MaitaiClient:
176
190
  pass
177
191
 
178
192
  def init_sdk(self, api_key: str, host: str):
193
+ """Initialize the SDK and warm up connections."""
194
+ if "/batch" in host:
195
+ host = host.replace("/batch", "")
179
196
  url = f"{host}/config/init_sdk"
180
197
  headers = {
181
198
  "Content-Type": "application/json",
@@ -183,7 +200,9 @@ class MaitaiClient:
183
200
  "User-Agent": version,
184
201
  }
185
202
 
186
- response = httpx.get(url, headers=headers, timeout=15)
203
+ # Get the shared client to warm up connections
204
+ client = self.get_client()
205
+ response = client.get(url, headers=headers, timeout=15)
187
206
  if response.status_code != 200:
188
207
  raise Exception(f"Failed to initialize Maitai client: {response.text}")
189
208
  return response.json()
@@ -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
@@ -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)
@@ -1,3 +1,3 @@
1
- version = "1.2.21"
1
+ version = "1.2.23"
2
2
  if __name__ == "__main__":
3
3
  print(version)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maitai-python
3
- Version: 1.2.21
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
@@ -3,3 +3,4 @@ httpx[http2]
3
3
  websocket-client
4
4
  pyhumps
5
5
  pydantic>=2.0.0
6
+ groq
@@ -31,6 +31,7 @@ setup(
31
31
  "websocket-client",
32
32
  "pyhumps",
33
33
  "pydantic>=2.0.0",
34
+ "groq",
34
35
  ],
35
36
  # Optional metadata
36
37
  author="Maitai",
File without changes
File without changes