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

Commit d97b65e

Browse files
committed
Fixed regression on secrets step for Anthropic.
1 parent 0bbdde3 commit d97b65e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/codegate/pipeline/secrets/secrets.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,17 @@ async def process_chunk(
498498
"",
499499
)
500500

501+
# If the chunk has no content, we do not touch it, as it is
502+
# likely to break the communication protocol. As of the time
503+
# of this writing, this is probably only valid for Anthropic,
504+
# and we might want to abstract this away in the interface by
505+
# answering a question like "is this chunk modifiable?"
506+
if next(chunk.get_content(), None) is None:
507+
return [chunk]
508+
for content in chunk.get_content():
509+
if content.get_text() is None or content.get_text() == "":
510+
return [chunk]
511+
501512
# Check if this is the first chunk (delta role will be present, others will not)
502513
redacted_count = input_context.metadata["redacted_secrets_count"]
503514
secret_text = "secret" if redacted_count == 1 else "secrets"

tests/types/openai/streaming_messages.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ data: {"id":"chatcmpl-B0szUPll9BiFva49CokSsI1pVPjA6","choices":[{"index":0,"delt
55
data: {"id":"chatcmpl-B0szUPll9BiFva49CokSsI1pVPjA6","choices":[],"created":1739551084,"model":"gpt-4o-2024-08-06","service_tier":"default","system_fingerprint":"fp_523b9b6e5f","object":"chat.completion.chunk","usage":{"completion_tokens":394,"prompt_tokens":15675,"total_tokens":16069,"completion_tokens_details":{"accepted_prediction_tokens":0,"audio_tokens":0,"reasoning_tokens":0,"rejected_prediction_tokens":0},"prompt_tokens_details":{"audio_tokens":0,"cached_tokens":4352}}}
66

77
data: [DONE]
8+

0 commit comments

Comments
 (0)