litellm-proxy-extras 0.1.0__py3-none-any.whl → 0.1.2__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.
Potentially problematic release.
This version of litellm-proxy-extras might be problematic. Click here for more details.
- litellm_proxy_extras/_logging.py +12 -0
- litellm_proxy_extras/migrations/20250331215456_track_success_and_failed_requests_daily_agg_table/migration.sql +4 -0
- litellm_proxy_extras/utils.py +80 -0
- litellm_proxy_extras-0.1.2.dist-info/LICENSE +26 -0
- {litellm_proxy_extras-0.1.0.dist-info → litellm_proxy_extras-0.1.2.dist-info}/METADATA +1 -1
- {litellm_proxy_extras-0.1.0.dist-info → litellm_proxy_extras-0.1.2.dist-info}/RECORD +7 -3
- {litellm_proxy_extras-0.1.0.dist-info → litellm_proxy_extras-0.1.2.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
# Set up package logger
|
|
4
|
+
logger = logging.getLogger("litellm_proxy_extras")
|
|
5
|
+
if not logger.handlers: # Only add handler if none exists
|
|
6
|
+
handler = logging.StreamHandler()
|
|
7
|
+
formatter = logging.Formatter(
|
|
8
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
9
|
+
)
|
|
10
|
+
handler.setFormatter(formatter)
|
|
11
|
+
logger.addHandler(handler)
|
|
12
|
+
logger.setLevel(logging.INFO)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import random
|
|
3
|
+
import subprocess
|
|
4
|
+
import time
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from litellm_proxy_extras._logging import logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def str_to_bool(value: Optional[str]) -> bool:
|
|
11
|
+
if value is None:
|
|
12
|
+
return False
|
|
13
|
+
return value.lower() in ("true", "1", "t", "y", "yes")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ProxyExtrasDBManager:
|
|
17
|
+
@staticmethod
|
|
18
|
+
def setup_database(schema_path: str, use_migrate: bool = False) -> bool:
|
|
19
|
+
"""
|
|
20
|
+
Set up the database using either prisma migrate or prisma db push
|
|
21
|
+
Uses migrations from litellm-proxy-extras package
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
schema_path (str): Path to the Prisma schema file
|
|
25
|
+
use_migrate (bool): Whether to use prisma migrate instead of db push
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
bool: True if setup was successful, False otherwise
|
|
29
|
+
"""
|
|
30
|
+
use_migrate = str_to_bool(os.getenv("USE_PRISMA_MIGRATE")) or use_migrate
|
|
31
|
+
for attempt in range(4):
|
|
32
|
+
original_dir = os.getcwd()
|
|
33
|
+
schema_dir = os.path.dirname(schema_path)
|
|
34
|
+
os.chdir(schema_dir)
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
if use_migrate:
|
|
38
|
+
logger.info("Running prisma migrate deploy")
|
|
39
|
+
try:
|
|
40
|
+
# Set migrations directory for Prisma
|
|
41
|
+
subprocess.run(
|
|
42
|
+
["prisma", "migrate", "deploy"],
|
|
43
|
+
timeout=60,
|
|
44
|
+
check=True,
|
|
45
|
+
capture_output=True,
|
|
46
|
+
text=True,
|
|
47
|
+
)
|
|
48
|
+
logger.info("prisma migrate deploy completed")
|
|
49
|
+
return True
|
|
50
|
+
except subprocess.CalledProcessError as e:
|
|
51
|
+
logger.info(f"prisma db error: {e.stderr}, e: {e.stdout}")
|
|
52
|
+
if (
|
|
53
|
+
"P3005" in e.stderr
|
|
54
|
+
and "database schema is not empty" in e.stderr
|
|
55
|
+
):
|
|
56
|
+
logger.info("Error: Database schema is not empty")
|
|
57
|
+
return False
|
|
58
|
+
else:
|
|
59
|
+
# Use prisma db push with increased timeout
|
|
60
|
+
subprocess.run(
|
|
61
|
+
["prisma", "db", "push", "--accept-data-loss"],
|
|
62
|
+
timeout=60,
|
|
63
|
+
check=True,
|
|
64
|
+
)
|
|
65
|
+
return True
|
|
66
|
+
except subprocess.TimeoutExpired:
|
|
67
|
+
logger.info(f"Attempt {attempt + 1} timed out")
|
|
68
|
+
time.sleep(random.randrange(5, 15))
|
|
69
|
+
except subprocess.CalledProcessError as e:
|
|
70
|
+
attempts_left = 3 - attempt
|
|
71
|
+
retry_msg = (
|
|
72
|
+
f" Retrying... ({attempts_left} attempts left)"
|
|
73
|
+
if attempts_left > 0
|
|
74
|
+
else ""
|
|
75
|
+
)
|
|
76
|
+
logger.info(f"The process failed to execute. Details: {e}.{retry_msg}")
|
|
77
|
+
time.sleep(random.randrange(5, 15))
|
|
78
|
+
finally:
|
|
79
|
+
os.chdir(original_dir)
|
|
80
|
+
return False
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
* All content that resides under the "enterprise/" directory of this repository, if that directory exists, is licensed under the license defined in "enterprise/LICENSE".
|
|
4
|
+
* Content outside of the above mentioned directories or restrictions above is available under the MIT license as defined below.
|
|
5
|
+
---
|
|
6
|
+
MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2023 Berri AI
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: litellm-proxy-extras
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Additional files for the LiteLLM Proxy. Reduces the size of the main litellm package.
|
|
5
5
|
Author: BerriAI
|
|
6
6
|
Requires-Python: >=3.8, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
litellm_proxy_extras/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
litellm_proxy_extras/_logging.py,sha256=7KoWerTOol5IPNyNdbZvLuSlpQbEGE235VgzwpgafKQ,393
|
|
2
3
|
litellm_proxy_extras/migrations/20250326162113_baseline/migration.sql,sha256=9aRWmBbLf7EWbCMXifDl5zL9bAw0uPXJut1AXNKrSTE,13383
|
|
3
4
|
litellm_proxy_extras/migrations/20250326171002_add_daily_user_table/migration.sql,sha256=dY-dNCLosWmXNli2B9wqX4hZpp3s0DL3IwEPtTTC134,1179
|
|
4
5
|
litellm_proxy_extras/migrations/20250327180120_add_api_requests_to_daily_user_table/migration.sql,sha256=or5TaEgH4cHwR5kDvVjZvcAj1OwzTxjqwO-lxXe3FXk,110
|
|
5
6
|
litellm_proxy_extras/migrations/20250329084805_new_cron_job_table/migration.sql,sha256=eZNDwrzKtWFXkTqOKb9JS4hzum1dI-VTXvMqzhryfxc,404
|
|
7
|
+
litellm_proxy_extras/migrations/20250331215456_track_success_and_failed_requests_daily_agg_table/migration.sql,sha256=tyeLY6u8KFyw71osCBM-sdjhIgvHoFCK88cIx8dExNY,178
|
|
6
8
|
litellm_proxy_extras/migrations/migration_lock.toml,sha256=HbF6jQUaoTYRBzZ1LF4fi37ZK26o6AMRL7viSXBHwhA,24
|
|
7
|
-
litellm_proxy_extras
|
|
8
|
-
litellm_proxy_extras-0.1.
|
|
9
|
-
litellm_proxy_extras-0.1.
|
|
9
|
+
litellm_proxy_extras/utils.py,sha256=09w_J9nsHS_GhPNs1tjJqVBYhGh6OUDI4p8Vld4Xv6w,3081
|
|
10
|
+
litellm_proxy_extras-0.1.2.dist-info/LICENSE,sha256=sXDWv46INd01fgEWgdsCj01R4vsOqJIFj1bgH7ObgnM,1419
|
|
11
|
+
litellm_proxy_extras-0.1.2.dist-info/METADATA,sha256=U2Pin4dmmX-JrndTt4RwWoCd7buX5Eg04pP90vS5iNE,1267
|
|
12
|
+
litellm_proxy_extras-0.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
13
|
+
litellm_proxy_extras-0.1.2.dist-info/RECORD,,
|
|
File without changes
|