[go: nahoru, domu]

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

feat: Allow Connection of ChatGenerator to AnswerBuilder #7897

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lbux
Copy link
Contributor
@lbux lbux commented Jun 19, 2024

Related Issues

Proposed Changes:

This PR makes it possible to pass in a ChatMessage to AnswerBuilder

How did you test it?

Replicated str tests for ChatMessages.

Notes for the reviewer

Checklist

@github-actions github-actions bot added the type:documentation Improvements on the docs label Jun 19, 2024
@lbux lbux marked this pull request as ready for review June 21, 2024 00:47
@lbux lbux requested review from a team as code owners June 21, 2024 00:47
@lbux lbux requested review from dfokina and julian-risch and removed request for a team June 21, 2024 00:47
@lbux
Copy link
Contributor Author
lbux commented Jun 21, 2024

ChatGenerators only return replies, so when you connect a ChatGenerator to an AnswerBuilder, you have to use llm -> answer_builder as shown here:
rag_pipeline.connect("llm", "answer_builder")

Why not add support for .meta in a ChatGenerator?

The metadata is already contained in a ChatMessage. If we add support for metadata output of the ChatGenerator, we will be sending redundant data.

@coveralls
Copy link
Collaborator
coveralls commented Jun 24, 2024

Pull Request Test Coverage Report for Build 9606421122

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 4 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.02%) to 90.176%

Files with Coverage Reduction New Missed Lines %
components/builders/answer_builder.py 1 98.33%
components/builders/chat_prompt_builder.py 1 98.41%
document_stores/types/filter_policy.py 2 84.21%
Totals Coverage Status
Change from base Build 9583192592: 0.02%
Covered Lines: 7022
Relevant Lines: 7787

💛 - Coveralls

@coveralls
Copy link
Collaborator
coveralls commented Jun 24, 2024

Pull Request Test Coverage Report for Build 9606450913

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 4 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.02%) to 90.176%

Files with Coverage Reduction New Missed Lines %
components/builders/answer_builder.py 1 98.33%
components/builders/chat_prompt_builder.py 1 98.41%
document_stores/types/filter_policy.py 2 84.21%
Totals Coverage Status
Change from base Build 9583192592: 0.02%
Covered Lines: 7022
Relevant Lines: 7787

💛 - Coveralls

Copy link
Member
@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @lbux . The PR looks quite good to me already! 👍 There are just four mypy issues we need to fix:

haystack/components/builders/answer_builder.py:110: error: Item "str" of "Union[str, ChatMessage]" has no attribute "meta"  [union-attr]
haystack/components/builders/answer_builder.py:111: error: Item "str" of "Union[str, ChatMessage]" has no attribute "content"  [union-attr]
haystack/components/builders/answer_builder.py:119: error: Argument 1 to "_extract_reference_idxs" of "AnswerBuilder" has incompatible type "object"; expected "str"  [arg-type]
haystack/components/builders/answer_builder.py:131: error: Argument 1 to "_extract_answer_string" of "AnswerBuilder" has incompatible type "object"; expected "str"  [arg-type]

In addition, we should extend the release note to explain a bit more that the AnswerBuilder now accepts ChatMessages as input in addition to strings and that the metadata of the ChatMessage will be added to the Answer. Please let me know if you need any help here. Happy to address these change requests and pushing the PR over the finish line. 🙂

@coveralls
Copy link
Collaborator
coveralls commented Jun 25, 2024

Pull Request Test Coverage Report for Build 9668079863

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 101 unchanged lines in 11 files lost coverage.
  • Overall coverage decreased (-0.2%) to 89.975%

Files with Coverage Reduction New Missed Lines %
components/builders/answer_builder.py 1 98.36%
components/builders/chat_prompt_builder.py 1 98.41%
components/evaluators/document_map.py 1 96.15%
components/evaluators/document_mrr.py 1 95.45%
core/component/component.py 2 98.28%
document_stores/types/filter_policy.py 2 84.21%
components/converters/pypdf.py 6 90.0%
components/evaluators/sas_evaluator.py 8 63.33%
document_stores/in_memory/document_store.py 9 97.02%
utils/hf.py 20 83.89%
Totals Coverage Status
Change from base Build 9583192592: -0.2%
Covered Lines: 6722
Relevant Lines: 7471

💛 - Coveralls

@coveralls
Copy link
Collaborator
coveralls commented Jun 25, 2024

Pull Request Test Coverage Report for Build 9668339128

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.007%) to 89.975%

Files with Coverage Reduction New Missed Lines %
components/builders/answer_builder.py 1 98.36%
Totals Coverage Status
Change from base Build 9664851641: 0.007%
Covered Lines: 6722
Relevant Lines: 7471

💛 - Coveralls

@lbux
Copy link
Contributor Author
lbux commented Jun 25, 2024

The mypy issues were resolved by explicitly casting as I did not want to just # type: ignore, but it can be done if that is preferred. I was hoping the isinstance check would be enough, but mypy still thinks we are trying to do ChatMessage logic on a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Chat Generators to connect to Answer Builder
3 participants