File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
nemoguardrails/colang/v2_x/runtime Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 3333 ColangSyntaxError ,
3434)
3535from nemoguardrails .colang .v2_x .runtime .flows import Event , FlowStatus
36+ from nemoguardrails .colang .v2_x .runtime .serialization import json_to_state
3637from 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
Original file line number Diff line number Diff 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 },
You can’t perform that action at this time.
0 commit comments