From e3ae39e2baba55a1c18e2bc8ca985ea596cf3279 Mon Sep 17 00:00:00 2001 From: Dave Glover Date: Tue, 10 Sep 2024 20:48:25 +1000 Subject: [PATCH 1/3] gpt-4-vision --- .../src/components/playground/ChatCard.tsx | 431 +++++++++++------- .../src/components/playground/Message.tsx | 46 +- src/playground/src/pages/playground/Chat.tsx | 5 +- 3 files changed, 313 insertions(+), 169 deletions(-) diff --git a/src/playground/src/components/playground/ChatCard.tsx b/src/playground/src/components/playground/ChatCard.tsx index d72c3d57..45fb3cff 100644 --- a/src/playground/src/components/playground/ChatCard.tsx +++ b/src/playground/src/components/playground/ChatCard.tsx @@ -1,15 +1,14 @@ import { - makeStyles, - Body1, - Button, - CardFooter, - Field, - Textarea, - Spinner, - shorthands + makeStyles, + Body1, + Button, + CardFooter, + Textarea, + Spinner, + shorthands } from "@fluentui/react-components"; import { Dispatch, useEffect, useRef, useState } from "react"; -import { Delete24Regular, SendRegular } from "@fluentui/react-icons"; +import { Delete24Regular, SendRegular, Attach24Regular } from "@fluentui/react-icons"; import { Message } from "./Message"; import { Response } from "./Response"; import { useEventDataContext } from "../../providers/EventDataProvider"; @@ -17,175 +16,281 @@ import { Card } from "./Card"; import { ChatResponseMessageExtended } from "../../pages/playground/Chat.state"; interface CardProps { - onPromptEntered: Dispatch; - messageList: ChatResponseMessageExtended[]; - onClear: () => void; - isLoading: boolean; - canChat: boolean; + onPromptEntered: Dispatch; + messageList: ChatResponseMessageExtended[]; + onClear: () => void; + isLoading: boolean; + canChat: boolean; } const useStyles = makeStyles({ - dialog: { - display: "block", - }, - smallButton: { - width: "100%", - height: "40%", - maxWidth: "none", - textAlign: "left", - marginBottom: "12px" - }, - startCard: { - display: "flex", - maxWidth: "80%", - ...shorthands.margin("35%", "20%"), - ...shorthands.padding("20px", "0px"), - }, - chatCard: { - display: "flex", - height: "calc(100vh - 92px)", - }, + dialog: { + display: "block", + }, + buttonContainer: { + display: "flex", + justifyContent: "flex-end", // Align buttons to the right + }, + smallButton: { + marginBottom: "12px", + ...shorthands.margin("4px"), + }, + startCard: { + display: "flex", + maxWidth: "80%", + ...shorthands.margin("35%", "20%"), + ...shorthands.padding("20px", "0px"), + }, + chatCard: { + display: "flex", + height: "calc(100vh - 100px)", + }, + wrapper: { + display: "flex", + flexDirection: "column", + justifyContent: "flex-end", // Ensure content sticks to the bottom + height: "120px", + maxHeight: "120px", + }, + userQuery: { + flexGrow: 0, // Do not grow to fill remaining space + marginBottom: "10px", + overflowY: "auto", // Scroll if content overflows + } }); export const ChatCard = ({ - onPromptEntered, - messageList, - onClear, - isLoading, - canChat, + onPromptEntered, + messageList, + onClear, + isLoading, + canChat, }: CardProps) => { - const chat = useStyles(); - const chatContainerRef = useRef(null); - const { isAuthorized } = useEventDataContext(); - - useEffect(() => { - if (chatContainerRef.current) { - chatContainerRef.current.scrollTop = - chatContainerRef.current.scrollHeight; - } - }, [messageList]); - - return ( - - - {isAuthorized && ( - <> -
- - {messageList.length > 1 ? ( - messageList.map((message, index) => { - if (message.role === "system") { - return null; - } - return message.role === "user" ? ( - - ) : ( - - ); - }) - ) : ( - - - {!canChat && (

Select a model

)} - {canChat && ( - <> -

Start chatting

- Test your assistant by sending queries below. Then adjust your assistant setup to improve the assistant's responses. - - )} -
-
+ const chat = useStyles(); + const chatContainerRef = useRef(null); + const { isAuthorized } = useEventDataContext(); + + useEffect(() => { + if (chatContainerRef.current) { + chatContainerRef.current.scrollTop = + chatContainerRef.current.scrollHeight; + } + }, [messageList]); + + return ( + + + {isAuthorized && ( + <> +
+ + {messageList.length > 1 ? ( + messageList.map((message, index) => { + if (message.role === "system") { + return null; + } + return message.role === "user" ? ( + + ) : ( + + ); + }) + ) : ( + + + {!canChat && (

Select a model

)} + {canChat && ( + <> +

Start chatting

+ Test your assistant by sending queries below. Then adjust your assistant setup to improve the assistant's responses. + + )} +
+
+ )} +
+ {isLoading && } + {isAuthorized && ( + + )} + {!isAuthorized && ( + <> + +

Please enter your event code to start the chat session.

+
+ + )} + )} -
- {isLoading && } - {isAuthorized && ( - - )} - {!isAuthorized && ( - <> - -

Please enter your event code to start the chat session.

-
- - )} - - )} -
- ); + + ); }; const hasPrompt = (prompt: string) => { - const regex = /^\s*$/; - return !regex.test(prompt); + const regex = /^\s*$/; + return !regex.test(prompt); }; function ChatInput({ - promptSubmitted, - onClear, - canChat, + promptSubmitted, + onClear, + canChat, }: { - promptSubmitted: Dispatch; - onClear: () => void; - canChat: boolean; + promptSubmitted: Dispatch; + onClear: () => void; + canChat: boolean; }) { - const [userPrompt, setPrompt] = useState(""); - - const chat = useStyles(); - return ( - - -