Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io

This commit is contained in:
Lucas Oliveira 2023-06-28 17:13:43 -03:00
commit 78ffad4c85
4 changed files with 26 additions and 5 deletions

View file

@ -37,11 +37,11 @@ def build_input_keys_response(langchain_object):
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"]
input_keys_response["input_keys"] = {
key: value
for key, value in input_keys_response["input_keys"].items()
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

View file

@ -128,6 +128,8 @@ async def stream_build(flow_id: str):
yield str(StreamData(event="message", data=input_keys_response))
chat_manager.set_cache(flow_id, langchain_object)
# We need to reset the chat history
chat_manager.chat_history.empty_history(flow_id)
except Exception as exc:
logger.error("Error while building the flow: %s", exc)
yield str(StreamData(event="error", data={"error": str(exc)}))

View file

@ -61,6 +61,11 @@ def post_validate_prompt(prompt: ValidatePromptRequest):
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
# Now we will set the field "input_variables" to the new list of variables
# if it exists
if "input_variables" in prompt.frontend_node.template:
prompt.frontend_node.template["input_variables"]["value"] = input_variables
return PromptValidationResponse(
input_variables=input_variables,
frontend_node=prompt.frontend_node,

View file

@ -110,7 +110,21 @@ def instantiate_prompt(node_type, class_object, params):
if node_type == "ChatPromptTemplate":
return class_object.from_messages(**params)
return class_object(**params)
prompt = class_object(**params)
# Now we go through input_variables
# Check if they are in params, if so
# get their values and set them
format_kwargs = {}
for input_variable in prompt.input_variables:
if input_variable in params:
input_value = params[input_variable]
format_kwargs[input_variable] = input_value
if format_kwargs:
prompt = prompt.partial(**format_kwargs)
return prompt
def instantiate_tool(node_type, class_object, params):