import { DefaultButton, ISeparatorStyles, IconButton, Image, Link, Modal, PrimaryButton, Separator, Spinner, Stack, Text, } from "@fluentui/react"; import { QueryCopilotSampleDatabaseId, StyleConstants } from "Common/Constants"; import { handleError } from "Common/ErrorHandlingUtils"; import { createCollection } from "Common/dataAccess/createCollection"; import * as DataModels from "Contracts/DataModels"; import { ContainerSampleGenerator } from "Explorer/DataSamples/ContainerSampleGenerator"; import Explorer from "Explorer/Explorer"; import { AllPropertiesIndexed } from "Explorer/Panes/AddCollectionPanel"; import { PromptCard } from "Explorer/QueryCopilot/PromptCard"; import { useDatabases } from "Explorer/useDatabases"; import { useCarousel } from "hooks/useCarousel"; import { ReactTabKind, useTabs } from "hooks/useTabs"; import React, { useState } from "react"; import YoutubePlaceholder from "../../../images/YoutubePlaceholder.svg"; interface QueryCopilotCarouselProps { isOpen: boolean; explorer: Explorer; } const separatorStyles: Partial = { root: { selectors: { "::before": { background: StyleConstants.BaseMedium, }, }, padding: "16px 0", height: 1, }, }; export const QueryCopilotCarousel: React.FC = ({ isOpen, explorer, }: QueryCopilotCarouselProps): JSX.Element => { const [page, setPage] = useState(1); const [isCreatingDatabase, setIsCreatingDatabase] = useState(false); const [spinnerText, setSpinnerText] = useState(""); const [selectedPrompt, setSelectedPrompt] = useState(1); const getHeaderText = (): string => { switch (page) { case 1: return "What exactly is copilot?"; case 2: return "Setting up your Sample database"; case 3: return "Sample prompts to help you"; default: return ""; } }; const getQueryCopilotInitialInput = (): string => { switch (selectedPrompt) { case 1: return "Write a query to return all records in this table"; case 2: return "Write a query to return all records in this table created in the last thirty days"; case 3: return 'Write a query to return all records in this table created in the last thirty days which also have the record owner as "Contoso"'; default: return ""; } }; const createSampleDatabase = async (): Promise => { const database = useDatabases.getState().findDatabaseWithId(QueryCopilotSampleDatabaseId); if (database) { return; } try { setIsCreatingDatabase(true); setSpinnerText("Setting up your database..."); const params: DataModels.CreateCollectionParams = { createNewDatabase: true, collectionId: "SampleContainer", databaseId: QueryCopilotSampleDatabaseId, databaseLevelThroughput: true, autoPilotMaxThroughput: 1000, offerThroughput: undefined, indexingPolicy: AllPropertiesIndexed, partitionKey: { paths: ["/categoryId"], kind: "Hash", version: 2, }, }; await createCollection(params); await explorer.refreshAllDatabases(); const database = useDatabases.getState().findDatabaseWithId(QueryCopilotSampleDatabaseId); await database.loadCollections(); const collection = database.findCollectionWithId("SampleContainer"); setSpinnerText("Adding sample data set..."); const sampleGenerator = await ContainerSampleGenerator.createSampleGeneratorAsync(explorer, true); await sampleGenerator.populateContainerAsync(collection); await database.expandDatabase(); collection.expandCollection(); useDatabases.getState().updateDatabase(database); } catch (error) { //TODO: show error in UI handleError(error, "QueryCopilotCreateSampleDB"); throw error; } finally { setIsCreatingDatabase(false); setSpinnerText(""); } }; const getContent = (): JSX.Element => { switch (page) { case 1: return ( A couple of lines about copilot and the background about it. The idea is to have some text to give context to the user. How do you use copilot To generate queries , just describe the query you want and copilot will generate the query for you.Watch this video to learn more about how to use copilot. What is copilot good at A couple of lines about what copilot can do and its capablites with a link to{" "} documentation {" "} if possible. What are its limitations A couple of lines about what copilot cant do and its limitations.{" "} Link to documentation Disclaimer AI-generated content can have mistakes. Make sure it's accurate and appropriate before using it.{" "} Read preview terms ); case 2: return ( Before you get started, we need to configure your sample database for you. Here is a summary of the database being created for your reference. Configuration values can be updated using the settings icon in the query builder. Database Id CopilotSampleDb Database throughput (autoscale) Autoscale Database Max RU/s 1000 Your database throughput will automatically scale from{" "} 100 RU/s (10% of max RU/s) - 1000 RU/s based on usage. Estimated monthly cost (USD): $8.76 - $87.60 (1 region, 100 - 1000 RU/s, $0.00012/RU) Container Id SampleContainer Partition key categoryId ); case 3: return ( To help you get started, here are some sample prompts to get you started setSelectedPrompt(1)} isSelected={selectedPrompt === 1} /> setSelectedPrompt(2)} isSelected={selectedPrompt === 2} /> setSelectedPrompt(3)} isSelected={selectedPrompt === 3} /> Interested in learning more about how to write effective prompts. Please read this article for more information. You can also access these prompts by selecting the Samples prompts button in the query builder page. Don't like any of the prompts? Just click Get Started and write your own prompt. ); default: return <>; } }; return ( {getHeaderText()} useCarousel.getState().setShowCopilotCarousel(false)} /> {getContent()} {page !== 1 && ( setPage(page - 1)} disabled={isCreatingDatabase} /> )} { if (page === 3) { useCarousel.getState().setShowCopilotCarousel(false); useTabs.getState().setQueryCopilotTabInitialInput(getQueryCopilotInitialInput()); useTabs.getState().openAndActivateReactTab(ReactTabKind.QueryCopilot); return; } if (page === 2) { await createSampleDatabase(); } setPage(page + 1); }} disabled={isCreatingDatabase} /> {isCreatingDatabase && } {isCreatingDatabase && {spinnerText}} ); };