haystack icon indicating copy to clipboard operation
haystack copied to clipboard

feat: Allow Connection of ChatGenerator to AnswerBuilder

Open lbux opened this issue 1 year ago • 6 comments

Related Issues

  • fixes #7839

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

lbux avatar Jun 19 '24 19:06 lbux

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.

lbux avatar Jun 21 '24 00:06 lbux

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%
<!-- Total: 4
Totals Coverage Status
Change from base Build 9583192592: 0.02%
Covered Lines: 7022
Relevant Lines: 7787

💛 - Coveralls

coveralls avatar Jun 24 '24 11:06 coveralls

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%
<!-- Total: 4
Totals Coverage Status
Change from base Build 9583192592: 0.02%
Covered Lines: 7022
Relevant Lines: 7787

💛 - Coveralls

coveralls avatar Jun 24 '24 11:06 coveralls

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%
<!-- Total: 101
Totals Coverage Status
Change from base Build 9583192592: -0.2%
Covered Lines: 6722
Relevant Lines: 7471

💛 - Coveralls

coveralls avatar Jun 25 '24 19:06 coveralls

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%
<!-- Total: 1
Totals Coverage Status
Change from base Build 9664851641: 0.007%
Covered Lines: 6722
Relevant Lines: 7471

💛 - Coveralls

coveralls avatar Jun 25 '24 19:06 coveralls

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.

lbux avatar Jun 25 '24 22:06 lbux

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%
<!-- Total: 62
Totals Coverage Status
Change from base Build 9664851641: 0.04%
Covered Lines: 6770
Relevant Lines: 7522

💛 - Coveralls

coveralls avatar Jul 04 '24 20:07 coveralls

@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 avatar Jul 05 '24 06:07 julian-risch