Skip to content

How best to handle sessions behind web API #26

Discussion options

You must be logged in to vote

You guessed it! This is what dump() and load() 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.
  • The user sends back the history together with a new message, the API now does a 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…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@KennyVaneetvelde
Comment options

@oehm-smith
Comment options

@oehm-smith
Comment options

@oehm-smith
Comment options

@KennyVaneetvelde
Comment options

Answer selected by KennyVaneetvelde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants