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

fix: ChatPromptBuilder Fails to JSON Serialize #7849

Merged
merged 16 commits into from
Jun 20, 2024

Conversation

CarlosFerLo
Copy link
Contributor

@CarlosFerLo CarlosFerLo commented Jun 12, 2024

Related Issues

Proposed Changes:

The bug was caused by the 'ChatMessage' class not being serialized correctly, which led to a failure in the serialization of 'ChatPromptTemplate'. To resolve this issue, 'to_dict' and 'from_dict' methods were added to both classes, ensuring proper serialization.

How did you test it?

Added testing for all the new methods and reproduced the scenario presented on #7844 , it works fine now

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes ✅
  • I added unit tests and updated the docstrings ✅
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test:. ✅
  • I documented my code ✅
  • I ran pre-commit hooks and fixed any issue ✅

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Jun 12, 2024
@coveralls
Copy link
Collaborator

coveralls commented Jun 12, 2024

Pull Request Test Coverage Report for Build 9489988243

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 89.808%

Totals Coverage Status
Change from base Build 9480552838: 0.03%
Covered Lines: 6926
Relevant Lines: 7712

💛 - Coveralls

@CarlosFerLo CarlosFerLo changed the title ChatPromptBuilder Fails to JSON Serialize due to ChatMessage class fix: ChatPromptBuilder Fails to JSON Serialize Jun 13, 2024
@coveralls
Copy link
Collaborator

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9499141713

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.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 89.678%

Files with Coverage Reduction New Missed Lines %
components/converters/docx.py 11 58.33%
Totals Coverage Status
Change from base Build 9480552838: -0.1%
Covered Lines: 6924
Relevant Lines: 7721

💛 - Coveralls

@CarlosFerLo
Copy link
Contributor Author

I do not know if this is the place for this, but I've found a doc string on 'ChatPromptTemplate' that is misleading:

:param required_variables: An optional list of input variables that must be provided at all times.
            If not provided, an exception will be raised.

I believe that, when reading it, it means that if 'required_variables' argument is not provided the function fails, but instead it means that the run method raises an exception if some of those variables is not provided.

Should I fix this one here or open another PR for it.

@CarlosFerLo CarlosFerLo marked this pull request as ready for review June 13, 2024 20:48
@CarlosFerLo CarlosFerLo requested review from a team as code owners June 13, 2024 20:48
@CarlosFerLo CarlosFerLo requested review from dfokina and davidsbatista and removed request for a team June 13, 2024 20:48
@coveralls
Copy link
Collaborator

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9506510225

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 89.678%

Totals Coverage Status
Change from base Build 9497203825: 0.04%
Covered Lines: 6924
Relevant Lines: 7721

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9506509369

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 89.678%

Totals Coverage Status
Change from base Build 9497203825: 0.04%
Covered Lines: 6924
Relevant Lines: 7721

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9506565575

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 89.678%

Totals Coverage Status
Change from base Build 9497203825: 0.04%
Covered Lines: 6924
Relevant Lines: 7721

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9506715329

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 89.678%

Totals Coverage Status
Change from base Build 9497203825: 0.04%
Covered Lines: 6924
Relevant Lines: 7721

💛 - Coveralls

haystack/dataclasses/chat_message.py Outdated Show resolved Hide resolved
@coveralls
Copy link
Collaborator

coveralls commented Jun 15, 2024

Pull Request Test Coverage Report for Build 9527200328

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.
  • 40 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.77%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
core/pipeline/base.py 7 92.5%
core/pipeline/pipeline.py 32 68.31%
Totals Coverage Status
Change from base Build 9497203825: 0.1%
Covered Lines: 6950
Relevant Lines: 7742

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 15, 2024

Pull Request Test Coverage Report for Build 9528525456

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.03%) to 89.77%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
Totals Coverage Status
Change from base Build 9518891629: 0.03%
Covered Lines: 6950
Relevant Lines: 7742

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566152365

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.03%) to 89.788%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
Totals Coverage Status
Change from base Build 9565773860: 0.03%
Covered Lines: 6955
Relevant Lines: 7746

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9566276770

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.02%) to 89.786%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
Totals Coverage Status
Change from base Build 9565773860: 0.02%
Covered Lines: 6953
Relevant Lines: 7744

💛 - Coveralls

haystack/dataclasses/chat_message.py Outdated Show resolved Hide resolved
haystack/dataclasses/chat_message.py Outdated Show resolved Hide resolved
@CarlosFerLo CarlosFerLo requested a review from shadeMe June 18, 2024 18:13
@CarlosFerLo
Copy link
Contributor Author

Do not know why tests fail 🫠, will work on it later.

@davidsbatista
Copy link
Contributor

seems to be just a linting issue

@CarlosFerLo
Copy link
Contributor Author

@davidsbatista how can I solve that? I used the pre-commit hooks and they all passed.

@davidsbatista
Copy link
Contributor

I suspect updating the branch might fixe it

@davidsbatista
Copy link
Contributor

seems like this file test/dataclasses/test_chat_message.py is not being properly formatted.

@CarlosFerLo
Copy link
Contributor Author

seems like this file test/dataclasses/test_chat_message.py is not being properly formatted.
@davidsbatista I see that, but how do we solve that jajaja

@lbux
Copy link
Contributor

lbux commented Jun 19, 2024

seems like this file test/dataclasses/test_chat_message.py is not being properly formatted.
@davidsbatista I see that, but how do we solve that jajaja

You need to make sure you have the same Hatch version as the CI. Ensure it is 1.9.3, Newer versions will produce inconsistent results.
image

@coveralls
Copy link
Collaborator

coveralls commented Jun 19, 2024

Pull Request Test Coverage Report for Build 9587909214

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.01%) to 90.165%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
Totals Coverage Status
Change from base Build 9583192592: 0.01%
Covered Lines: 7013
Relevant Lines: 7778

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 19, 2024

Pull Request Test Coverage Report for Build 9587996856

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.01%) to 90.165%

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.41%
Totals Coverage Status
Change from base Build 9583192592: 0.01%
Covered Lines: 7013
Relevant Lines: 7778

💛 - Coveralls

@CarlosFerLo CarlosFerLo requested a review from shadeMe June 20, 2024 10:54
@shadeMe shadeMe merged commit 57c1d47 into deepset-ai:main Jun 20, 2024
17 checks passed
@sherrywang31
Copy link

sherrywang31 commented Jul 2, 2024

It seems that this change is not in the v2.2.3? I downloaded the source code and noticed that the ChatMessage as well as ChatPromptBuilder class doesn't have 'to_dict' and 'from_dict' functions. Is it expected...?

@sherrywang31
Copy link

Also, I noticed that there's no default value for optional input "name". When using the "from_dict" function in ChatMessage, it would complain "name" is missing in initialization.

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.

ChatPromptBuilder Fails to JSON Serialize due to ChatMessage class
6 participants