Noeud de préparation des documents
Pas encore totalement fonctionnel, mais déjà de bons résultats là dessus
This commit is contained in:
@@ -5,7 +5,7 @@ from langgraph.types import Command
|
||||
from .InterruptPayload import InterruptPayload
|
||||
|
||||
# Une fonction pour stream et gérer proprement le graphe
|
||||
def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph):
|
||||
def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0):
|
||||
# https://docs.langchain.com/oss/python/langgraph/interrupts#stream-with-human-in-the-loop-hitl-interrupts
|
||||
for mode, state in graphe.stream(
|
||||
initial_input,
|
||||
@@ -15,8 +15,11 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph):
|
||||
):
|
||||
if mode == "values":
|
||||
# Handle streaming message content
|
||||
msg = state['messages'][-1]
|
||||
msg.pretty_print()
|
||||
i=0
|
||||
for msg in state['messages'][lastMsgIndex:]: # Permet de gérer plusieurs nouveaux messages d'un coup
|
||||
msg.pretty_print()
|
||||
i+=1
|
||||
lastMsgIndex+=i
|
||||
|
||||
elif mode == "updates":
|
||||
# Check for interrupts
|
||||
@@ -25,7 +28,7 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph):
|
||||
|
||||
payload = InterruptPayload.fromJSON(payload) # Chargement de la requête depuis sa version JSON
|
||||
payload.humanDisplay() # L'utilisateur peut accepter/modifier/refuser ici
|
||||
streamGraph(Command(resume=payload.toJSON()), config, graphe) # Je renvois la chaîne JSON, qui sera reconvertie en objet dans l'outil, et je relance le stream récursivement
|
||||
streamGraph(Command(resume=payload.toJSON()), config, graphe, lastMsgIndex) # Je renvois la chaîne JSON, qui sera reconvertie en objet dans l'outil, et je relance le stream récursivement
|
||||
return # Fin de cette fonction récursive
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user