Format diff.

This commit is contained in:
Hemang
2025-06-11 16:15:52 +02:00
committed by Hemang Sarkar
parent 1825f543a7
commit d59a96676f
3 changed files with 10 additions and 5 deletions

View File

@@ -251,7 +251,9 @@ class AnthropicProvider(BaseProvider):
}
}
)
return ExtraItem(f"event: error\ndata: {error_chunk}\n\n".encode(), end_of_stream=True)
return ExtraItem(
f"event: error\ndata: {error_chunk}\n\n".encode(), end_of_stream=True
)
def should_push_trace(self, _1: dict[str, Any], _2: bool) -> bool:
"""Anthropic always pushes traces"""
@@ -309,7 +311,7 @@ class AnthropicProvider(BaseProvider):
elif line.startswith("data:"):
event_data = line[5:].strip()
if event_data and event_type != "ping": # Ignore ping events
if event_data and event_type != "ping": # Ignore ping events
try:
event_json = json.loads(event_data)
update_merged_response(event_json, merged_response)

View File

@@ -290,7 +290,10 @@ class GeminiProvider(BaseProvider):
location: Literal["request", "response"] = "response",
) -> ExtraItem:
"""Gemini streaming error format"""
return ExtraItem(json.dumps(make_refusal(location, guardrails_execution_result)), end_of_stream=True)
return ExtraItem(
json.dumps(make_refusal(location, guardrails_execution_result)),
end_of_stream=True,
)
def should_push_trace(
self, merged_response: dict[str, Any], has_errors: bool

View File

@@ -170,8 +170,8 @@ class BaseInstrumentedResponse(ABC):
if self.is_streaming:
return self.provider.create_error_chunk(
self.guardrails_execution_result, location="request"
)
self.guardrails_execution_result, location="request"
)
return self.provider.create_non_streaming_error_response(
self.guardrails_execution_result, location="request"
)