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

Improve UX for chat interaction #481

Open
pmeier opened this issue Aug 6, 2024 · 0 comments
Open

Improve UX for chat interaction #481

pmeier opened this issue Aug 6, 2024 · 0 comments
Labels
type: RFD ⚖️ Decision making
Milestone

Comments

@pmeier
Copy link
Member

pmeier commented Aug 6, 2024

I propose three improvements:

  1. Remove the context manager for a Chat

    ragna/ragna/core/_rag.py

    Lines 402 to 409 in 7071cf4

    async def __aenter__(self) -> Chat:
    await self.prepare()
    return self
    async def __aexit__(
    self, exc_type: Type[Exception], exc: Exception, traceback: str
    ) -> None:
    pass

    It was somewhat quirky to begin with, because we only had enter but not exit logic. But after Add metadata filter handling for builtin source storages #456 we have regular use cases where we don't want to call await chat.prepare().

  2. Add a prepare: Optional[bool] = None flag to Chat.answer(). If omitted, i.e. prepare is None, we can check self._prepared and call self.prepare if required. This skips the need for the user to call Chat.prepare() explicitly and streamlines the UX. Note that if Make Chat.prepare idempotent #480 is accepted, we can make the flag prepare: bool = True.

The points above would transform

async with Rag().chat(...) as chat:
    message = await chat.answer(...)

into

chat = Rag().chat(...)
message = await chat.answer(...)
  1. I'm a little on the fence on this one, but I'm going to propose it anyway to see what others think of it: add a __acall__() method to Chat that either defers to or completely replaces Chat.answer().

This would simplify the snippet from above even further to

chat = Rag().chat(...)
message = await chat(...)
@pmeier pmeier added the type: RFD ⚖️ Decision making label Aug 6, 2024
@pmeier pmeier added this to the 0.3.0 milestone Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: RFD ⚖️ Decision making
Projects
None yet
Development

No branches or pull requests

1 participant