🔧 refactor(chat.py): refactor stream_build function to send input_keys to the client
The stream_build function has been refactored to send input_keys to the client if the langchain_object has the attribute "input_keys". This change improves the user experience by providing the client with the necessary input keys to continue the conversation.
This commit is contained in:
parent
ae71a54a06
commit
ff0abf5183
1 changed files with 9 additions and 1 deletions
|
|
@ -120,7 +120,15 @@ async def stream_build(flow_id: str):
|
|||
|
||||
yield str(StreamData(event="message", data=response))
|
||||
|
||||
chat_manager.set_cache(flow_id, graph.build())
|
||||
langchain_object = graph.build()
|
||||
# Now we need to check the input_keys to send them to the client
|
||||
if hasattr(langchain_object, "input_keys"):
|
||||
input_keys_response = {
|
||||
"input_keys": langchain_object.input_keys,
|
||||
}
|
||||
yield str(StreamData(event="input_keys", data=input_keys_response))
|
||||
|
||||
chat_manager.set_cache(flow_id, langchain_object)
|
||||
except Exception as exc:
|
||||
logger.error("Error while building the flow: %s", exc)
|
||||
yield str(StreamData(event="error", data={"error": str(exc)}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue