From 46959acaa95dec3f5bade648eacc0124f723d469 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Mon, 29 May 2023 18:52:47 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A8=20refactor(prompts.py):=20swap?= =?UTF-8?q?=20suffix=20and=20format=5Finstructions=20fields=20=F0=9F=94=A8?= =?UTF-8?q?=20refactor(util.py):=20add=20format=5Finstructions=20to=20the?= =?UTF-8?q?=20list=20of=20fields=20to=20format=20in=20format=5Fdict=20func?= =?UTF-8?q?tion=20The=20suffix=20and=20format=5Finstructions=20fields=20in?= =?UTF-8?q?=20the=20ZeroShotPromptNode=20class=20were=20swapped=20to=20imp?= =?UTF-8?q?rove=20the=20readability=20of=20the=20code.=20The=20format=5Fin?= =?UTF-8?q?structions=20field=20is=20now=20above=20the=20suffix=20field,?= =?UTF-8?q?=20which=20makes=20more=20sense=20as=20it=20is=20a=20required?= =?UTF-8?q?=20field.=20In=20the=20util.py=20file,=20the=20format=5Finstruc?= =?UTF-8?q?tions=20field=20was=20added=20to=20the=20list=20of=20fields=20t?= =?UTF-8?q?o=20format=20in=20the=20format=5Fdict=20function.=20This=20ensu?= =?UTF-8?q?res=20that=20the=20format=5Finstructions=20field=20is=20properl?= =?UTF-8?q?y=20formatted=20when=20the=20function=20is=20called.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/template/frontend_node/prompts.py | 14 +++++++++----- src/backend/langflow/utils/util.py | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/prompts.py b/src/backend/langflow/template/frontend_node/prompts.py index 830623a7e..7d7b1cde2 100644 --- a/src/backend/langflow/template/frontend_node/prompts.py +++ b/src/backend/langflow/template/frontend_node/prompts.py @@ -89,18 +89,18 @@ class ZeroShotPromptNode(BasePromptFrontendNode): is_list=False, show=True, multiline=True, - value=prompt.SUFFIX, - name="suffix", + value=prompt.FORMAT_INSTRUCTIONS, + name="format_instructions", ), TemplateField( field_type="str", - required=False, + required=True, placeholder="", is_list=False, show=True, multiline=True, - value=prompt.FORMAT_INSTRUCTIONS, - name="format_instructions", + value=prompt.SUFFIX, + name="suffix", ), ], ) @@ -109,3 +109,7 @@ class ZeroShotPromptNode(BasePromptFrontendNode): def to_dict(self): return super().to_dict() + + @staticmethod + def format_field(field: TemplateField, name: Optional[str] = None) -> None: + PromptFrontendNode.format_field(field, name) diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index af49856d7..0c9a18335 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -273,6 +273,7 @@ def format_dict(d, name: Optional[str] = None): "examples", "code", "headers", + "format_instructions", ] # Replace dict type with str From c05b94e4e90e4ece9be16b4f2f54202697448fdd Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Mon, 29 May 2023 18:57:56 -0300 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9A=80=20feat(test=5Fprompts=5Ftempla?= =?UTF-8?q?te.py):=20change=20type=20of=20"suffix"=20and=20"prefix"=20fiel?= =?UTF-8?q?ds=20to=20"prompt"=20and=20update=20"format=5Finstructions"=20f?= =?UTF-8?q?ield=20The=20"suffix"=20and=20"prefix"=20fields=20have=20been?= =?UTF-8?q?=20changed=20from=20type=20"str"=20to=20"prompt"=20to=20allow?= =?UTF-8?q?=20for=20more=20flexibility=20in=20the=20input.=20The=20"format?= =?UTF-8?q?=5Finstructions"=20field=20has=20been=20updated=20to=20be=20req?= =?UTF-8?q?uired=20and=20multiline,=20and=20to=20show=20the=20instructions?= =?UTF-8?q?=20by=20default.=20This=20change=20will=20make=20it=20easier=20?= =?UTF-8?q?for=20users=20to=20understand=20the=20expected=20input=20format?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_prompts_template.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_prompts_template.py b/tests/test_prompts_template.py index 1fe6f3775..83da2f14d 100644 --- a/tests/test_prompts_template.py +++ b/tests/test_prompts_template.py @@ -182,7 +182,7 @@ def test_zero_shot_prompt(client: TestClient): "value": "Answer the following questions as best you can. You have access to the following tools:", # noqa: E501 "password": False, "name": "prefix", - "type": "str", + "type": "prompt", "list": False, "advanced": False, } @@ -194,19 +194,19 @@ def test_zero_shot_prompt(client: TestClient): "value": "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}", "password": False, "name": "suffix", - "type": "str", + "type": "prompt", "list": False, "advanced": False, } assert template["format_instructions"] == { - "required": False, + "required": True, "placeholder": "", - "show": False, - "multiline": False, + "show": True, + "multiline": True, "value": "Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question", # noqa: E501 "password": False, "name": "format_instructions", - "type": "str", + "type": "prompt", "list": False, "advanced": False, }