Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 599d8f6

Browse files
authored
Workaround for system messages that contain a list of dicts (#1214)
In the litellm `ChatCompletionMessage` that we use a system message is defined as follows: ``` class OpenAIChatCompletionSystemMessage(TypedDict, total=False): role: Required[Literal["system"]] content: Required[Union[str, List]] name: str ``` So content can either be a string or a list. Our secret encryption code only handled the string case. Since both cases will properly be handled by the soon-to-be-coming rewrite, let's just add a workaround so that e.g. Cline with Anthropic keeps working. With the no-more-litellm branch, everything works as expected. Fixes: #1207
1 parent ce37fa4 commit 599d8f6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/codegate/pipeline/secrets/secrets.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,17 @@ async def process(
316316
# Process all messages
317317
for i, message in enumerate(new_request["messages"]):
318318
if "content" in message and message["content"]:
319+
message_content = message["content"]
320+
321+
# cline with anthropic seems to be sending a list of dicts with type:text instead of
322+
# a string
323+
# this hack will not be needed once we access the native functions through an API
324+
# (I tested this actually)
325+
if isinstance(message_content, list) and "text" in message_content[0]:
326+
message_content = message_content[0]["text"]
327+
319328
redacted_content, secrets_matched = self._redact_message_content(
320-
message["content"], sensitive_data_manager, session_id, context
329+
message_content, sensitive_data_manager, session_id, context
321330
)
322331
new_request["messages"][i]["content"] = redacted_content
323332
if i > last_assistant_idx:

0 commit comments

Comments
 (0)