How best to handle sessions behind web API #26
-
Howdy, i'm newish to Python development though have been a JavaScript / NodeJS / Java dev for many years. I've developed a stand alone Would this library work for web apps that sit behind an RESTful API? You'd need to manage the state somehow. Would creating a new Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
You guessed it! This is what Since the general assumption is that an API itself is stateless (in other words: an API does not track a conversation in-memory) you have a few options. Option 1 (This is what the APIs of OpenAI, Groq, ... do)
Option 2:Basically the same as above, but you keep track of the state in an sqllite DB and instead of sending the history to&from the user you save/load it from the DB and give the user some kind of a user ID that you can use to track instead. Both have some implications In either case, you'll be using Keep in mind though: The system prompt is handled separately from the rest of the history, since typically you don't want to give away your system prompt. You still can do so, if you have a use case for it, though. There is just no simple dump/load mechanism for it, but I don't think that's ever needed since initializing your system prompt is easy enough. I haven't gotten around to creating an API example yet, but it's coming! Hopefully this was helpful to you! Let me know if it worked or if you're stuck or whatever! |
Beta Was this translation helpful? Give feedback.
You guessed it! This is what
dump()
andload()
were designed for.Since the general assumption is that an API itself is stateless (in other words: an API does not track a conversation in-memory) you have a few options.
Option 1 (This is what the APIs of OpenAI, Groq, ... do)
dump()
the history & return it together with the response from the API, this is what for example the OpenAI API does.load()
Option 2:
Basically the same as above, but you keep track of the state in an sqllite DB and instead of sending the history to&from the user you save/load it from the DB and give the user some kind of a user ID that…