mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(fix) - proxy reliability, ensure duplicate callbacks are not added to proxy (#8067)
* refactor _add_callbacks_from_db_config * fix check for _custom_logger_exists_in_litellm_callbacks * move loc of test utils * run ci/cd again * test_add_custom_logger_callback_to_specific_event_with_duplicates_callbacks * fix _custom_logger_class_exists_in_success_callbacks * unit testing for test_add_callbacks_from_db_config * test_custom_logger_exists_in_callbacks_individual_functions * fix config.yml * fix test test_stream_chunk_builder_openai_audio_output_usage - use direct dict comparison
This commit is contained in:
parent
ae7b042bc2
commit
b812286534
5 changed files with 398 additions and 15 deletions
|
@ -346,11 +346,12 @@ def _add_custom_logger_callback_to_specific_event(
|
|||
llm_router=None,
|
||||
)
|
||||
|
||||
# don't double add a callback
|
||||
if callback_class is not None and not any(
|
||||
isinstance(cb, type(callback_class)) for cb in litellm.callbacks # type: ignore
|
||||
):
|
||||
if logging_event == "success":
|
||||
if callback_class:
|
||||
if (
|
||||
logging_event == "success"
|
||||
and _custom_logger_class_exists_in_success_callbacks(callback_class)
|
||||
is False
|
||||
):
|
||||
litellm.success_callback.append(callback_class)
|
||||
litellm._async_success_callback.append(callback_class)
|
||||
if callback in litellm.success_callback:
|
||||
|
@ -361,7 +362,11 @@ def _add_custom_logger_callback_to_specific_event(
|
|||
litellm._async_success_callback.remove(
|
||||
callback
|
||||
) # remove the string from the callback list
|
||||
elif logging_event == "failure":
|
||||
elif (
|
||||
logging_event == "failure"
|
||||
and _custom_logger_class_exists_in_failure_callbacks(callback_class)
|
||||
is False
|
||||
):
|
||||
litellm.failure_callback.append(callback_class)
|
||||
litellm._async_failure_callback.append(callback_class)
|
||||
if callback in litellm.failure_callback:
|
||||
|
@ -374,6 +379,38 @@ def _add_custom_logger_callback_to_specific_event(
|
|||
) # remove the string from the callback list
|
||||
|
||||
|
||||
def _custom_logger_class_exists_in_success_callbacks(
|
||||
callback_class: CustomLogger,
|
||||
) -> bool:
|
||||
"""
|
||||
Returns True if an instance of the custom logger exists in litellm.success_callback or litellm._async_success_callback
|
||||
|
||||
e.g if `LangfusePromptManagement` is passed in, it will return True if an instance of `LangfusePromptManagement` exists in litellm.success_callback or litellm._async_success_callback
|
||||
|
||||
Prevents double adding a custom logger callback to the litellm callbacks
|
||||
"""
|
||||
return any(
|
||||
isinstance(cb, type(callback_class))
|
||||
for cb in litellm.success_callback + litellm._async_success_callback
|
||||
)
|
||||
|
||||
|
||||
def _custom_logger_class_exists_in_failure_callbacks(
|
||||
callback_class: CustomLogger,
|
||||
) -> bool:
|
||||
"""
|
||||
Returns True if an instance of the custom logger exists in litellm.failure_callback or litellm._async_failure_callback
|
||||
|
||||
e.g if `LangfusePromptManagement` is passed in, it will return True if an instance of `LangfusePromptManagement` exists in litellm.failure_callback or litellm._async_failure_callback
|
||||
|
||||
Prevents double adding a custom logger callback to the litellm callbacks
|
||||
"""
|
||||
return any(
|
||||
isinstance(cb, type(callback_class))
|
||||
for cb in litellm.failure_callback + litellm._async_failure_callback
|
||||
)
|
||||
|
||||
|
||||
def function_setup( # noqa: PLR0915
|
||||
original_function: str, rules_obj, start_time, *args, **kwargs
|
||||
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue