Added format_instructions to ZeroShotPrompt (#402)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-05-29 22:45:55 -03:00 • committed by GitHub
commit 09cb59d9d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View file

@ -89,18 +89,18 @@ class ZeroShotPromptNode(BasePromptFrontendNode):
is_list=False, is_list=False,
show=True, show=True,
multiline=True, multiline=True,
value=prompt.SUFFIX, value=prompt.FORMAT_INSTRUCTIONS,
name="suffix", name="format_instructions",
), ),
TemplateField( TemplateField(
field_type="str", field_type="str",
required=False, required=True,
placeholder="", placeholder="",
is_list=False, is_list=False,
show=True, show=True,
multiline=True, multiline=True,
value=prompt.FORMAT_INSTRUCTIONS, value=prompt.SUFFIX,
name="format_instructions", name="suffix",
), ),
], ],
) )
@ -109,3 +109,7 @@ class ZeroShotPromptNode(BasePromptFrontendNode):
def to_dict(self): def to_dict(self):
return super().to_dict() return super().to_dict()
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
PromptFrontendNode.format_field(field, name)

View file

@ -273,6 +273,7 @@ def format_dict(d, name: Optional[str] = None):
"examples", "examples",
"code", "code",
"headers", "headers",
"format_instructions",
] ]
# Replace dict type with str # Replace dict type with str

View file

@ -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 "value": "Answer the following questions as best you can. You have access to the following tools:", # noqa: E501
"password": False, "password": False,
"name": "prefix", "name": "prefix",
"type": "str", "type": "prompt",
"list": False, "list": False,
"advanced": False, "advanced": False,
} }
@ -194,19 +194,19 @@ def test_zero_shot_prompt(client: TestClient):
"value": "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}", "value": "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}",
"password": False, "password": False,
"name": "suffix", "name": "suffix",
"type": "str", "type": "prompt",
"list": False, "list": False,
"advanced": False, "advanced": False,
} }
assert template["format_instructions"] == { assert template["format_instructions"] == {
"required": False, "required": True,
"placeholder": "", "placeholder": "",
"show": False, "show": True,
"multiline": False, "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 "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, "password": False,
"name": "format_instructions", "name": "format_instructions",
"type": "str", "type": "prompt",
"list": False, "list": False,
"advanced": False, "advanced": False,
} }