forked from phoenix/litellm-mirror
fix(utils.py): function_setup empty message fix
fixes https://github.com/BerriAI/litellm/issues/2858
This commit is contained in:
parent
b38c09c87f
commit
6eb8fe35c8
2 changed files with 231 additions and 202 deletions
33
litellm/tests/test_function_setup.py
Normal file
33
litellm/tests/test_function_setup.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# What is this?
|
||||
## Unit tests for the 'function_setup()' function
|
||||
import sys, os
|
||||
import traceback
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
import os, io
|
||||
|
||||
sys.path.insert(
|
||||
0, os.path.abspath("../..")
|
||||
) # Adds the parent directory to the, system path
|
||||
import pytest, uuid
|
||||
from litellm.utils import function_setup, Rules
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def test_empty_content():
|
||||
"""
|
||||
Make a chat completions request with empty content -> expect this to work
|
||||
"""
|
||||
rules_obj = Rules()
|
||||
|
||||
def completion():
|
||||
pass
|
||||
|
||||
function_setup(
|
||||
original_function=completion,
|
||||
rules_obj=rules_obj,
|
||||
start_time=datetime.now(),
|
||||
messages=[],
|
||||
litellm_call_id=str(uuid.uuid4()),
|
||||
)
|
|
@ -2381,25 +2381,12 @@ class Rules:
|
|||
|
||||
####### CLIENT ###################
|
||||
# make it easy to log if completion/embedding runs succeeded or failed + see what happened | Non-Blocking
|
||||
def client(original_function):
|
||||
global liteDebuggerClient, get_all_keys
|
||||
rules_obj = Rules()
|
||||
|
||||
def function_setup(
|
||||
start_time, *args, **kwargs
|
||||
original_function, rules_obj, start_time, *args, **kwargs
|
||||
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
|
||||
try:
|
||||
global callback_list, add_breadcrumb, user_logger_fn, Logging
|
||||
function_id = kwargs["id"] if "id" in kwargs else None
|
||||
if litellm.use_client or (
|
||||
"use_client" in kwargs and kwargs["use_client"] == True
|
||||
):
|
||||
if "lite_debugger" not in litellm.input_callback:
|
||||
litellm.input_callback.append("lite_debugger")
|
||||
if "lite_debugger" not in litellm.success_callback:
|
||||
litellm.success_callback.append("lite_debugger")
|
||||
if "lite_debugger" not in litellm.failure_callback:
|
||||
litellm.failure_callback.append("lite_debugger")
|
||||
if len(litellm.callbacks) > 0:
|
||||
for callback in litellm.callbacks:
|
||||
if callback not in litellm.input_callback:
|
||||
|
@ -2522,7 +2509,7 @@ def client(original_function):
|
|||
input="".join(
|
||||
m.get("content", "")
|
||||
for m in messages
|
||||
if isinstance(m["content"], str)
|
||||
if "content" in m and isinstance(m["content"], str)
|
||||
),
|
||||
model=model,
|
||||
)
|
||||
|
@ -2585,6 +2572,11 @@ def client(original_function):
|
|||
)
|
||||
raise e
|
||||
|
||||
|
||||
def client(original_function):
|
||||
global liteDebuggerClient, get_all_keys
|
||||
rules_obj = Rules()
|
||||
|
||||
def check_coroutine(value) -> bool:
|
||||
if inspect.iscoroutine(value):
|
||||
return True
|
||||
|
@ -2677,7 +2669,9 @@ def client(original_function):
|
|||
|
||||
try:
|
||||
if logging_obj is None:
|
||||
logging_obj, kwargs = function_setup(start_time, *args, **kwargs)
|
||||
logging_obj, kwargs = function_setup(
|
||||
original_function, rules_obj, start_time, *args, **kwargs
|
||||
)
|
||||
kwargs["litellm_logging_obj"] = logging_obj
|
||||
|
||||
# CHECK FOR 'os.environ/' in kwargs
|
||||
|
@ -2985,7 +2979,9 @@ def client(original_function):
|
|||
|
||||
try:
|
||||
if logging_obj is None:
|
||||
logging_obj, kwargs = function_setup(start_time, *args, **kwargs)
|
||||
logging_obj, kwargs = function_setup(
|
||||
original_function, rules_obj, start_time, *args, **kwargs
|
||||
)
|
||||
kwargs["litellm_logging_obj"] = logging_obj
|
||||
|
||||
# [OPTIONAL] CHECK BUDGET
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue