mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
feat(proxy_server.py): allow user to override api key auth
This commit is contained in:
parent
51cddf1e97
commit
030bd22078
9 changed files with 274 additions and 118 deletions
|
@ -1,6 +1,7 @@
|
|||
from typing import Optional, List, Any
|
||||
import os, subprocess, hashlib
|
||||
import os, subprocess, hashlib, importlib
|
||||
|
||||
### DB CONNECTOR ###
|
||||
class PrismaClient:
|
||||
def __init__(self, database_url: str):
|
||||
print("LiteLLM: DATABASE_URL Set in config, trying to 'pip install prisma'")
|
||||
|
@ -95,3 +96,60 @@ class PrismaClient:
|
|||
async def disconnect(self):
|
||||
await self.db.disconnect()
|
||||
|
||||
# ### CUSTOM FILE ###
|
||||
# def get_instance_fn(value: str, config_file_path: Optional[str]=None):
|
||||
# try:
|
||||
# # Split the path by dots to separate module from instance
|
||||
# parts = value.split(".")
|
||||
# # The module path is all but the last part, and the instance is the last part
|
||||
# module_path = ".".join(parts[:-1])
|
||||
# instance_name = parts[-1]
|
||||
|
||||
# if config_file_path is not None:
|
||||
# directory = os.path.dirname(config_file_path)
|
||||
# module_path = os.path.join(directory, module_path)
|
||||
# # Dynamically import the module
|
||||
# module = importlib.import_module(module_path)
|
||||
|
||||
# # Get the instance from the module
|
||||
# instance = getattr(module, instance_name)
|
||||
|
||||
# return instance
|
||||
# except ImportError as e:
|
||||
# print(e)
|
||||
# raise ImportError(f"Could not import file at {value}")
|
||||
|
||||
def get_instance_fn(value: str, config_file_path: Optional[str] = None) -> Any:
|
||||
try:
|
||||
print(f"value: {value}")
|
||||
# Split the path by dots to separate module from instance
|
||||
parts = value.split(".")
|
||||
|
||||
# The module path is all but the last part, and the instance_name is the last part
|
||||
module_name = ".".join(parts[:-1])
|
||||
instance_name = parts[-1]
|
||||
|
||||
# If config_file_path is provided, use it to determine the module spec and load the module
|
||||
if config_file_path is not None:
|
||||
directory = os.path.dirname(config_file_path)
|
||||
module_file_path = os.path.join(directory, *module_name.split('.'))
|
||||
module_file_path += '.py'
|
||||
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_file_path)
|
||||
if spec is None:
|
||||
raise ImportError(f"Could not find a module specification for {module_file_path}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
else:
|
||||
# Dynamically import the module
|
||||
module = importlib.import_module(module_name)
|
||||
|
||||
# Get the instance from the module
|
||||
instance = getattr(module, instance_name)
|
||||
|
||||
return instance
|
||||
except ImportError as e:
|
||||
# Print the error message for easier debugging
|
||||
print(e)
|
||||
# Re-raise the exception with a user-friendly message
|
||||
raise ImportError(f"Could not import {instance_name} from {module_name}") from e
|
Loading…
Add table
Add a link
Reference in a new issue