Skip to content

Commit 9970296

Browse files
fix: Colang 2.x doesn't support assistant messages
1 parent f5b2d1f commit 9970296

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

nemoguardrails/colang/v2_x/runtime/runtime.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
ColangSyntaxError,
3232
)
3333
from nemoguardrails.colang.v2_x.runtime.flows import Event, FlowStatus
34+
from nemoguardrails.colang.v2_x.runtime.serialization import json_to_state
3435
from nemoguardrails.colang.v2_x.runtime.statemachine import (
3536
FlowConfig,
3637
InternalEvent,
@@ -394,10 +395,13 @@ async def process_events(
394395
state = State(flow_states={}, flow_configs=self.flow_configs, rails_config=self.config)
395396
initialize_state(state)
396397
elif isinstance(state, dict):
397-
# TODO: Implement dict to State conversion
398-
raise NotImplementedError()
399-
# if isinstance(state, dict):
400-
# state = State.from_dict(state)
398+
# Convert dict to State object
399+
if state.get("version") == "2.x" and "state" in state:
400+
# Handle the serialized state format from API calls
401+
state = json_to_state(state["state"])
402+
else:
403+
# TODO: Implement other dict to State conversion formats if needed
404+
raise NotImplementedError("Unsupported state dict format")
401405

402406
assert isinstance(state, State)
403407
assert state.main_flow_state is not None

tests/test_server_calls_with_state.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def _test_call(config_id):
4444

4545
# When making a second call with the returned state, the conversations should continue
4646
# and we should get the "Hello again!" message.
47+
# For Colang 2.x, we only send the new user message, not the conversation history
48+
# since the state maintains the conversation context.
4749
response = client.post(
4850
"/v1/chat/completions",
4951
json={
@@ -52,11 +54,7 @@ def _test_call(config_id):
5254
{
5355
"content": "hi",
5456
"role": "user",
55-
},
56-
{
57-
"content": "hi",
58-
"role": "assistant",
59-
},
57+
}
6058
],
6159
"state": res["state"],
6260
},

0 commit comments

Comments
 (0)