forked from phoenix/litellm-mirror
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:
|
||||
def __init__(self):
|
||||
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()
|
||||
|
||||
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]):
|
||||
global prisma_client, proxy_logging_obj, user_api_key_cache
|
||||
|
||||
proxy_logging_obj._init_litellm_callbacks()
|
||||
if database_url is not None:
|
||||
try:
|
||||
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"
|
||||
else:
|
||||
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}")
|
||||
elif key == "failure_callback":
|
||||
litellm.failure_callback = []
|
||||
|
@ -816,11 +811,9 @@ def get_litellm_model_info(model: dict = {}):
|
|||
|
||||
@router.on_event("startup")
|
||||
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
|
||||
|
||||
print(f"VALUE OF USE_QUEUE: {use_queue}")
|
||||
|
||||
### LOAD CONFIG ###
|
||||
worker_config = litellm.get_secret("WORKER_CONFIG")
|
||||
print_verbose(f"worker_config: {worker_config}")
|
||||
|
@ -833,6 +826,8 @@ async def startup_event():
|
|||
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:
|
||||
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
|
||||
def print_verbose(print_statement):
|
||||
if litellm.set_verbose:
|
||||
print(print_statement) # noqa
|
||||
print(f"LiteLLM Proxy: {print_statement}") # noqa
|
||||
### LOGGING ###
|
||||
class ProxyLogging:
|
||||
"""
|
||||
|
@ -26,7 +26,7 @@ class ProxyLogging:
|
|||
pass
|
||||
|
||||
def _init_litellm_callbacks(self):
|
||||
|
||||
print_verbose(f"INITIALIZING LITELLM CALLBACKS!")
|
||||
litellm.callbacks.append(self.max_parallel_request_limiter)
|
||||
for callback in litellm.callbacks:
|
||||
if callback not in litellm.input_callback:
|
||||
|
|
|
@ -386,7 +386,7 @@ class Router:
|
|||
self.print_verbose(f'Async Response: {response}')
|
||||
return response
|
||||
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
|
||||
try:
|
||||
self.print_verbose(f"Trying to fallback b/w models")
|
||||
|
|
|
@ -18,4 +18,5 @@ celery
|
|||
psutil
|
||||
mangum
|
||||
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