33import React , { useState } from "react" ;
44import { CopilotKit } from "@copilotkit/react-core" ;
55import {
6- CopilotSidebar ,
6+ CopilotChat ,
77 useFrontendTool ,
88 useConfigureSuggestions ,
99} from "@copilotkit/react-core/v2" ;
@@ -16,16 +16,30 @@ interface Haiku {
1616 gradient : string ;
1717}
1818
19+ const VALID_IMAGE_NAMES = [
20+ "Osaka_Castle_Turret_Stone_Wall_Pine_Trees_Daytime.jpg" ,
21+ "Tokyo_Skyline_Night_Tokyo_Tower_Mount_Fuji_View.jpg" ,
22+ "Itsukushima_Shrine_Miyajima_Floating_Torii_Gate_Sunset_Long_Exposure.jpg" ,
23+ "Takachiho_Gorge_Waterfall_River_Lush_Greenery_Japan.jpg" ,
24+ "Bonsai_Tree_Potted_Japanese_Art_Green_Foliage.jpeg" ,
25+ "Shirakawa-go_Gassho-zukuri_Thatched_Roof_Village_Aerial_View.jpg" ,
26+ "Ginkaku-ji_Silver_Pavilion_Kyoto_Japanese_Garden_Pond_Reflection.jpg" ,
27+ "Senso-ji_Temple_Asakusa_Cherry_Blossoms_Kimono_Umbrella.jpg" ,
28+ "Cherry_Blossoms_Sakura_Night_View_City_Lights_Japan.jpg" ,
29+ "Mount_Fuji_Lake_Reflection_Cherry_Blossoms_Sakura_Spring.jpg" ,
30+ ] ;
31+
1932export default function GenUiToolBasedDemo ( ) {
2033 return (
2134 < CopilotKit runtimeUrl = "/api/copilotkit" agent = "gen-ui-tool-based" >
22- < SidebarWithSuggestions />
23- < HaikuDisplay />
35+ < Chat />
2436 </ CopilotKit >
2537 ) ;
2638}
2739
28- function SidebarWithSuggestions ( ) {
40+ function Chat ( ) {
41+ const [ haikus , setHaikus ] = useState < Haiku [ ] > ( [ ] ) ;
42+
2943 useConfigureSuggestions ( {
3044 suggestions : [
3145 { title : "Nature Haiku" , message : "Write me a haiku about nature." } ,
@@ -35,43 +49,6 @@ function SidebarWithSuggestions() {
3549 available : "always" ,
3650 } ) ;
3751
38- return (
39- < CopilotSidebar
40- defaultOpen = { true }
41- labels = { {
42- modalHeaderTitle : "Haiku Generator" ,
43- } }
44- />
45- ) ;
46- }
47-
48- const VALID_IMAGE_NAMES = [
49- "Osaka_Castle_Turret_Stone_Wall_Pine_Trees_Daytime.jpg" ,
50- "Tokyo_Skyline_Night_Tokyo_Tower_Mount_Fuji_View.jpg" ,
51- "Itsukushima_Shrine_Miyajima_Floating_Torii_Gate_Sunset_Long_Exposure.jpg" ,
52- "Takachiho_Gorge_Waterfall_River_Lush_Greenery_Japan.jpg" ,
53- "Bonsai_Tree_Potted_Japanese_Art_Green_Foliage.jpeg" ,
54- "Shirakawa-go_Gassho-zukuri_Thatched_Roof_Village_Aerial_View.jpg" ,
55- "Ginkaku-ji_Silver_Pavilion_Kyoto_Japanese_Garden_Pond_Reflection.jpg" ,
56- "Senso-ji_Temple_Asakusa_Cherry_Blossoms_Kimono_Umbrella.jpg" ,
57- "Cherry_Blossoms_Sakura_Night_View_City_Lights_Japan.jpg" ,
58- "Mount_Fuji_Lake_Reflection_Cherry_Blossoms_Sakura_Spring.jpg" ,
59- ] ;
60-
61- function HaikuDisplay ( ) {
62- const [ haikus , setHaikus ] = useState < Haiku [ ] > ( [
63- {
64- japanese : [ "仮の句よ" , "まっさらながら" , "花を呼ぶ" ] ,
65- english : [
66- "A placeholder verse--" ,
67- "even in a blank canvas," ,
68- "it beckons flowers." ,
69- ] ,
70- image_name : null ,
71- gradient : "" ,
72- } ,
73- ] ) ;
74-
7552 useFrontendTool (
7653 {
7754 name : "generate_haiku" ,
@@ -105,10 +82,7 @@ function HaikuDisplay() {
10582 image_name : image_name || null ,
10683 gradient : gradient || "" ,
10784 } ;
108- setHaikus ( ( prev ) => [
109- newHaiku ,
110- ...prev . filter ( ( h ) => h . english [ 0 ] !== "A placeholder verse--" ) ,
111- ] ) ;
85+ setHaikus ( ( prev ) => [ newHaiku , ...prev ] ) ;
11286 return "Haiku generated!" ;
11387 } ,
11488 render : ( { args } : { args : Partial < Haiku > } ) => {
@@ -120,13 +94,12 @@ function HaikuDisplay() {
12094 ) ;
12195
12296 return (
123- < div className = "relative flex items-center justify-center h-full w-full" >
124- < div className = "px-20 py-12 w-full max-w-4xl" >
125- < div className = "space-y-6" >
126- { haikus . map ( ( haiku , index ) => (
127- < HaikuCard key = { index } haiku = { haiku } />
128- ) ) }
129- </ div >
97+ < div className = "flex justify-center items-center h-screen w-full" >
98+ < div className = "h-full w-full max-w-4xl" >
99+ < CopilotChat
100+ agentId = "gen-ui-tool-based"
101+ className = "h-full rounded-2xl"
102+ />
130103 </ div >
131104 </ div >
132105 ) ;
0 commit comments