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

refactor: pass a role string to OpenAI API #7404

Merged
merged 2 commits into from
Mar 22, 2024
Merged

Conversation

anakin87
Copy link
Member

Related Issues

While investigating on chat use cases, I discovered that we are sending requests like this to OpenAI:
[{'content': 'You are a helpful assistant.', 'role': <ChatRole.SYSTEM: 'system'>}]

instead of [{'content': 'You are a helpful assistant.', 'role': 'system'}]

Although this probably causes no problems, it is best to pass the correct format.

Proposed Changes:

  • introduce a method to_openai_format in the ChatMessage dataclass
  • use it in OpenAI generators and HF TGI Chat generator

How did you test it?

New tests, CI

Checklist

@anakin87 anakin87 requested a review from a team as a code owner March 22, 2024 07:31
@anakin87 anakin87 requested review from vblagoje and removed request for a team March 22, 2024 07:31
@anakin87 anakin87 added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Mar 22, 2024
@github-actions github-actions bot added topic:tests 2.x Related to Haystack v2.0 type:documentation Improvements on the docs labels Mar 22, 2024
@coveralls
Copy link
Collaborator

coveralls commented Mar 22, 2024

Pull Request Test Coverage Report for Build 8386997297

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 23 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.02%) to 89.259%

Files with Coverage Reduction New Missed Lines %
components/generators/chat/hugging_face_tgi.py 2 94.85%
components/generators/openai.py 3 96.1%
components/generators/chat/openai.py 18 77.88%
Totals Coverage Status
Change from base Build 8376985254: -0.02%
Covered Lines: 5410
Relevant Lines: 6061

💛 - Coveralls

Copy link
Member

@vblagoje vblagoje left a comment

Choose a reason for hiding this comment

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

Nice catch thanks @anakin87

@anakin87 anakin87 merged commit c789f90 into main Mar 22, 2024
20 checks passed
@anakin87 anakin87 deleted the convert-messages-to-openai branch March 22, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to Haystack v2.0 ignore-for-release-notes PRs with this flag won't be included in the release notes. topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants