forked from phoenix/litellm-mirror
fix(utils.py): don't run post-call rules on a coroutine function
This commit is contained in:
parent
d08da5b05a
commit
9b7383ac67
2 changed files with 28 additions and 5 deletions
|
@ -127,3 +127,14 @@ def test_post_call_rule_streaming():
|
||||||
print(type(e))
|
print(type(e))
|
||||||
print(vars(e))
|
print(vars(e))
|
||||||
assert e.message == "This violates LiteLLM Proxy Rules. Response too short"
|
assert e.message == "This violates LiteLLM Proxy Rules. Response too short"
|
||||||
|
|
||||||
|
|
||||||
|
def test_post_call_processing_error_async_response():
|
||||||
|
response = asyncio.run(
|
||||||
|
acompletion(
|
||||||
|
model="command-nightly", # Just used as an example
|
||||||
|
messages=[{"content": "Hello, how are you?", "role": "user"}],
|
||||||
|
api_base="https://openai-proxy.berriai.repl.co", # Just used as an example
|
||||||
|
custom_llm_provider="openai",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -2465,6 +2465,14 @@ def client(original_function):
|
||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def check_coroutine(value) -> bool:
|
||||||
|
if inspect.iscoroutine(value):
|
||||||
|
return True
|
||||||
|
elif inspect.iscoroutinefunction(value):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def post_call_processing(original_response, model):
|
def post_call_processing(original_response, model):
|
||||||
try:
|
try:
|
||||||
if original_response is None:
|
if original_response is None:
|
||||||
|
@ -2475,11 +2483,15 @@ def client(original_function):
|
||||||
call_type == CallTypes.completion.value
|
call_type == CallTypes.completion.value
|
||||||
or call_type == CallTypes.acompletion.value
|
or call_type == CallTypes.acompletion.value
|
||||||
):
|
):
|
||||||
model_response = original_response["choices"][0]["message"][
|
is_coroutine = check_coroutine(original_function)
|
||||||
"content"
|
if is_coroutine == True:
|
||||||
]
|
pass
|
||||||
### POST-CALL RULES ###
|
else:
|
||||||
rules_obj.post_call_rules(input=model_response, model=model)
|
model_response = original_response["choices"][0]["message"][
|
||||||
|
"content"
|
||||||
|
]
|
||||||
|
### POST-CALL RULES ###
|
||||||
|
rules_obj.post_call_rules(input=model_response, model=model)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue