From f56e31163a61439e82fcd202090a8fb996198480 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 10 Jul 2023 13:22:44 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20handle=20KeyErr?= =?UTF-8?q?or=20when=20formatting=20prompt=20with=20artifacts=20to=20preve?= =?UTF-8?q?nt=20application=20crash=20=F0=9F=94=80=20refactor(types.py):?= =?UTF-8?q?=20remove=20"handle=5Fkeys"=20from=20artifacts=20before=20forma?= =?UTF-8?q?tting=20prompt=20to=20avoid=20format=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/types.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/graph/vertex/types.py b/src/backend/langflow/graph/vertex/types.py index 6d9a28356..9c02ef847 100644 --- a/src/backend/langflow/graph/vertex/types.py +++ b/src/backend/langflow/graph/vertex/types.py @@ -220,7 +220,14 @@ class PromptVertex(Vertex): # We'll build the prompt with the artifacts # to show the user what the prompt looks like # with the variables filled in - return self._built_object.format(**self.artifacts) + artifacts = self.artifacts.copy() + # Remove the handle_keys from the artifacts + # so the prompt format doesn't break + artifacts.pop("handle_keys", None) + try: + return self._built_object.format(**self.artifacts) + except KeyError: + return super()._built_object_repr() else: return super()._built_object_repr()