Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/user-guides/community/openai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## OpenAI API Compatibility for NeMo Guardrails

NeMo Guardrails provides server-side compatibility with OpenAI API endpoints, enabling applications that use OpenAI clients to seamlessly integrate with NeMo Guardrails for adding guardrails to LLM interactions. Point your OpenAI client to `http://localhost:8000` (or your server URL) and use the standard `/v1/chat/completions` endpoint.

## Feature Support Matrix

The following table outlines which OpenAI API features are currently supported when using NeMo Guardrails:

| Feature | Status | Notes |
| :------ | :----: | :---- |
| **Basic Chat Completion** | ✔ Supported | Full support for standard chat completions with guardrails applied |
| **Streaming Responses** | ✔ Supported | Server-Sent Events (SSE) streaming with `stream=true` |
| **Multimodal Input** | ✖ Unsupported | Support for text and image inputs (vision models) with guardrails but not yet OpenAI compatible |
| **Function Calling** | ✖ Unsupported | Not yet implemented; guardrails need structured output support |
| **Tools** | ✖ Unsupported | Related to function calling; requires action flow integration |
| **Response Format (JSON Mode)** | ✖ Unsupported | Structured output with guardrails requires additional validation logic |
12 changes: 8 additions & 4 deletions nemoguardrails/colang/v2_x/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ColangSyntaxError,
)
from nemoguardrails.colang.v2_x.runtime.flows import Event, FlowStatus
from nemoguardrails.colang.v2_x.runtime.serialization import json_to_state
from nemoguardrails.colang.v2_x.runtime.statemachine import (
FlowConfig,
InternalEvent,
Expand Down Expand Up @@ -439,10 +440,13 @@ async def process_events(
)
initialize_state(state)
elif isinstance(state, dict):
# TODO: Implement dict to State conversion
raise NotImplementedError()
# if isinstance(state, dict):
# state = State.from_dict(state)
# Convert dict to State object
if state.get("version") == "2.x" and "state" in state:
# Handle the serialized state format from API calls
state = json_to_state(state["state"])
else:
# TODO: Implement other dict to State conversion formats if needed
raise NotImplementedError("Unsupported state dict format")

assert isinstance(state, State)
assert state.main_flow_state is not None
Expand Down
Loading