Skip to content

Commit

Permalink
Merge changes and ideas from Arnold and Alsong (#332)
Browse files Browse the repository at this point in the history
Merge messages in global context and add local storage example

Co-authored-by: Oburusule Dunstan <alsongdunstan2@gmail.com>
  • Loading branch information
mme and alsong committed May 13, 2024
1 parent da72126 commit 9ea511c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { useCopilotReadable } from "@copilotkit/react-core";
import { use, useCallback, useMemo, useState } from "react";
import { useCopilotContext, useCopilotReadable } from "@copilotkit/react-core";
import { use, useCallback, useEffect, useMemo, useState } from "react";
import { Slide } from "./Slide";
import { Header } from "./Header";
import useAppendSlide from "../../actions/useAppendSlide";
Expand All @@ -13,6 +13,26 @@ interface PresentationProps {
}

export const Presentation = ({ performResearch, setPerformResearch }: PresentationProps) => {
// 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));
// }
// }, []);

const [slides, setSlides] = useState<SlideModel[]>([
{
content: "This is the first slide.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* </CopilotKit>
```
*/

import { Ref, useCallback, useRef, useState } from "react";
import {
CopilotContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ToolDefinition,
} from "@copilotkit/shared";
import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
import React, { Ref } from "react";
import React from "react";
import { TreeNodeId } from "../hooks/use-tree";
import { DocumentPointer } from "../types";

Expand Down
4 changes: 2 additions & 2 deletions CopilotKit/packages/react-core/src/hooks/use-chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRef, useState } from "react";
import { useRef, useState, useContext, useEffect } from "react";
import { CopilotContext } from "../context/copilot-context";
import {
Message,
ToolDefinition,
Expand Down Expand Up @@ -123,7 +124,6 @@ export function useChat(options: UseChatOptionsWithCopilotConfig): UseChatHelper
abortControllerRef.current = abortController;

setMessages([...messages, ...newMessages]);

// add threadId and runId to the body if it exists
const copilotConfigBody = options.copilotConfig.body || {};
if (threadIdRef.current) {
Expand Down

0 comments on commit 9ea511c

Please sign in to comment.