litellm-proxy-extras 0.1.1__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.1.dist-info → litellm_proxy_extras-0.1.2.dist-info}/METADATA +1 -1
- {litellm_proxy_extras-0.1.1.dist-info → litellm_proxy_extras-0.1.2.dist-info}/RECORD +7 -4
- {litellm_proxy_extras-0.1.1.dist-info → litellm_proxy_extras-0.1.2.dist-info}/LICENSE +0 -0
- {litellm_proxy_extras-0.1.1.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
|
|
@@ -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,10 +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.
|
|
10
|
-
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
|
|
File without changes
|