Skip to content

Commit f494cf2

Browse files
fix: Colang 2.x doesn't support assistant messages
1 parent 4b2f46c commit f494cf2

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
@@ -33,6 +33,7 @@
3333
ColangSyntaxError,
3434
)
3535
from nemoguardrails.colang.v2_x.runtime.flows import Event, FlowStatus
36+
from nemoguardrails.colang.v2_x.runtime.serialization import json_to_state
3637
from nemoguardrails.colang.v2_x.runtime.statemachine import (
3738
FlowConfig,
3839
InternalEvent,
@@ -439,10 +440,13 @@ async def process_events(
439440
)
440441
initialize_state(state)
441442
elif isinstance(state, dict):
442-
# TODO: Implement dict to State conversion
443-
raise NotImplementedError()
444-
# if isinstance(state, dict):
445-
# state = State.from_dict(state)
443+
# Convert dict to State object
444+
if state.get("version") == "2.x" and "state" in state:
445+
# Handle the serialized state format from API calls
446+
state = json_to_state(state["state"])
447+
else:
448+
# TODO: Implement other dict to State conversion formats if needed
449+
raise NotImplementedError("Unsupported state dict format")
446450

447451
assert isinstance(state, State)
448452
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)