maitai-python 1.2.23b0__tar.gz → 1.2.25__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.23b0 → maitai_python-1.2.25}/PKG-INFO +1 -1
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_config.py +1 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_inference.py +6 -2
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_maitai.py +17 -14
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_maitai_async.py +15 -13
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_maitai_client.py +4 -41
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_utils.py +3 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/chat.py +4 -1
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/key.py +2 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_common/config/config_service.py +1 -1
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_common/version.py +1 -1
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/README.md +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/__init__.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_config_listener.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_context.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_evaluator.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_pydantic.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/_types.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/exceptions.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/__init__.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/application.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/config.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/event.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/inference.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/metric.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/models/sentinel.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_common/__init__.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/setup.cfg +0 -0
- {maitai_python-1.2.23b0 → maitai_python-1.2.25}/setup.py +0 -0
|
@@ -32,6 +32,7 @@ class Config(MaitaiClient):
|
|
|
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
34
|
azure_api_key=Key(id=-1, key_value=os.environ.get("AZURE_API_KEY")),
|
|
35
|
+
deepseek_api_key=Key(id=-1, key_value=os.environ.get("DEEPSEEK_API_KEY")),
|
|
35
36
|
)
|
|
36
37
|
self.refresh_interval = 30 * 60 # 30 minutes in seconds
|
|
37
38
|
|
|
@@ -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
|
|
|
@@ -68,6 +68,7 @@ class Maitai:
|
|
|
68
68
|
azure_api_key: Optional[str] = None,
|
|
69
69
|
sambanova_api_key: Optional[str] = None,
|
|
70
70
|
gemini_api_key: Optional[str] = None,
|
|
71
|
+
deepseek_api_key: Optional[str] = None,
|
|
71
72
|
azure_deployment: Optional[str] = None,
|
|
72
73
|
azure_api_version: Optional[str] = None,
|
|
73
74
|
azure_endpoint: Optional[str] = None,
|
|
@@ -91,7 +92,7 @@ class Maitai:
|
|
|
91
92
|
)
|
|
92
93
|
if api_key:
|
|
93
94
|
raise ValueError(
|
|
94
|
-
"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"
|
|
95
|
+
"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"
|
|
95
96
|
)
|
|
96
97
|
if openai_api_key:
|
|
97
98
|
if not config.auth_keys.openai_api_key:
|
|
@@ -142,6 +143,13 @@ class Maitai:
|
|
|
142
143
|
)
|
|
143
144
|
else:
|
|
144
145
|
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
146
|
+
if deepseek_api_key:
|
|
147
|
+
if not config.auth_keys.deepseek_api_key:
|
|
148
|
+
config.auth_keys.deepseek_api_key = Key(
|
|
149
|
+
key_value=deepseek_api_key,
|
|
150
|
+
)
|
|
151
|
+
else:
|
|
152
|
+
config.auth_keys.deepseek_api_key.key_value = deepseek_api_key
|
|
145
153
|
self._openai_client = None
|
|
146
154
|
self._groq_client = None
|
|
147
155
|
azure_params = None
|
|
@@ -482,6 +490,13 @@ class Completions:
|
|
|
482
490
|
logger.warning("Maitai issue, retrying on client side")
|
|
483
491
|
server_side_inference = False
|
|
484
492
|
if not server_side_inference:
|
|
493
|
+
groq_model = False
|
|
494
|
+
if "groq:" in model or "maitai:" in model or "llama" in model:
|
|
495
|
+
groq_model = True
|
|
496
|
+
model = model.replace("groq:", "").replace("maitai:", "")
|
|
497
|
+
if "openai:" in model:
|
|
498
|
+
model = model.replace("openai:", "")
|
|
499
|
+
|
|
485
500
|
local_params = {
|
|
486
501
|
"messages": messages,
|
|
487
502
|
"model": model,
|
|
@@ -511,12 +526,6 @@ class Completions:
|
|
|
511
526
|
"timeout": timeout,
|
|
512
527
|
"parallel_tool_calls": parallel_tool_calls,
|
|
513
528
|
}
|
|
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:", "")
|
|
518
|
-
if "openai:" in model:
|
|
519
|
-
model = model.replace("openai:", "")
|
|
520
529
|
|
|
521
530
|
if groq_model:
|
|
522
531
|
if self._groq_client is None:
|
|
@@ -690,13 +699,7 @@ class Completions:
|
|
|
690
699
|
if chunk.choices and chunk.choices[0].finish_reason:
|
|
691
700
|
timing.time_request_end = time.time()
|
|
692
701
|
self.inference.store_request_timing_data(timing)
|
|
693
|
-
if chunk.
|
|
694
|
-
return
|
|
695
|
-
if (
|
|
696
|
-
not includes_usage
|
|
697
|
-
and chunk.choices
|
|
698
|
-
and chunk.choices[0].finish_reason
|
|
699
|
-
):
|
|
702
|
+
if chunk.choices and chunk.choices[0].finish_reason:
|
|
700
703
|
return
|
|
701
704
|
except MaitaiConnectionError as e:
|
|
702
705
|
if "gpt" not in retry_args.get("model", "") and "gpt" in (
|
|
@@ -67,6 +67,7 @@ class MaitaiAsync:
|
|
|
67
67
|
cerebras_api_key: Optional[str] = None,
|
|
68
68
|
sambanova_api_key: Optional[str] = None,
|
|
69
69
|
gemini_api_key: Optional[str] = None,
|
|
70
|
+
deepseek_api_key: Optional[str] = None,
|
|
70
71
|
azure_api_key: Optional[str] = None,
|
|
71
72
|
azure_deployment: Optional[str] = None,
|
|
72
73
|
azure_api_version: Optional[str] = None,
|
|
@@ -137,6 +138,13 @@ class MaitaiAsync:
|
|
|
137
138
|
)
|
|
138
139
|
else:
|
|
139
140
|
config.auth_keys.gemini_api_key.key_value = gemini_api_key
|
|
141
|
+
if deepseek_api_key:
|
|
142
|
+
if not config.auth_keys.deepseek_api_key:
|
|
143
|
+
config.auth_keys.deepseek_api_key = Key(
|
|
144
|
+
key_value=deepseek_api_key,
|
|
145
|
+
)
|
|
146
|
+
else:
|
|
147
|
+
config.auth_keys.deepseek_api_key.key_value = deepseek_api_key
|
|
140
148
|
self._openai_client = None
|
|
141
149
|
self._groq_client = None
|
|
142
150
|
azure_params = None
|
|
@@ -480,6 +488,12 @@ class AsyncCompletions:
|
|
|
480
488
|
logger.warning("Maitai issue, retrying on client side")
|
|
481
489
|
server_side_inference = False
|
|
482
490
|
if not server_side_inference:
|
|
491
|
+
groq_model = False
|
|
492
|
+
if "groq:" in model or "maitai:" in model or "llama" in model:
|
|
493
|
+
groq_model = True
|
|
494
|
+
model = model.replace("groq:", "").replace("maitai:", "")
|
|
495
|
+
if "openai:" in model:
|
|
496
|
+
model = model.replace("openai:", "")
|
|
483
497
|
local_params = {
|
|
484
498
|
"messages": messages,
|
|
485
499
|
"model": model,
|
|
@@ -509,12 +523,6 @@ class AsyncCompletions:
|
|
|
509
523
|
"timeout": timeout,
|
|
510
524
|
"parallel_tool_calls": parallel_tool_calls,
|
|
511
525
|
}
|
|
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:", "")
|
|
516
|
-
if "openai:" in model:
|
|
517
|
-
model = model.replace("openai:", "")
|
|
518
526
|
|
|
519
527
|
if groq_model:
|
|
520
528
|
if self._groq_client is None:
|
|
@@ -694,13 +702,7 @@ class AsyncCompletions:
|
|
|
694
702
|
asyncio.create_task(
|
|
695
703
|
self.inference_client.send_request_timing_data_async(timing)
|
|
696
704
|
)
|
|
697
|
-
if chunk.
|
|
698
|
-
return
|
|
699
|
-
if (
|
|
700
|
-
not includes_usage
|
|
701
|
-
and chunk.choices
|
|
702
|
-
and chunk.choices[0].finish_reason
|
|
703
|
-
):
|
|
705
|
+
if chunk.choices and chunk.choices[0].finish_reason:
|
|
704
706
|
return
|
|
705
707
|
except MaitaiConnectionError as e:
|
|
706
708
|
if "gpt" not in retry_args.get("model", "") and "gpt" in (
|
|
@@ -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
|
|
|
@@ -308,6 +308,9 @@ def convert_params_to_groq(params: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
308
308
|
del params["reasoning_effort"]
|
|
309
309
|
if "stream_options" in params:
|
|
310
310
|
del params["stream_options"]
|
|
311
|
+
if params.get("max_tokens", openai.NOT_GIVEN) == openai.NOT_GIVEN or params.get("max_tokens", 0) <= 0:
|
|
312
|
+
## max_tokens must be positive
|
|
313
|
+
params["max_tokens"] = 1000
|
|
311
314
|
to_del = []
|
|
312
315
|
for key, item in params.items():
|
|
313
316
|
if item == openai.NOT_GIVEN:
|
|
@@ -18,6 +18,8 @@ class EvaluationProvider(Enum):
|
|
|
18
18
|
MAITAI = 3
|
|
19
19
|
SAMBANOVA = 4
|
|
20
20
|
GEMINI = 5
|
|
21
|
+
DEEPSEEK = 6
|
|
22
|
+
ANTHROPIC = 7
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
class AzureParams(BaseModel):
|
|
@@ -42,6 +44,7 @@ class ChatCompletionAuth(BaseModel):
|
|
|
42
44
|
azure_api_key: Optional[str] = ""
|
|
43
45
|
sambanova_api_key: Optional[str] = ""
|
|
44
46
|
gemini_api_key: Optional[str] = ""
|
|
47
|
+
deepseek_api_key: Optional[str] = ""
|
|
45
48
|
|
|
46
49
|
|
|
47
50
|
class Property(BaseModel):
|
|
@@ -82,7 +85,7 @@ class Tool(BaseModel):
|
|
|
82
85
|
|
|
83
86
|
|
|
84
87
|
class JSONSchema(BaseModel):
|
|
85
|
-
name: str
|
|
88
|
+
name: str = "output_schema"
|
|
86
89
|
strict: Optional[bool] = False
|
|
87
90
|
json_schema: FunctionParameters = Field(alias="schema")
|
|
88
91
|
|
|
@@ -24,6 +24,7 @@ class KeyIdMap(BaseModel):
|
|
|
24
24
|
azure_api_key: Optional[int] = 0
|
|
25
25
|
sambanova_api_key: Optional[int] = 0
|
|
26
26
|
gemini_api_key: Optional[int] = 0
|
|
27
|
+
deepseek_api_key: Optional[int] = 0
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
class KeyMap(BaseModel):
|
|
@@ -34,6 +35,7 @@ class KeyMap(BaseModel):
|
|
|
34
35
|
azure_api_key: Optional[Key] = None
|
|
35
36
|
sambanova_api_key: Optional[Key] = None
|
|
36
37
|
gemini_api_key: Optional[Key] = None
|
|
38
|
+
deepseek_api_key: Optional[Key] = None
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
Key.model_rebuild()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
|
-
if os.environ.get("MAITAI_ENV") in ["prod", "staging", "development"]:
|
|
3
|
+
if os.environ.get("MAITAI_ENV") in ["prod", "staging", "development", "test"]:
|
|
4
4
|
from maitai_models.config import Config, InferenceLocations
|
|
5
5
|
else:
|
|
6
6
|
from maitai.models.config import Config, InferenceLocations
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|