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

Merge changes and ideas from Arnold and Alsong #332

Merged
merged 5 commits into from May 13, 2024
Merged

Conversation

mme
Copy link
Collaborator

@mme mme commented May 10, 2024

Hi @arnoldmukisa @alsong,

We recently moved messages to the global context, just in a slightly different way :) This PR merges the existing approach with your PR.

Also nice idea loading/restoring the message history from local storage! Since our users might have different strategies on storing the message history, I cannot enable this for all users. However, since we now gained the capability to access the messages array from the context object, it is now very simple to just load the messages in application code.

   // Load messages from local storage

   const { messages, setMessages } = useCopilotContext();

   // save to local storage when messages change
   useEffect(() => {
     if (messages.length !== 0) {
       localStorage.setItem("copilotkit-messages", JSON.stringify(messages));
     }
   }, [JSON.stringify(messages)]);

   // initially load from local storage
   useEffect(() => {
     const messages = localStorage.getItem("copilotkit-messages");
     if (messages) {
       console.log("got messages from local storage", messages);
       setMessages(JSON.parse(messages));
     }
   }, []);

I added this as an example to the presentation code.

@mme mme merged commit 9ea511c into main May 13, 2024
5 checks passed
@mme mme deleted the mme/merge-arnold-pr branch May 13, 2024 07:07
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.

None yet

2 participants