litellm-proxy-extras 0.1.12__tar.gz → 0.1.13__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.
Potentially problematic release.
This version of litellm-proxy-extras might be problematic. Click here for more details.
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/PKG-INFO +1 -1
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/utils.py +123 -16
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/pyproject.toml +2 -2
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/LICENSE +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/README.md +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/__init__.py +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/_logging.py +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250326162113_baseline/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250326171002_add_daily_user_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250327180120_add_api_requests_to_daily_user_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250329084805_new_cron_job_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250331215456_track_success_and_failed_requests_daily_agg_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250411215431_add_managed_file_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250412081753_team_member_permissions/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250415151647_add_cache_read_write_tokens_daily_spend_transactions/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250415191926_add_daily_team_table/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250416115320_add_tag_table_to_db/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250416151339_drop_tag_uniqueness_requirement/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250416185146_add_allowed_routes_litellm_verification_token/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/20250425182129_add_session_id/migration.sql +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/migrations/migration_lock.toml +0 -0
- {litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/schema.prisma +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: litellm-proxy-extras
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.13
|
|
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.*
|
|
@@ -2,8 +2,10 @@ import glob
|
|
|
2
2
|
import os
|
|
3
3
|
import random
|
|
4
4
|
import re
|
|
5
|
+
import shutil
|
|
5
6
|
import subprocess
|
|
6
7
|
import time
|
|
8
|
+
from datetime import datetime
|
|
7
9
|
from pathlib import Path
|
|
8
10
|
from typing import Optional
|
|
9
11
|
|
|
@@ -19,9 +21,30 @@ def str_to_bool(value: Optional[str]) -> bool:
|
|
|
19
21
|
class ProxyExtrasDBManager:
|
|
20
22
|
@staticmethod
|
|
21
23
|
def _get_prisma_dir() -> str:
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
"""
|
|
25
|
+
Get the path to the migrations directory
|
|
26
|
+
|
|
27
|
+
Set os.environ["LITELLM_MIGRATION_DIR"] to a custom migrations directory, to support baselining db in read-only fs.
|
|
28
|
+
"""
|
|
29
|
+
custom_migrations_dir = os.getenv("LITELLM_MIGRATION_DIR")
|
|
30
|
+
pkg_migrations_dir = os.path.dirname(__file__)
|
|
31
|
+
if custom_migrations_dir:
|
|
32
|
+
# If migrations_dir exists, copy contents
|
|
33
|
+
if os.path.exists(custom_migrations_dir):
|
|
34
|
+
# Copy contents instead of directory itself
|
|
35
|
+
for item in os.listdir(pkg_migrations_dir):
|
|
36
|
+
src_path = os.path.join(pkg_migrations_dir, item)
|
|
37
|
+
dst_path = os.path.join(custom_migrations_dir, item)
|
|
38
|
+
if os.path.isdir(src_path):
|
|
39
|
+
shutil.copytree(src_path, dst_path, dirs_exist_ok=True)
|
|
40
|
+
else:
|
|
41
|
+
shutil.copy2(src_path, dst_path)
|
|
42
|
+
else:
|
|
43
|
+
# If directory doesn't exist, create it and copy everything
|
|
44
|
+
shutil.copytree(pkg_migrations_dir, custom_migrations_dir)
|
|
45
|
+
return custom_migrations_dir
|
|
46
|
+
|
|
47
|
+
return pkg_migrations_dir
|
|
25
48
|
|
|
26
49
|
@staticmethod
|
|
27
50
|
def _create_baseline_migration(schema_path: str) -> bool:
|
|
@@ -33,27 +56,29 @@ class ProxyExtrasDBManager:
|
|
|
33
56
|
# Create migrations/0_init directory
|
|
34
57
|
init_dir.mkdir(parents=True, exist_ok=True)
|
|
35
58
|
|
|
36
|
-
|
|
37
|
-
migration_file = init_dir / "migration.sql"
|
|
59
|
+
database_url = os.getenv("DATABASE_URL")
|
|
38
60
|
|
|
39
61
|
try:
|
|
40
|
-
# Generate migration
|
|
62
|
+
# 1. Generate migration SQL file by comparing empty state to current db state
|
|
63
|
+
logger.info("Generating baseline migration...")
|
|
64
|
+
migration_file = init_dir / "migration.sql"
|
|
41
65
|
subprocess.run(
|
|
42
66
|
[
|
|
43
67
|
"prisma",
|
|
44
68
|
"migrate",
|
|
45
69
|
"diff",
|
|
46
70
|
"--from-empty",
|
|
47
|
-
"--to-
|
|
48
|
-
|
|
71
|
+
"--to-url",
|
|
72
|
+
database_url,
|
|
49
73
|
"--script",
|
|
50
74
|
],
|
|
51
75
|
stdout=open(migration_file, "w"),
|
|
52
76
|
check=True,
|
|
53
77
|
timeout=30,
|
|
54
|
-
)
|
|
78
|
+
)
|
|
55
79
|
|
|
56
|
-
# Mark migration as applied
|
|
80
|
+
# 3. Mark the migration as applied since it represents current state
|
|
81
|
+
logger.info("Marking baseline migration as applied...")
|
|
57
82
|
subprocess.run(
|
|
58
83
|
[
|
|
59
84
|
"prisma",
|
|
@@ -73,8 +98,10 @@ class ProxyExtrasDBManager:
|
|
|
73
98
|
)
|
|
74
99
|
return False
|
|
75
100
|
except subprocess.CalledProcessError as e:
|
|
76
|
-
logger.warning(
|
|
77
|
-
|
|
101
|
+
logger.warning(
|
|
102
|
+
f"Error creating baseline migration: {e}, {e.stderr}, {e.stdout}"
|
|
103
|
+
)
|
|
104
|
+
raise e
|
|
78
105
|
|
|
79
106
|
@staticmethod
|
|
80
107
|
def _get_migration_names(migrations_dir: str) -> list:
|
|
@@ -104,8 +131,85 @@ class ProxyExtrasDBManager:
|
|
|
104
131
|
)
|
|
105
132
|
|
|
106
133
|
@staticmethod
|
|
107
|
-
def _resolve_all_migrations(migrations_dir: str):
|
|
108
|
-
"""
|
|
134
|
+
def _resolve_all_migrations(migrations_dir: str, schema_path: str):
|
|
135
|
+
"""
|
|
136
|
+
1. Compare the current database state to schema.prisma and generate a migration for the diff.
|
|
137
|
+
2. Run prisma migrate deploy to apply any pending migrations.
|
|
138
|
+
3. Mark all existing migrations as applied.
|
|
139
|
+
"""
|
|
140
|
+
database_url = os.getenv("DATABASE_URL")
|
|
141
|
+
diff_dir = (
|
|
142
|
+
Path(migrations_dir)
|
|
143
|
+
/ "migrations"
|
|
144
|
+
/ f"{datetime.now().strftime('%Y%m%d%H%M%S')}_baseline_diff"
|
|
145
|
+
)
|
|
146
|
+
try:
|
|
147
|
+
diff_dir.mkdir(parents=True, exist_ok=True)
|
|
148
|
+
except Exception as e:
|
|
149
|
+
if "Permission denied" in str(e):
|
|
150
|
+
logger.warning(
|
|
151
|
+
f"Permission denied - {e}\nunable to baseline db. Set LITELLM_MIGRATION_DIR environment variable to a writable directory to enable migrations."
|
|
152
|
+
)
|
|
153
|
+
return
|
|
154
|
+
raise e
|
|
155
|
+
diff_sql_path = diff_dir / "migration.sql"
|
|
156
|
+
|
|
157
|
+
# 1. Generate migration SQL for the diff between DB and schema
|
|
158
|
+
try:
|
|
159
|
+
logger.info("Generating migration diff between DB and schema.prisma...")
|
|
160
|
+
with open(diff_sql_path, "w") as f:
|
|
161
|
+
subprocess.run(
|
|
162
|
+
[
|
|
163
|
+
"prisma",
|
|
164
|
+
"migrate",
|
|
165
|
+
"diff",
|
|
166
|
+
"--from-url",
|
|
167
|
+
database_url,
|
|
168
|
+
"--to-schema-datamodel",
|
|
169
|
+
schema_path,
|
|
170
|
+
"--script",
|
|
171
|
+
],
|
|
172
|
+
check=True,
|
|
173
|
+
timeout=60,
|
|
174
|
+
stdout=f,
|
|
175
|
+
)
|
|
176
|
+
except subprocess.CalledProcessError as e:
|
|
177
|
+
logger.warning(f"Failed to generate migration diff: {e.stderr}")
|
|
178
|
+
except subprocess.TimeoutExpired:
|
|
179
|
+
logger.warning("Migration diff generation timed out.")
|
|
180
|
+
|
|
181
|
+
# check if the migration was created
|
|
182
|
+
if not diff_sql_path.exists():
|
|
183
|
+
logger.warning("Migration diff was not created")
|
|
184
|
+
return
|
|
185
|
+
logger.info(f"Migration diff created at {diff_sql_path}")
|
|
186
|
+
|
|
187
|
+
# 2. Run prisma db execute to apply the migration
|
|
188
|
+
try:
|
|
189
|
+
logger.info("Running prisma db execute to apply the migration diff...")
|
|
190
|
+
result = subprocess.run(
|
|
191
|
+
[
|
|
192
|
+
"prisma",
|
|
193
|
+
"db",
|
|
194
|
+
"execute",
|
|
195
|
+
"--file",
|
|
196
|
+
str(diff_sql_path),
|
|
197
|
+
"--schema",
|
|
198
|
+
schema_path,
|
|
199
|
+
],
|
|
200
|
+
timeout=60,
|
|
201
|
+
check=True,
|
|
202
|
+
capture_output=True,
|
|
203
|
+
text=True,
|
|
204
|
+
)
|
|
205
|
+
logger.info(f"prisma db execute stdout: {result.stdout}")
|
|
206
|
+
logger.info("✅ Migration diff applied successfully")
|
|
207
|
+
except subprocess.CalledProcessError as e:
|
|
208
|
+
logger.warning(f"Failed to apply migration diff: {e.stderr}")
|
|
209
|
+
except subprocess.TimeoutExpired:
|
|
210
|
+
logger.warning("Migration diff application timed out.")
|
|
211
|
+
|
|
212
|
+
# 3. Mark all migrations as applied
|
|
109
213
|
migration_names = ProxyExtrasDBManager._get_migration_names(migrations_dir)
|
|
110
214
|
logger.info(f"Resolving {len(migration_names)} migrations")
|
|
111
215
|
for migration_name in migration_names:
|
|
@@ -126,7 +230,7 @@ class ProxyExtrasDBManager:
|
|
|
126
230
|
)
|
|
127
231
|
|
|
128
232
|
@staticmethod
|
|
129
|
-
def setup_database(
|
|
233
|
+
def setup_database(use_migrate: bool = False) -> bool:
|
|
130
234
|
"""
|
|
131
235
|
Set up the database using either prisma migrate or prisma db push
|
|
132
236
|
Uses migrations from litellm-proxy-extras package
|
|
@@ -138,6 +242,7 @@ class ProxyExtrasDBManager:
|
|
|
138
242
|
Returns:
|
|
139
243
|
bool: True if setup was successful, False otherwise
|
|
140
244
|
"""
|
|
245
|
+
schema_path = ProxyExtrasDBManager._get_prisma_dir() + "/schema.prisma"
|
|
141
246
|
use_migrate = str_to_bool(os.getenv("USE_PRISMA_MIGRATE")) or use_migrate
|
|
142
247
|
for attempt in range(4):
|
|
143
248
|
original_dir = os.getcwd()
|
|
@@ -200,7 +305,9 @@ class ProxyExtrasDBManager:
|
|
|
200
305
|
logger.info(
|
|
201
306
|
"Baseline migration created, resolving all migrations"
|
|
202
307
|
)
|
|
203
|
-
ProxyExtrasDBManager._resolve_all_migrations(
|
|
308
|
+
ProxyExtrasDBManager._resolve_all_migrations(
|
|
309
|
+
migrations_dir, schema_path
|
|
310
|
+
)
|
|
204
311
|
logger.info("✅ All migrations resolved.")
|
|
205
312
|
return True
|
|
206
313
|
elif (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "litellm-proxy-extras"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.13"
|
|
4
4
|
description = "Additional files for the LiteLLM Proxy. Reduces the size of the main litellm package."
|
|
5
5
|
authors = ["BerriAI"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -22,7 +22,7 @@ requires = ["poetry-core"]
|
|
|
22
22
|
build-backend = "poetry.core.masonry.api"
|
|
23
23
|
|
|
24
24
|
[tool.commitizen]
|
|
25
|
-
version = "0.1.
|
|
25
|
+
version = "0.1.13"
|
|
26
26
|
version_files = [
|
|
27
27
|
"pyproject.toml:version",
|
|
28
28
|
"../requirements.txt:litellm-proxy-extras==",
|
|
File without changes
|
|
File without changes
|
{litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/__init__.py
RENAMED
|
File without changes
|
{litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/_logging.py
RENAMED
|
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
|
{litellm_proxy_extras-0.1.12 → litellm_proxy_extras-0.1.13}/litellm_proxy_extras/schema.prisma
RENAMED
|
File without changes
|