Option pour cacher les messages Sys et Tools
This commit is contained in:
@@ -6,7 +6,7 @@ from langchain.messages import SystemMessage
|
||||
from .InterruptPayload import InterruptPayload
|
||||
|
||||
# Une fonction pour stream et gérer proprement le graphe
|
||||
def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0, showSysMessages=True):
|
||||
def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, lastMsgIndex=0, showSysMessages=True, showToolMessages=True):
|
||||
# https://docs.langchain.com/oss/python/langgraph/interrupts#stream-with-human-in-the-loop-hitl-interrupts
|
||||
for mode, state in graphe.stream(
|
||||
initial_input,
|
||||
@@ -18,7 +18,9 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, last
|
||||
# Handle streaming message content
|
||||
i=0
|
||||
for msg in state['messages'][lastMsgIndex:]: # Permet de gérer plusieurs nouveaux messages d'un coup
|
||||
if showSysMessages or not msg.type == "system": msg.pretty_print()
|
||||
if msg.type == "system" and showSysMessages: msg.pretty_print()
|
||||
elif msg.type == "tool" and showToolMessages: msg.pretty_print()
|
||||
elif msg.type != "tool" and msg.type != "system": msg.pretty_print() # User et IA
|
||||
i+=1
|
||||
lastMsgIndex+=i
|
||||
|
||||
@@ -29,7 +31,7 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, last
|
||||
|
||||
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, lastMsgIndex, showSysMessages) # 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, showSysMessages, showToolMessages) # 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