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

This commit is contained in:
Lucas Oliveira 2023-06-26 10:34:43 -03:00
commit 466d583103
3 changed files with 19 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
# This is to avoid Opencommit hook from getting pushed
prepare-commit-msg
# Logs
logs
*.log

View file

@ -1,6 +1,7 @@
from pydantic import BaseModel, validator
from langflow.interface.utils import extract_input_variables_from_prompt
from langchain.prompts import PromptTemplate
class CacheResponse(BaseModel):
@ -57,6 +58,13 @@ def validate_prompt(template: str):
# Check if there are invalid characters in the input_variables
input_variables = check_input_variables(input_variables)
try:
PromptTemplate(template=template, input_variables=input_variables)
except Exception as exc:
raise ValueError(str(exc)) from exc
# if len(input_variables) > 1:
# # If there's more than one input variable
return PromptValidationResponse(input_variables=input_variables)

View file

@ -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)}))