mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
fix(proxy_server.py): setup depedencies on server startup
This commit is contained in:
parent
4e828ff541
commit
3291de9e11
5 changed files with 10 additions and 13 deletions
|
@ -1,7 +1,8 @@
|
||||||
class TraceloopLogger:
|
class TraceloopLogger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
from traceloop.sdk.tracing.tracing import TracerWrapper
|
from traceloop.sdk.tracing.tracing import TracerWrapper
|
||||||
|
from traceloop.sdk import Traceloop
|
||||||
|
Traceloop.init(app_name="Litellm-Server", disable_batch=True)
|
||||||
self.tracer_wrapper = TracerWrapper()
|
self.tracer_wrapper = TracerWrapper()
|
||||||
|
|
||||||
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
|
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
|
||||||
|
|
|
@ -319,7 +319,6 @@ async def user_api_key_auth(request: Request, api_key: str = fastapi.Security(ap
|
||||||
def prisma_setup(database_url: Optional[str]):
|
def prisma_setup(database_url: Optional[str]):
|
||||||
global prisma_client, proxy_logging_obj, user_api_key_cache
|
global prisma_client, proxy_logging_obj, user_api_key_cache
|
||||||
|
|
||||||
proxy_logging_obj._init_litellm_callbacks()
|
|
||||||
if database_url is not None:
|
if database_url is not None:
|
||||||
try:
|
try:
|
||||||
prisma_client = PrismaClient(database_url=database_url, proxy_logging_obj=proxy_logging_obj)
|
prisma_client = PrismaClient(database_url=database_url, proxy_logging_obj=proxy_logging_obj)
|
||||||
|
@ -527,10 +526,6 @@ def load_router_config(router: Optional[litellm.Router], config_file_path: str):
|
||||||
# these are litellm callbacks - "langfuse", "sentry", "wandb"
|
# these are litellm callbacks - "langfuse", "sentry", "wandb"
|
||||||
else:
|
else:
|
||||||
litellm.success_callback.append(callback)
|
litellm.success_callback.append(callback)
|
||||||
if callback == "traceloop":
|
|
||||||
from traceloop.sdk import Traceloop
|
|
||||||
print_verbose(f"{blue_color_code} Initializing Traceloop SDK - \nRunning:`Traceloop.init(app_name='Litellm-Server', disable_batch=True)`")
|
|
||||||
Traceloop.init(app_name="Litellm-Server", disable_batch=True)
|
|
||||||
print_verbose(f"{blue_color_code} Initialized Success Callbacks - {litellm.success_callback} {reset_color_code}")
|
print_verbose(f"{blue_color_code} Initialized Success Callbacks - {litellm.success_callback} {reset_color_code}")
|
||||||
elif key == "failure_callback":
|
elif key == "failure_callback":
|
||||||
litellm.failure_callback = []
|
litellm.failure_callback = []
|
||||||
|
@ -816,11 +811,9 @@ def get_litellm_model_info(model: dict = {}):
|
||||||
|
|
||||||
@router.on_event("startup")
|
@router.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
global prisma_client, master_key, use_background_health_checks, use_queue
|
global prisma_client, master_key, use_background_health_checks
|
||||||
import json
|
import json
|
||||||
|
|
||||||
print(f"VALUE OF USE_QUEUE: {use_queue}")
|
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
worker_config = litellm.get_secret("WORKER_CONFIG")
|
worker_config = litellm.get_secret("WORKER_CONFIG")
|
||||||
print_verbose(f"worker_config: {worker_config}")
|
print_verbose(f"worker_config: {worker_config}")
|
||||||
|
@ -833,6 +826,8 @@ async def startup_event():
|
||||||
initialize(**worker_config)
|
initialize(**worker_config)
|
||||||
|
|
||||||
|
|
||||||
|
proxy_logging_obj._init_litellm_callbacks() # INITIALIZE LITELLM CALLBACKS ON SERVER STARTUP <- do this to catch any logging errors on startup, not when calls are being made
|
||||||
|
|
||||||
if use_background_health_checks:
|
if use_background_health_checks:
|
||||||
asyncio.create_task(_run_background_health_check()) # start the background health check coroutine.
|
asyncio.create_task(_run_background_health_check()) # start the background health check coroutine.
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from litellm.proxy.hooks.parallel_request_limiter import MaxParallelRequestsHand
|
||||||
from litellm.integrations.custom_logger import CustomLogger
|
from litellm.integrations.custom_logger import CustomLogger
|
||||||
def print_verbose(print_statement):
|
def print_verbose(print_statement):
|
||||||
if litellm.set_verbose:
|
if litellm.set_verbose:
|
||||||
print(print_statement) # noqa
|
print(f"LiteLLM Proxy: {print_statement}") # noqa
|
||||||
### LOGGING ###
|
### LOGGING ###
|
||||||
class ProxyLogging:
|
class ProxyLogging:
|
||||||
"""
|
"""
|
||||||
|
@ -26,7 +26,7 @@ class ProxyLogging:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _init_litellm_callbacks(self):
|
def _init_litellm_callbacks(self):
|
||||||
|
print_verbose(f"INITIALIZING LITELLM CALLBACKS!")
|
||||||
litellm.callbacks.append(self.max_parallel_request_limiter)
|
litellm.callbacks.append(self.max_parallel_request_limiter)
|
||||||
for callback in litellm.callbacks:
|
for callback in litellm.callbacks:
|
||||||
if callback not in litellm.input_callback:
|
if callback not in litellm.input_callback:
|
||||||
|
|
|
@ -386,7 +386,7 @@ class Router:
|
||||||
self.print_verbose(f'Async Response: {response}')
|
self.print_verbose(f'Async Response: {response}')
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.print_verbose(f"An exception occurs: {e}")
|
self.print_verbose(f"An exception occurs: {e}\n\n Traceback{traceback.format_exc()}")
|
||||||
original_exception = e
|
original_exception = e
|
||||||
try:
|
try:
|
||||||
self.print_verbose(f"Trying to fallback b/w models")
|
self.print_verbose(f"Trying to fallback b/w models")
|
||||||
|
|
|
@ -18,4 +18,5 @@ celery
|
||||||
psutil
|
psutil
|
||||||
mangum
|
mangum
|
||||||
google-generativeai
|
google-generativeai
|
||||||
async_generator # for ollama
|
traceloop-sdk==0.5.3
|
||||||
|
langfuse==1.14.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue