Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io
This commit is contained in:
commit
4303e9efb0
2 changed files with 25 additions and 3 deletions
|
|
@ -22,3 +22,26 @@ def remove_api_keys(flow: dict):
|
||||||
value["value"] = None
|
value["value"] = None
|
||||||
|
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
|
|
||||||
|
def build_input_keys_response(langchain_object):
|
||||||
|
"""Build the input keys response."""
|
||||||
|
input_keys_response = {
|
||||||
|
"input_keys": langchain_object.input_keys,
|
||||||
|
"memory_keys": [],
|
||||||
|
}
|
||||||
|
# If the object has memory, that memory will have a memory_variables attribute
|
||||||
|
# memory variables should be removed from the input keys
|
||||||
|
if hasattr(langchain_object, "memory") and hasattr(
|
||||||
|
langchain_object.memory, "memory_variables"
|
||||||
|
):
|
||||||
|
# Remove memory variables from input keys
|
||||||
|
input_keys_response["input_keys"] = [
|
||||||
|
key
|
||||||
|
for key in input_keys_response["input_keys"]
|
||||||
|
if key not in langchain_object.memory.memory_variables
|
||||||
|
]
|
||||||
|
# Add memory variables to memory_keys
|
||||||
|
input_keys_response["memory_keys"] = langchain_object.memory.memory_variables
|
||||||
|
|
||||||
|
return input_keys_response
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from fastapi import (
|
||||||
status,
|
status,
|
||||||
)
|
)
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
from langflow.api.utils import build_input_keys_response
|
||||||
from langflow.api.v1.schemas import BuiltResponse, InitResponse, StreamData
|
from langflow.api.v1.schemas import BuiltResponse, InitResponse, StreamData
|
||||||
|
|
||||||
from langflow.chat.manager import ChatManager
|
from langflow.chat.manager import ChatManager
|
||||||
|
|
@ -123,9 +124,7 @@ async def stream_build(flow_id: str):
|
||||||
langchain_object = graph.build()
|
langchain_object = graph.build()
|
||||||
# Now we need to check the input_keys to send them to the client
|
# Now we need to check the input_keys to send them to the client
|
||||||
if hasattr(langchain_object, "input_keys"):
|
if hasattr(langchain_object, "input_keys"):
|
||||||
input_keys_response = {
|
input_keys_response = build_input_keys_response(langchain_object)
|
||||||
"input_keys": langchain_object.input_keys,
|
|
||||||
}
|
|
||||||
yield str(StreamData(event="input_keys", data=input_keys_response))
|
yield str(StreamData(event="input_keys", data=input_keys_response))
|
||||||
|
|
||||||
chat_manager.set_cache(flow_id, langchain_object)
|
chat_manager.set_cache(flow_id, langchain_object)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue