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

Merged
merged 6 commits into from
Jul 5, 2024

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.

@coveralls
Copy link
Collaborator

coveralls commented Jul 4, 2024

Pull Request Test Coverage Report for Build 9799313838

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.
  • 62 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.04%) to 90.003%

Files with Coverage Reduction New Missed Lines %
components/builders/answer_builder.py 1 98.28%
tracing/datadog.py 1 94.59%
components/generators/openai.py 2 96.34%
components/routers/conditional_router.py 2 97.4%
components/audio/whisper_local.py 5 92.19%
components/evaluators/llm_evaluator.py 6 94.74%
components/fetchers/link_content.py 12 78.49%
components/converters/azure.py 14 89.55%
core/pipeline/pipeline.py 19 73.83%
Totals Coverage Status
Change from base Build 9664851641: 0.04%
Covered Lines: 6770
Relevant Lines: 7522

💛 - 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.

Looks good to me now. 👍 Ready to be merged.
Sorry for taking exceptionally long for the review. The only changes I made is that the inputs remain unchanged so we don't overwrite the replies and meta inputs. In addition, I added one type ignore instead of casting and moved the extraction inside of the loop.
Thanks again for contributing to Haystack! 🎉

@julian-risch
Copy link
Member

@dfokina For updating the documentation, we need to add here that the AnswerBuilder works not only with Generators but also with ChatGenerators and that the replies input can be either a List[str] or a List[ChatMessage]: https://docs.haystack.deepset.ai/v2.3-unstable/docs/answerbuilder I'll create an issue for that and will assign you. We can sync on the changes and I can support you.

@julian-risch julian-risch merged commit e92a0e4 into deepset-ai:main Jul 5, 2024
17 checks passed
@lbux lbux deleted the answer-builder-chat branch July 6, 2024 21:25
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