-
Notifications
You must be signed in to change notification settings - Fork 31
Description
I propose three improvements:
-
Remove the context manager for a
ChatLines 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(). -
Add a
prepare: Optional[bool] = Noneflag toChat.answer(). If omitted, i.e.prepare is None, we can checkself._preparedand callself.prepareif required. This skips the need for the user to callChat.prepare()explicitly and streamlines the UX. Note that if Make Chat.prepare idempotent #480 is accepted, we can make the flagprepare: 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(...)- 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 toChatthat either defers to or completely replacesChat.answer().
This would simplify the snippet from above even further to
chat = Rag().chat(...)
message = await chat(...)