mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-08 08:08:37 +00:00
Response transformation crashed with TypeError when counting tokens for multimodal (dict-shaped) embedding inputs, since encoding.encode() was called directly on the dict instead of its text parts. Also removed a dead, equally-buggy duplicate of the same loop in _transform_response. Separately, the embeddings guardrail handler silently skipped multimodal dict inputs instead of scanning them, letting prohibited text/image content bypass the configured guardrail. It now extracts and scans the text parts while leaving image parts untouched.
35 lines
1 KiB
Python
35 lines
1 KiB
Python
import os
|
|
import sys
|
|
import threading
|
|
from datetime import datetime
|
|
|
|
sys.path.insert(
|
|
0, os.path.abspath("../..")
|
|
) # Adds the parent directory to the system-path
|
|
|
|
import pytest
|
|
from litellm.integrations.humanloop import HumanLoopPromptManager
|
|
from litellm.types.utils import StandardCallbackDynamicParams
|
|
from litellm.litellm_core_utils.litellm_logging import DynamicLoggingCache
|
|
from unittest.mock import Mock, patch
|
|
|
|
|
|
def test_compile_prompt():
|
|
prompt_manager = HumanLoopPromptManager()
|
|
prompt_template = [
|
|
{
|
|
"content": "You are {{person}}. Answer questions as this person. Do not break character.",
|
|
"name": None,
|
|
"tool_call_id": None,
|
|
"role": "system",
|
|
"tool_calls": None,
|
|
}
|
|
]
|
|
prompt_variables = {"person": "John"}
|
|
compiled_prompt = prompt_manager._compile_prompt_helper(
|
|
prompt_template, prompt_variables
|
|
)
|
|
assert (
|
|
compiled_prompt[0]["content"]
|
|
== "You are John. Answer questions as this person. Do not break character."
|
|
)
|