Skip to navigation

nemoguardrails.server.experimental.providers.openai.chat_completions.stream_hooks

View as MarkdownOpen in Claude

Bind OpenAI Chat Completions protocol hooks to the staged classifier.

Module Contents

Classes

NameDescription
ChatCompletionsStreamHooksRequire successful streams to end with [DONE].

API

class nemoguardrails.server.experimental.providers.openai.chat_completions.stream_hooks.ChatCompletionsStreamHooks()

Require successful streams to end with [DONE].

A provider error may end the stream without a sentinel. Data-less keepalives are permitted throughout; payload events cannot follow an error or sentinel, except for a sentinel after an error. State belongs to one upstream stream.

nemoguardrails.server.experimental.providers.openai.chat_completions.stream_hooks.ChatCompletionsStreamHooks.encode_error(
rendered_body: bytes
) -> tuple[bytes, bytes]

Encode an OpenAI-compatible error and terminal chat event.

nemoguardrails.server.experimental.providers.openai.chat_completions.stream_hooks.ChatCompletionsStreamHooks.observe_event(
) -> None

Track the actual sentinel and reject payloads after termination.

nemoguardrails.server.experimental.providers.openai.chat_completions.stream_hooks.ChatCompletionsStreamHooks.validate_end_of_stream() -> None

Reject successful streams that end before their sentinel.