Option pour cacher les messages Sys et Tools
This commit is contained in:
@@ -22,4 +22,4 @@ initial_input = {
|
|||||||
config={"configurable": {"thread_id": 'yes'}}
|
config={"configurable": {"thread_id": 'yes'}}
|
||||||
|
|
||||||
# Et je lance !
|
# Et je lance !
|
||||||
streamGraph(initial_input, config, getGraph(), showSysMessages=False)
|
streamGraph(initial_input, config, getGraph(), showSysMessages=True, showToolMessages=True)
|
||||||
@@ -6,7 +6,7 @@ from langchain.messages import SystemMessage
|
|||||||
from .InterruptPayload import InterruptPayload
|
from .InterruptPayload import InterruptPayload
|
||||||
|
|
||||||
# Une fonction pour stream et gérer proprement le graphe
|
# 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
|
# https://docs.langchain.com/oss/python/langgraph/interrupts#stream-with-human-in-the-loop-hitl-interrupts
|
||||||
for mode, state in graphe.stream(
|
for mode, state in graphe.stream(
|
||||||
initial_input,
|
initial_input,
|
||||||
@@ -18,7 +18,9 @@ def streamGraph(initial_input:Dict, config:Dict, graphe:CompiledStateGraph, last
|
|||||||
# Handle streaming message content
|
# Handle streaming message content
|
||||||
i=0
|
i=0
|
||||||
for msg in state['messages'][lastMsgIndex:]: # Permet de gérer plusieurs nouveaux messages d'un coup
|
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
|
i+=1
|
||||||
lastMsgIndex+=i
|
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 = InterruptPayload.fromJSON(payload) # Chargement de la requête depuis sa version JSON
|
||||||
payload.humanDisplay() # L'utilisateur peut accepter/modifier/refuser ici
|
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
|
return # Fin de cette fonction récursive
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user