Skip to content

Commit

Permalink
fix: leading whitespace is missing in the generated text when using `…
Browse files Browse the repository at this point in the history
…stop_words` (#5511)

* bug fix

* add release note

* Update releasenotes/notes/fix-stop-words-strip-issue-22ce51306e7b91e4.yaml

Co-authored-by: Stefano Fiorucci <[email protected]>

* Update releasenotes/notes/fix-stop-words-strip-issue-22ce51306e7b91e4.yaml

Co-authored-by: Stefano Fiorucci <[email protected]>

---------

Co-authored-by: Stefano Fiorucci <[email protected]>
  • Loading branch information
faaany and anakin87 authored Aug 4, 2023
1 parent abc6737 commit 4496fc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion haystack/nodes/prompt/invocation_layer/hugging_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def invoke(self, *args, **kwargs):
# We want to exclude it to be consistent with other invocation layers
for idx, _ in enumerate(generated_texts):
for stop_word in stop_words:
generated_texts[idx] = generated_texts[idx].replace(stop_word, "").strip()
generated_texts[idx] = generated_texts[idx].replace(stop_word, "").rstrip()
return generated_texts

def _ensure_token_limit(self, prompt: Union[str, List[Dict[str, str]]]) -> Union[str, List[Dict[str, str]]]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Ensure the leading whitespace in the generated text is preserved when using `stop_words` in the Hugging Face invocation layer of the PromptNode.

0 comments on commit 4496fc6

Please sign in to comment.