From ff0abf51839dec1113e350e403055e40f6954e49 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 26 Jun 2023 10:20:28 -0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20refactor(chat.py):=20refacto?= =?UTF-8?q?r=20stream=5Fbuild=20function=20to=20send=20input=5Fkeys=20to?= =?UTF-8?q?=20the=20client=20The=20stream=5Fbuild=20function=20has=20been?= =?UTF-8?q?=20refactored=20to=20send=20input=5Fkeys=20to=20the=20client=20?= =?UTF-8?q?if=20the=20langchain=5Fobject=20has=20the=20attribute=20"input?= =?UTF-8?q?=5Fkeys".=20This=20change=20improves=20the=20user=20experience?= =?UTF-8?q?=20by=20providing=20the=20client=20with=20the=20necessary=20inp?= =?UTF-8?q?ut=20keys=20to=20continue=20the=20conversation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index be9d6802c..666c5d3cd 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -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)})) From ebcaedb84000008c4fced20d6c078b5e92ee791d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 26 Jun 2023 10:20:48 -0300 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20feat(base.py):=20add=20input=20?= =?UTF-8?q?validation=20for=20PromptTemplate=20to=20ensure=20that=20the=20?= =?UTF-8?q?template=20and=20input=20variables=20are=20valid=20The=20commen?= =?UTF-8?q?ted=20out=20code=20was=20removed=20to=20improve=20code=20readab?= =?UTF-8?q?ility.=20Input=20validation=20was=20added=20to=20ensure=20that?= =?UTF-8?q?=20the=20template=20and=20input=20variables=20are=20valid=20bef?= =?UTF-8?q?ore=20creating=20a=20PromptTemplate=20object.=20This=20helps=20?= =?UTF-8?q?to=20prevent=20errors=20that=20may=20occur=20when=20the=20objec?= =?UTF-8?q?t=20is=20created=20with=20invalid=20input.=20=F0=9F=94=92=20cho?= =?UTF-8?q?re(base.py):=20remove=20commented=20out=20code=20and=20add=20in?= =?UTF-8?q?put=20validation=20for=20PromptTemplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/base.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/langflow/api/v1/base.py b/src/backend/langflow/api/v1/base.py index 6941bedf3..d595210bb 100644 --- a/src/backend/langflow/api/v1/base.py +++ b/src/backend/langflow/api/v1/base.py @@ -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) From 423caa5ddccf7e2ece70badcee9767fedec84070 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 26 Jun 2023 10:22:27 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=8D=20chore(.gitignore):=20add=20p?= =?UTF-8?q?repare-commit-msg=20to=20avoid=20pushing=20Opencommit=20hook=20?= =?UTF-8?q?The=20prepare-commit-msg=20file=20is=20added=20to=20the=20.giti?= =?UTF-8?q?gnore=20file=20to=20avoid=20pushing=20the=20Opencommit=20hook?= =?UTF-8?q?=20to=20the=20remote=20repository.=20This=20is=20done=20to=20pr?= =?UTF-8?q?event=20the=20hook=20from=20being=20executed=20on=20other=20mac?= =?UTF-8?q?hines=20and=20to=20avoid=20any=20issues=20that=20may=20arise=20?= =?UTF-8?q?from=20the=20hook=20being=20executed=20on=20different=20machine?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 36af35fa2..ee56c6e1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# This is to avoid Opencommit hook from getting pushed +prepare-commit-msg # Logs logs *.log