deepset-ai / deepset-ai/haystack
Updates to the ChatGenerator protocol
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 26.6k
- Forks
- 3.2k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 194
Description
Two ideas for updating the ChatGenerator protocol:
- Update the return type of the
runmethod to at least requirereplies: list[ChatMessage]since we rely on that key being present when we use the protocol in the codebase. This should be possible through usingTypedDict,total=FalseandRequired(still needs to be tested). So something like
from typing import Protocol
from typing_extensions import Required, TypedDict
from haystack.dataclasses import ChatMessage
class ChatGeneratorOutput(TypedDict, total=False):
"""
Return type for Chat Generators.
``replies`` is always required. Implementations may include additional keys.
"""
replies: Required[list[ChatMessage]]
class ChatGenerator(Protocol):
def run(self, messages: list[ChatMessage]) -> ChatGeneratorOutput:
- Consider adding a
run_asyncto the protocol since we have finished addingrun_asyncto all of our chat generators in core and in core-integrations https://github.com/deepset-ai/haystack/issues/8858 and https://github.com/deepset-ai/haystack-core-integrations/issues/1379. Only a consideration since it's not guaranteed that community made components follow the protocol, but we are starting to addrun_asyncmethods to components that use theChatGeneratorprotocol so I wonder if creating a second protocol (e.g.ChatGeneratorWithAsync) would be an alternative.
👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the ChatGenerator protocol and its implementations, then review how run return values and run_async methods are used across the codebase. Check issues #8858 and #1379 for the existing async work. Done would mean an agreed protocol design with its typing and async implications addressed, though the issue states that this work is handled internally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100