Support contextual session management#55
Conversation
Signed-off-by: elronbandel <elronbandel@gmail.com>
| from typing import Literal | ||
|
|
||
| from mellea import generative, start_session | ||
| from mellea import generative, session |
There was a problem hiding this comment.
I do worry a bit about confusion arising from session vs start_session vs MelleaSession but I'm probably just being paranoid.
There was a problem hiding this comment.
It is confusing. For now I added the context management ability to start_session so we have only start_session which now works also with with start_session():. In the future we can consider having one name that represents both modes, and deprecating this one. Anyways if and when it should be separate PR.
|
I'm inclined to merge; I like it. Adding @HendrikStrobelt as a reviewer to make sure I'm not missing anything obvious. @elronbandel did you test this with mobject stuff? |
…ed objects Signed-off-by: elronbandel <elronbandel@gmail.com>
|
@nrfulton I added comprehensive tests, including mified objects. |
Signed-off-by: elronbandel <elronbandel@gmail.com>
|
LGTM. We need to create some documentation about this, probably in the Context Management section of the tutorial I'll create a new issue for this and merge for now, so that we're not gating a new feature on docs. |
* Support contextual session management Signed-off-by: elronbandel <elronbandel@gmail.com> * Add comprehensive tests for contextual session functionality and mified objects Signed-off-by: elronbandel <elronbandel@gmail.com> * Unify session and start_session Signed-off-by: elronbandel <elronbandel@gmail.com> --------- Signed-off-by: elronbandel <elronbandel@gmail.com>
Adds Python contextvars support to enable implicit session usage,
providing a cleaner API while maintaining full backwards compatibility.
Changes
session()that manages session lifecycleinstruct(),chat(),validate(),query(),transform()use current active context session (and fail if called outside the context)session parameter
Usage
New (cleaner):
Still works:
Also works: