fix(utils.py): fix rules calling

This commit is contained in:
Krrish Dholakia 2023-11-20 21:06:36 -08:00
parent b2e52eedf8
commit ab2986290e
2 changed files with 3 additions and 4 deletions

View file

@ -8,6 +8,7 @@ sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import pytest
import litellm
from litellm import completion
messages=[{"role": "user", "content": "Hey, how's it going?"}]

View file

@ -1077,21 +1077,19 @@ class Rules:
pass
def pre_call_rules(self, input: str, model: str):
model, custom_llm_provider, _, _ = get_llm_provider(model=model)
for rule in litellm.pre_call_rules:
if callable(rule):
decision = rule(input)
if decision is False:
raise litellm.APIResponseValidationError(message="LLM Response failed post-call-rule check", llm_provider=custom_llm_provider, model=model) # type: ignore
raise litellm.APIResponseValidationError(message="LLM Response failed post-call-rule check", llm_provider="", model=model) # type: ignore
return True
def post_call_rules(self, input: str, model: str):
model, custom_llm_provider, _, _ = get_llm_provider(model=model)
for rule in litellm.post_call_rules:
if callable(rule):
decision = rule(input)
if decision is False:
raise litellm.APIResponseValidationError(message="LLM Response failed post-call-rule check", llm_provider=custom_llm_provider, model=model) # type: ignore
raise litellm.APIResponseValidationError(message="LLM Response failed post-call-rule check", llm_provider="", model=model) # type: ignore
return True
####### CLIENT ###################