Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Ayers <[email protected]>
  • Loading branch information
smaye81 committed Oct 1, 2024
1 parent 5991d4e commit 816a6c7
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 242 deletions.
152 changes: 76 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 32 additions & 19 deletions src/components/eliza-demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
// limitations under the License.

import { ElizaService } from "@buf/connectrpc_eliza.connectrpc_es/connectrpc/eliza/v1/eliza_connect";
import React, { useCallback, useEffect, useRef } from "react";
import React, { useCallback, useState } from "react";
import { createPromiseClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import styles from "./styles.module.css";
import { TerminalHeader } from "../home/examples";
import { Terminal, Message } from "../terminal";

const host = "https://demo.connectrpc.com";

Expand All @@ -27,29 +26,43 @@ const transport = createConnectTransport({

const elizaServicePromiseClient = createPromiseClient(ElizaService, transport);

export const ElizaDemo: React.FC<{ focusOnMount?: boolean }> = ({
focusOnMount = false,
}) => {
const callbackRef = useRef(false);
useEffect(() => {
if (callbackRef.current) {
return;
}
callbackRef.current = true;
}, []);
interface DemoProps {
focusOnMount?: boolean;
}

export const ElizaDemo: React.FC<DemoProps> = ({ focusOnMount = false }) => {
const [conversation, setConversation] = useState<Message[]>([
{
sender: "user",
text: "Meet Eliza, our psychotherapist",
},
{
sender: "eliza",
text: "Hello, how are you feeling?",
},
]);

const handleCommand = useCallback(
async (str: string) => {
async (inputText: string) => {
const response = await elizaServicePromiseClient.say({
sentence: str,
sentence: inputText,
});
const updated = [
{ sender: "user", text: inputText } as Message,
{ sender: "eliza", text: response.sentence } as Message,
];
const updatedConvo = [...conversation, ...updated];
setConversation(updatedConvo);
return;
},
[elizaServicePromiseClient],
[elizaServicePromiseClient, conversation],
);

return (
<div className={styles.container} onClick={() => focus()}>
<TerminalHeader>Connect-Web</TerminalHeader>
</div>
<Terminal
conversation={conversation}
handleCommand={handleCommand}
focusOnMount={focusOnMount}
/>
);
};
Loading

0 comments on commit 816a6c7

Please sign in to comment.