-
Notifications
You must be signed in to change notification settings - Fork 329
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
Added session ID as a contextVar #327
base: main
Are you sure you want to change the base?
Conversation
for invocations by session ID. Adding it as a context var allows querying by session ID in an async server setup (ie. FastAPI), where a common usecase would be to collect the cost of invocations in a given user session
Think this can be useful for filtering invocations on the front end as well, since I think logically grouping invocations in sessions rather than individual LMP histrories make more sense for me |
I like this but is the implementation complete. I don't see it actually used anywhere? |
Ah. So for the implementation, I actually created a new api.py file in the root folder, and then exposed all of sql.py's functions via the global config.store like so:
And then on the client I would just call get_invocations_by_session_id. I figured the way you would probably want to access the API functions would be via a file export and not through an server API interface, so I just made it easier and more explicit by exporting them in api.py. Not sure how you felt that, was actually gonna ask if you had any better ideas, forgot to put that msg in the PR |
@alex-dixon might have some input here actually ill check it out when i land from this flight |
Might consider a metadata dict that can pass through to storage layers. I think this would support other use cases and allow the user to be in control over the lifecycle of concepts like session / request id across async/threaded contexts. I'd need more time to understand the session concept and its lifecycle -- is it per ell initialization? |
Yeah wrt to the lifecycle, the answer is yes for single threaded, and no for multi-threaded/async (coroutines). Although I haven't tested it extensively, afaik both of these cases, either single threaded execution as a simple script or multithreaded/async in a server loop, in which case a new session_id is created per thread, works. I do agree there should probbaly be some kind of session variable specified through the user to "tag" LMP calls, but I think this works pretty well as a default, out-of-the box session implementation |
Oh I think there is one case that might be surprising. Which is multi-threading it will create a new session_id in each thread. This actually might be kinda of an anti-usecase for this, because the user would probably expect all ell calls to have the same session_id. Hmm, yeah this would actually be kind of annoying, don't really have a good solution for this case (and actually, I just realized this was the cause of an error I had earlier in not being able to find some invocations ids via filtering with session_id lol) |
@MadcowD could he use |
Hey so got a suggestion to solve the threads problem, its a two parter:
What do you guys think? |
Personally I think the biggest thing session_id can be used for is filtering LMPs in the front end. At least for my personal use case, all of my logic is implemented using several LMPs, so seeing them grouped together rather than the single history for a single LMP makes much more sense to me |
Okay I agree with the idea of run groups and we do actually need this feature for the new evaluation PR so I'll give this another look. |
This works well with server applications with async support, as a common use case is aggregating the token cost per API request. I believe this is also in-line with ell design philosophy of relying on Python language features (ie. ell.config as a global variable) to promote ell lifecycle operations