forked from phoenix/litellm-mirror
🔊 fix: Correctly use verbose logging
Signed-off-by: Lunik <lunik@tiwabbit.fr>
This commit is contained in:
parent
8783fd4895
commit
1639a51f24
1 changed files with 7 additions and 15 deletions
|
@ -55,14 +55,6 @@ class _PROXY_AzureContentSafety(
|
||||||
|
|
||||||
return thresholds
|
return thresholds
|
||||||
|
|
||||||
def print_verbose(self, print_statement):
|
|
||||||
try:
|
|
||||||
verbose_proxy_logger.debug(print_statement)
|
|
||||||
if litellm.set_verbose:
|
|
||||||
print(print_statement) # noqa
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _compute_result(self, response):
|
def _compute_result(self, response):
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
|
@ -80,7 +72,7 @@ class _PROXY_AzureContentSafety(
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def test_violation(self, content: str, source: str = None):
|
async def test_violation(self, content: str, source: str = None):
|
||||||
self.print_verbose(f"Testing Azure Content-Safety for: {content}")
|
verbose_proxy_logger.debug("Testing Azure Content-Safety for: %s", content)
|
||||||
|
|
||||||
# Construct a request
|
# Construct a request
|
||||||
request = self.analyze_text_options(
|
request = self.analyze_text_options(
|
||||||
|
@ -92,14 +84,14 @@ class _PROXY_AzureContentSafety(
|
||||||
try:
|
try:
|
||||||
response = await self.client.analyze_text(request)
|
response = await self.client.analyze_text(request)
|
||||||
except self.azure_http_error as e:
|
except self.azure_http_error as e:
|
||||||
self.print_verbose(
|
verbose_proxy_logger.debug(
|
||||||
f"Error in Azure Content-Safety: {traceback.format_exc()}"
|
"Error in Azure Content-Safety: %s", traceback.format_exc()
|
||||||
)
|
)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
result = self._compute_result(response)
|
result = self._compute_result(response)
|
||||||
self.print_verbose(f"Azure Content-Safety Result: {result}")
|
verbose_proxy_logger.debug("Azure Content-Safety Result: %s", result)
|
||||||
|
|
||||||
for key, value in result.items():
|
for key, value in result.items():
|
||||||
if value["filtered"]:
|
if value["filtered"]:
|
||||||
|
@ -120,7 +112,7 @@ class _PROXY_AzureContentSafety(
|
||||||
data: dict,
|
data: dict,
|
||||||
call_type: str, # "completion", "embeddings", "image_generation", "moderation"
|
call_type: str, # "completion", "embeddings", "image_generation", "moderation"
|
||||||
):
|
):
|
||||||
self.print_verbose(f"Inside Azure Content-Safety Pre-Call Hook")
|
verbose_proxy_logger.debug("Inside Azure Content-Safety Pre-Call Hook")
|
||||||
try:
|
try:
|
||||||
if call_type == "completion" and "messages" in data:
|
if call_type == "completion" and "messages" in data:
|
||||||
for m in data["messages"]:
|
for m in data["messages"]:
|
||||||
|
@ -137,7 +129,7 @@ class _PROXY_AzureContentSafety(
|
||||||
user_api_key_dict: UserAPIKeyAuth,
|
user_api_key_dict: UserAPIKeyAuth,
|
||||||
response,
|
response,
|
||||||
):
|
):
|
||||||
self.print_verbose(f"Inside Azure Content-Safety Post-Call Hook")
|
verbose_proxy_logger.debug("Inside Azure Content-Safety Post-Call Hook")
|
||||||
if isinstance(response, litellm.ModelResponse) and isinstance(
|
if isinstance(response, litellm.ModelResponse) and isinstance(
|
||||||
response.choices[0], litellm.utils.Choices
|
response.choices[0], litellm.utils.Choices
|
||||||
):
|
):
|
||||||
|
@ -150,5 +142,5 @@ class _PROXY_AzureContentSafety(
|
||||||
# user_api_key_dict: UserAPIKeyAuth,
|
# user_api_key_dict: UserAPIKeyAuth,
|
||||||
# response: str,
|
# response: str,
|
||||||
# ):
|
# ):
|
||||||
# self.print_verbose(f"Inside Azure Content-Safety Call-Stream Hook")
|
# verbose_proxy_logger.debug("Inside Azure Content-Safety Call-Stream Hook")
|
||||||
# await self.test_violation(content=response, source="output")
|
# await self.test_violation(content=response, source="output")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue