|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import { createRef, useState } from "react"; |
| 4 | + |
| 5 | +import Button from "@cloudscape-design/components/button"; |
| 6 | +import Container from "@cloudscape-design/components/container"; |
| 7 | +import Header from "@cloudscape-design/components/header"; |
| 8 | +import PromptInput from "@cloudscape-design/components/prompt-input"; |
| 9 | +import SpaceBetween from "@cloudscape-design/components/space-between"; |
| 10 | + |
| 11 | +import { ChatBubble, SupportPromptGroup } from "../../lib/components"; |
| 12 | +import { TestBed } from "../app/test-bed"; |
| 13 | +import { ChatBubbleAvatarGenAI, ChatBubbleAvatarUser } from "../chat-bubble/util-components"; |
| 14 | +import { ScreenshotArea } from "../screenshot-area"; |
| 15 | + |
| 16 | +import styles from "./styles.module.scss"; |
| 17 | + |
| 18 | +export default function SupportPromptPage() { |
| 19 | + const [text, setText] = useState(""); |
| 20 | + const [text2, setText2] = useState(""); |
| 21 | + const [sentText, setSentText] = useState(""); |
| 22 | + const ref = createRef<HTMLTextAreaElement>(); |
| 23 | + |
| 24 | + const items = [ |
| 25 | + { |
| 26 | + text: "Create a really detailed and powerful image. The image should be of a mountain scene with a blue lake and green hills, with a sunset in the background. In the lake, there should be 3 whales leaping out of the water.", |
| 27 | + id: "image", |
| 28 | + }, |
| 29 | + { |
| 30 | + text: "Help me brainstorm for an upcoming sign-off.", |
| 31 | + id: "brainstorm", |
| 32 | + }, |
| 33 | + { |
| 34 | + text: "Summarize this long and complex PDF for me. Include a paragraph containing 3-4 sentences that capture the main ideas and overall message of the documents, a list of 5 to 10 key points from the document, and up to 3 follow-up questions that arise from the content of the document.", |
| 35 | + id: "summarize", |
| 36 | + }, |
| 37 | + ]; |
| 38 | + |
| 39 | + const items2 = [ |
| 40 | + { |
| 41 | + text: "Create a really detailed and powerful image.", |
| 42 | + id: "image", |
| 43 | + }, |
| 44 | + { |
| 45 | + text: "Help me brainstorm for an upcoming sign-off.", |
| 46 | + id: "brainstorm", |
| 47 | + }, |
| 48 | + { |
| 49 | + text: "Summarize this long PDF for me.", |
| 50 | + id: "summarize", |
| 51 | + }, |
| 52 | + ]; |
| 53 | + |
| 54 | + return ( |
| 55 | + <ScreenshotArea> |
| 56 | + <main className={styles.container}> |
| 57 | + <TestBed> |
| 58 | + <SpaceBetween size="xl"> |
| 59 | + <Container |
| 60 | + header={ |
| 61 | + <Header actions={<Button onClick={() => setText("")}>Reset</Button>}>Support prompt test: send</Header> |
| 62 | + } |
| 63 | + > |
| 64 | + <SpaceBetween direction="vertical" size="xxl"> |
| 65 | + <div> |
| 66 | + <ChatBubble type="outgoing" avatar={<ChatBubbleAvatarUser />} ariaLabel="User at 4:23:20pm"> |
| 67 | + What can I do with Amazon S3? |
| 68 | + </ChatBubble> |
| 69 | + <SpaceBetween direction="vertical" size="xs"> |
| 70 | + <ChatBubble avatar={<ChatBubbleAvatarGenAI />} type="incoming" ariaLabel="Gen AI at at 4:23:23pm"> |
| 71 | + Amazon S3 provides a simple web service interface that you can use to store and retrieve any |
| 72 | + amount of data, at any time, from anywhere. |
| 73 | + </ChatBubble> |
| 74 | + {text === "" && ( |
| 75 | + <div className={styles["support-prompt-container"]}> |
| 76 | + <SupportPromptGroup |
| 77 | + ariaLabel="Test support prompt group 1" |
| 78 | + alignment="vertical" |
| 79 | + onItemClick={({ detail }) => { |
| 80 | + const activeItem = items.find((item) => item.id === detail.id); |
| 81 | + setText(activeItem?.text || ""); |
| 82 | + console.log(detail); |
| 83 | + }} |
| 84 | + items={items} |
| 85 | + /> |
| 86 | + </div> |
| 87 | + )} |
| 88 | + </SpaceBetween> |
| 89 | + {text !== "" && ( |
| 90 | + <ChatBubble type="outgoing" avatar={<ChatBubbleAvatarUser />} ariaLabel="User at 4:23:20pm"> |
| 91 | + {text} |
| 92 | + </ChatBubble> |
| 93 | + )} |
| 94 | + </div> |
| 95 | + |
| 96 | + <SpaceBetween direction="vertical" size="m"> |
| 97 | + <PromptInput placeholder="Write a prompt" value="" actionButtonIconName="send" /> |
| 98 | + </SpaceBetween> |
| 99 | + </SpaceBetween> |
| 100 | + </Container> |
| 101 | + <Container |
| 102 | + header={ |
| 103 | + <Header actions={<Button onClick={() => setSentText("")}>Reset</Button>}> |
| 104 | + Support prompt test: draft |
| 105 | + </Header> |
| 106 | + } |
| 107 | + > |
| 108 | + <SpaceBetween direction="vertical" size="m"> |
| 109 | + <div className={styles.placeholder} /> |
| 110 | + {sentText !== "" && ( |
| 111 | + <ChatBubble type="outgoing" avatar={<ChatBubbleAvatarUser />} ariaLabel="User at 4:23:20pm"> |
| 112 | + {sentText} |
| 113 | + </ChatBubble> |
| 114 | + )} |
| 115 | + <SpaceBetween direction="vertical" size="m"> |
| 116 | + {sentText === "" && ( |
| 117 | + <SupportPromptGroup |
| 118 | + alignment="horizontal" |
| 119 | + ariaLabel="Test support prompt group 2" |
| 120 | + onItemClick={({ detail }) => { |
| 121 | + const activeItem = items2.find((item) => item.id === detail.id); |
| 122 | + setText2(activeItem?.text || ""); |
| 123 | + ref.current?.focus(); |
| 124 | + }} |
| 125 | + items={items2} |
| 126 | + /> |
| 127 | + )} |
| 128 | + |
| 129 | + <PromptInput |
| 130 | + ref={ref} |
| 131 | + placeholder="Write a prompt" |
| 132 | + value={text2} |
| 133 | + actionButtonIconName="send" |
| 134 | + onAction={() => { |
| 135 | + setSentText(text2); |
| 136 | + setText2(""); |
| 137 | + }} |
| 138 | + /> |
| 139 | + </SpaceBetween> |
| 140 | + </SpaceBetween> |
| 141 | + </Container> |
| 142 | + </SpaceBetween> |
| 143 | + </TestBed> |
| 144 | + </main> |
| 145 | + </ScreenshotArea> |
| 146 | + ); |
| 147 | +} |
0 commit comments