Skip to content

Commit

Permalink
fix: OutputParser when used within PromptTemplate (#7587)
Browse files Browse the repository at this point in the history
* fix: extracting results from OutputParser

* add reno
  • Loading branch information
tstadel authored and vblagoje committed Apr 23, 2024
1 parent 32199b8 commit 5618d1e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
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

0 comments on commit 5618d1e

Please sign in to comment.