Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io
This commit is contained in:
commit
a50e089401
4 changed files with 24 additions and 4 deletions
|
|
@ -24,13 +24,18 @@ def remove_api_keys(flow: dict):
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
|
|
||||||
def build_input_keys_response(langchain_object):
|
def build_input_keys_response(langchain_object, artifacts):
|
||||||
"""Build the input keys response."""
|
"""Build the input keys response."""
|
||||||
|
|
||||||
input_keys_response = {
|
input_keys_response = {
|
||||||
"input_keys": {key: "" for key in langchain_object.input_keys},
|
"input_keys": {key: "" for key in langchain_object.input_keys},
|
||||||
"memory_keys": [],
|
"memory_keys": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set the input keys values from artifacts
|
||||||
|
for key, value in artifacts.items():
|
||||||
|
if key in input_keys_response["input_keys"]:
|
||||||
|
input_keys_response["input_keys"][key] = value
|
||||||
# If the object has memory, that memory will have a memory_variables attribute
|
# If the object has memory, that memory will have a memory_variables attribute
|
||||||
# memory variables should be removed from the input keys
|
# memory variables should be removed from the input keys
|
||||||
if hasattr(langchain_object, "memory") and hasattr(
|
if hasattr(langchain_object, "memory") and hasattr(
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ async def stream_build(flow_id: str):
|
||||||
|
|
||||||
async def event_stream(flow_id):
|
async def event_stream(flow_id):
|
||||||
final_response = {"end_of_stream": True}
|
final_response = {"end_of_stream": True}
|
||||||
|
artifacts = {}
|
||||||
try:
|
try:
|
||||||
if flow_id not in flow_data_store:
|
if flow_id not in flow_data_store:
|
||||||
error_message = "Invalid session ID"
|
error_message = "Invalid session ID"
|
||||||
|
|
@ -108,6 +109,11 @@ async def stream_build(flow_id: str):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Building node {params[:50]}{'...' if len(params) > 50 else ''}"
|
f"Building node {params[:50]}{'...' if len(params) > 50 else ''}"
|
||||||
)
|
)
|
||||||
|
if vertex.artifacts:
|
||||||
|
# The artifacts will be prompt variables
|
||||||
|
# passed to build_input_keys_response
|
||||||
|
# to set the input_keys values
|
||||||
|
artifacts.update(vertex.artifacts)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
params = str(exc)
|
params = str(exc)
|
||||||
valid = False
|
valid = False
|
||||||
|
|
@ -124,7 +130,9 @@ 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 = build_input_keys_response(langchain_object)
|
input_keys_response = build_input_keys_response(
|
||||||
|
langchain_object, artifacts
|
||||||
|
)
|
||||||
yield str(StreamData(event="message", data=input_keys_response))
|
yield str(StreamData(event="message", data=input_keys_response))
|
||||||
|
|
||||||
chat_manager.set_cache(flow_id, langchain_object)
|
chat_manager.set_cache(flow_id, langchain_object)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class Vertex:
|
||||||
self._parse_data()
|
self._parse_data()
|
||||||
self._built_object = None
|
self._built_object = None
|
||||||
self._built = False
|
self._built = False
|
||||||
|
self.artifacts: Dict[str, Any] = {}
|
||||||
|
|
||||||
def _parse_data(self) -> None:
|
def _parse_data(self) -> None:
|
||||||
self.data = self._data["data"]
|
self.data = self._data["data"]
|
||||||
|
|
@ -195,11 +196,17 @@ class Vertex:
|
||||||
# and return the instance
|
# and return the instance
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._built_object = loading.instantiate_class(
|
result = loading.instantiate_class(
|
||||||
node_type=self.vertex_type,
|
node_type=self.vertex_type,
|
||||||
base_type=self.base_type,
|
base_type=self.base_type,
|
||||||
params=self.params,
|
params=self.params,
|
||||||
)
|
)
|
||||||
|
# Result could be the _built_object or
|
||||||
|
# (_built_object, dict) tuple
|
||||||
|
if isinstance(result, tuple):
|
||||||
|
self._built_object, self.artifacts = result
|
||||||
|
else:
|
||||||
|
self._built_object = result
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Error building node {self.vertex_type}: {str(exc)}"
|
f"Error building node {self.vertex_type}: {str(exc)}"
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ def instantiate_prompt(node_type, class_object, params):
|
||||||
if format_kwargs:
|
if format_kwargs:
|
||||||
prompt = prompt.partial(**format_kwargs)
|
prompt = prompt.partial(**format_kwargs)
|
||||||
|
|
||||||
return prompt
|
return prompt, format_kwargs
|
||||||
|
|
||||||
|
|
||||||
def instantiate_tool(node_type, class_object, params):
|
def instantiate_tool(node_type, class_object, params):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue