mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-23 22:07:07 +03:00
remove client image filter from chat messages
This commit is contained in:
+1
-22
@@ -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]
|
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(
|
def _tool_calls_awaiting_approval(
|
||||||
pending_tool_calls: list[dict[str, Any]],
|
pending_tool_calls: list[dict[str, Any]],
|
||||||
body: ChatCompletionRequest,
|
body: ChatCompletionRequest,
|
||||||
@@ -1549,7 +1528,7 @@ async def chat_completion(
|
|||||||
for msg in body.messages:
|
for msg in body.messages:
|
||||||
msg_dict = {
|
msg_dict = {
|
||||||
"role": msg.role,
|
"role": msg.role,
|
||||||
"content": _client_content(msg.content),
|
"content": msg.content,
|
||||||
}
|
}
|
||||||
if msg.tool_call_id:
|
if msg.tool_call_id:
|
||||||
msg_dict["tool_call_id"] = msg.tool_call_id
|
msg_dict["tool_call_id"] = msg.tool_call_id
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from peewee import SqliteDatabase
|
|||||||
|
|
||||||
from frigate.api.chat import (
|
from frigate.api.chat import (
|
||||||
TOOL_REJECTED_RESULT,
|
TOOL_REJECTED_RESULT,
|
||||||
_client_content,
|
|
||||||
_execute_create_export,
|
_execute_create_export,
|
||||||
_execute_get_event_image,
|
_execute_get_event_image,
|
||||||
_execute_get_export_cases,
|
_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):
|
class TestExecutePendingTools(unittest.TestCase):
|
||||||
def test_rejected_call_is_not_executed(self):
|
def test_rejected_call_is_not_executed(self):
|
||||||
execute = AsyncMock(return_value={"success": True})
|
execute = AsyncMock(return_value={"success": True})
|
||||||
|
|||||||
Reference in New Issue
Block a user