diff --git a/frigate/api/chat.py b/frigate/api/chat.py index 568dd882c7..c14ea8860e 100644 --- a/frigate/api/chat.py +++ b/frigate/api/chat.py @@ -1283,27 +1283,6 @@ def _with_server_ids(tool_calls: list[dict[str, Any]]) -> list[dict[str, Any]]: return [{**tc, "id": uuid.uuid4().hex[:9]} for tc in tool_calls] -def _client_content(content: Any) -> Any: - """Keep only text parts and inline images from client message content. - - Some model servers fetch remote image URLs themselves. - """ - if not isinstance(content, list): - return content - kept = [] - for part in content: - if not isinstance(part, dict): - continue - if part.get("type") == "text": - kept.append(part) - elif part.get("type") == "image_url": - image = part.get("image_url") - url = image.get("url") if isinstance(image, dict) else None - if isinstance(url, str) and url.startswith("data:image/"): - kept.append(part) - return kept - - def _tool_calls_awaiting_approval( pending_tool_calls: list[dict[str, Any]], body: ChatCompletionRequest, @@ -1549,7 +1528,7 @@ async def chat_completion( for msg in body.messages: msg_dict = { "role": msg.role, - "content": _client_content(msg.content), + "content": msg.content, } if msg.tool_call_id: msg_dict["tool_call_id"] = msg.tool_call_id diff --git a/frigate/test/test_chat_tool_approval.py b/frigate/test/test_chat_tool_approval.py index 685c93af01..b776ad95dc 100644 --- a/frigate/test/test_chat_tool_approval.py +++ b/frigate/test/test_chat_tool_approval.py @@ -16,7 +16,6 @@ from peewee import SqliteDatabase from frigate.api.chat import ( TOOL_REJECTED_RESULT, - _client_content, _execute_create_export, _execute_get_event_image, _execute_get_export_cases, @@ -171,28 +170,6 @@ class TestApprovalHelpers(unittest.TestCase): ) -class TestClientContent(unittest.TestCase): - def test_string_content_is_unchanged(self): - self.assertEqual(_client_content("hi"), "hi") - self.assertIsNone(_client_content(None)) - - def test_only_text_and_inline_images_are_kept(self): - text = {"type": "text", "text": "look"} - inline = { - "type": "image_url", - "image_url": {"url": "data:image/jpeg;base64,AAAA"}, - } - content = [ - text, - inline, - {"type": "image_url", "image_url": {"url": "http://frigate:5000/x.jpg"}}, - {"type": "image_url", "image_url": "data:image/jpeg;base64,AAAA"}, - {"type": "input_audio", "input_audio": {"data": "AAAA"}}, - "stray", - ] - self.assertEqual(_client_content(content), [text, inline]) - - class TestExecutePendingTools(unittest.TestCase): def test_rejected_call_is_not_executed(self): execute = AsyncMock(return_value={"success": True})