Skip to content
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

Stateful chat #2

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Stateful chat #2

wants to merge 2 commits into from

Conversation

bennyschmidt
Copy link
Owner

Closes #1

@@ -28,11 +28,15 @@ const {

const { prefixInput } = require('arthasgpt/src/utils/prefix');

const __statefulChatFunction = {};
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can cache the stateful chat method per worker, but it is a bit of an antipattern in a stateless API, and when scaling instances there will be multiple (inconsistent) histories depending on which worker is picking up the request.

With CACHE=true in the .env we already cache the query, prompt, and model responses. For scale, it might be worth the trade-off to keep the prompt endpoint stateless, relying on library-level caching for speed, and an application-level solution for chat history/context.

Note: __statefulChatFunction is instantiated as an object (hash) because it maintains a chat method for each active persona, not just 1, like this:

__statefulChatFunction = {
  [persona1Key]: persona1ChatFunction,
  [persona2Key]: persona2ChatFunction,
    
  ...
}

to be called like this:

__statefulChatFunction[persona1Key]("what did you just say?")

@@ -30,7 +30,8 @@ const PORT = 8000;
* Config
*/

const numCPUs = availableParallelism();
// const numCPUs = availableParallelism();
const numCPUs = 1;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach works in a single instance, but would still need another solution to share the stateful chat method across multiple.

@bennyschmidt bennyschmidt added enhancement New feature or request api Related to the API labels Mar 20, 2024
@bennyschmidt bennyschmidt changed the title Stateful Chat Stateful chat Mar 21, 2024
@bennyschmidt bennyschmidt removed enhancement New feature or request api Related to the API labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent not persisting between questions
1 participant