Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OutputParser when used within PromptTemplate #7587

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions haystack/nodes/prompt/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ def post_process(self, prompt_output: List[str], **kwargs) -> List[Any]:
if self.output_parser:
invocation_context = kwargs
invocation_context["results"] = prompt_output
self.output_parser.run(invocation_context=invocation_context)
return invocation_context[self.output_parser.outputs[0]]
parser_results, _ = self.output_parser.run(invocation_context=invocation_context)
return parser_results[self.output_parser.outputs[0]]
else:
return prompt_output

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixes OutputParser usage in PromptTemplate after making invocation context immutable in https://github.com/deepset-ai/haystack/pull/7510.
3 changes: 1 addition & 2 deletions test/prompt/test_prompt_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ def test_pipeline_with_prompt_template_at_query_time(prompt_model):
)


@pytest.mark.skip
@pytest.mark.integration
def test_pipeline_with_prompt_template_and_nested_shaper_yaml(tmp_path):
# TODO: This can be a Shaper unit test?
Expand All @@ -444,7 +443,7 @@ def test_pipeline_with_prompt_template_and_nested_shaper_yaml(tmp_path):
- name: template_with_nested_shaper
type: PromptTemplate
params:
prompt: "Given the context please answer the question. Context: {{documents}}; Question: {{query}}; Answer: "
prompt: "Given the context please answer the question. Context: {documents}; Question: {query}; Answer: "
output_parser:
type: AnswerParser
- name: p1
Expand Down
Loading