Skip to content

Commit 9bac248

Browse files
committed
fixed: interrupt occuring while hitl
1 parent f8f0a7b commit 9bac248

2 files changed

Lines changed: 43 additions & 23 deletions

File tree

allinone.py

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,29 +330,49 @@ async def chat(request:ChatRequest):
330330
}
331331
}
332332

333-
state=await graph.aget_state(config)
334-
if state.interrupts:
335-
result=await graph.ainvoke(Command(resume=request.message),config=config)
336-
337-
else:
338-
result=await graph.ainvoke(
339-
{"messages":[("user",request.message)],
340-
"user_id":request.user_id,
341-
"confirmed":False,
342-
"notice":""},config=config
343-
)
333+
try:
334+
current_state=await graph.aget_state(config)
335+
if current_state.interrupts:
336+
result_state=await graph.ainvoke(Command(resume=request.message),config=config)
337+
338+
new_state=await graph.aget_state(config)
339+
if new_state.interrupts:
340+
return {
341+
"thread_id":thread_id,
342+
"status":"confirmation_required",
343+
"message":new_state.interrups[0].value
344+
}
345+
return {
346+
"thread_id":thread_id,
347+
"status":"completed",
348+
"message":result_state["messages"][-1].content
349+
}
350+
else:
351+
result_state=await graph.ainvoke(
352+
{"messages":[("user",request.message)],
353+
"user_id":request.user_id,
354+
"confirmed":False,
355+
"notice":""},config=config
356+
)
344357

345-
if "__interrupt__" in result:
358+
after_state=await graph.aget_state(config)
359+
if after_state.interrupts:
360+
return {
361+
"thread_id":thread_id,
362+
"status":"confirmation required",
363+
"message":result["__interrupt__"][0].value
364+
}
365+
366+
return {
367+
"thread_id":thread_id,
368+
"status":"completed",
369+
"message":result["messages"][-1].content
370+
}
371+
372+
except Exception as e:
373+
print(f"error: {str(e)}")
346374
return {
347375
"thread_id":thread_id,
348-
"status":"confirmation required",
349-
"message":result["__interrupt__"][0].value
376+
"status":"error",
377+
"message":f"Error occured : {str(e)}"
350378
}
351-
352-
return {
353-
"thread_id":thread_id,
354-
"status":"completed",
355-
"message":result["messages"][-1].content
356-
}
357-
358-

streamlit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import uuid
44
import os
55

6-
st.title("Expense Tracker AI Assistant")
6+
st.title("Expense Tracker AI Assistant v2")
77

88

99
API_URL=os.getenv("API_URL")

0 commit comments

Comments
 (0)