
my-next-app with your desired project name.http://localhost:3000 to see your Next.js app in action.NEXT_PUBLIC_COPILOTKIT_BACKEND_URL=http://localhost:3000/api/copilotkit: This specifies the base URL for the CopilotKit backend API.NEXT_PUBLIC_ prefix makes this variable accessible both on the server side and in the client-side code of a Next.js application.http://localhost:3000/api/copilotkit indicates the API is running locally during development.NEXT_PUBLIC_GROQ_CLOUD_API_KEY=: This variable is intended to store an API key for a GROQ Cloud service. GROQ Cloud could be related to querying or data processing you will have to paste your own Groq API key.NEXT_PUBLIC_RESTDB_API_KEY=: Intended to hold the API key for accessing a RESTdb service. You will have to paste your own Groq API key.NEXT_PUBLIC_RESTDB_BASE_URL=https://demosql-fdcb.restdb.io/rest/demo-data: Defines the base URL for interacting with the RESTdb database. This URL will be created when you make your database. Here, I have given the URL of my database.https://demosql-fdcb.restdb.io/rest/demo-data points to a specific RESTdb database endpoint called demo-data.api. Inside the API folder, make another folder called copilotkit. Then in there, make a new file called route.js and inside the file paste this code:CopilotRuntime and GroqAdapter: These are classes from the CopilotKit library used to set up and configure the runtime environment and adapters for AI-based services.CopilotRuntime: A runtime environment to manage the CopilotKit operations.GroqAdapter: Adapts and connects a Groq service (used for querying or data processing) with CopilotKit.copilotRuntimeNextJSAppRouterEndpoint: A utility function to create a handler for a Next.js App Router API endpoint that integrates CopilotKit.Groq from "groq-sdk": A library for interacting with Groq services is initialized here for querying or processing data.Groq Initialization:Groq an object is created with an API key (NEXT_PUBLIC_GROQ_CLOUD_API_KEY) fetched from environment variables.console.log(process.env.NEXT_PUBLIC_GROQ_CLOUD_API_KEY): Logs the API key to the server console. Note: Avoid logging sensitive data in production to ensure security.CopilotRuntime Initialization: Creates an instance of CopilotKit's runtime environment to manage CopilotKit's features and services.GroqAdapter:model parameter specifies the AI model to use. Here, it is "llama-3.1-70b-versatile", a versatile language model with 70 billion parameters.POST handler for a Next.js App Router API endpoint.copilotRuntimeNextJSAppRouterEndpoint:/api/copilotkit endpoint.runtime (CopilotKit) and serviceAdapter (GroqAdapter) as inputs to configure the endpoint's behaviour.handleRequest:POST requests).return handleRequest(req);: Invokes the handler and processes the incoming request (req), returning the appropriate response./api/copilotkit endpoint is configured to handle POST requests, pass the requests to CopilotKit's runtime, and return the processed response.components folder for storing ShadCN components.tailwind.config.js file with required configurations.components.json:components folder now contains a ready-to-use button component.components folder that contains the Table component. This component is responsible for displaying the database data in a structured tabular format.Table component, there are two additional files in the front end. These files serve different purposes and will be integrated later in the project for specific functionalities.Tabledata.jsx file bridges the gap between the backend API and the frontend table display.Table, TableRow, TableCell, and so on) from @/components/ui/table.data prop, an array of objects representing table rows.Id, name, email, and more.data array to generate TableRow elements dynamically, using _id as the unique key._id, name, email, and so on) in TableCell components with custom styles.NLQueryForm.jsx:Table component for display.NLQueryForm component:useState) and side effects (useEffect).axios for HTTP requests.useCopilotReadable and useCopilotAction from @copilotkit/react-core to integrate CopilotKit functionality.Tabledata component for rendering data.NLQueryForm.NEXT_PUBLIC_RESTDB_API_KEY and NEXT_PUBLIC_RESTDB_BASE_URL).console.table.useEffect to fetch data from the API on the initial render.axios with required headers.data with the response and stops the loading state.error state.useCopilotReadable: Exposes a readable description and a slice of the first 25 records of data.useCopilotAction: Defines a CopilotKit action named fetchData which:nlQuery) as input.nlQuery state and returns it as a string.Loading...) if loading is true.data state to the Tabledata component for rendering.NLQueryForm component as the default export.page.js file inside the app folder and add this code:"use client"; indicates the file is using React's client-side rendering.NLQueryForm is imported from a local component directory to be used in the app.CopilotPopup is imported from the @copilotkit/react-ui package for displaying an interactive popup.Home is a React functional component that defines the UI for the home page.min-h-screen) with a background color (bg-background) wraps all content.bg-primary, text-primary-foreground).NLQueryForm component inside a container with padding (py-8).CopilotPopup at the bottom with:layout.js file and add this code:./globals.css: Imports global CSS styles for the application.@copilotkit/react-core: Imports the core functionality of CopilotKit.@copilotkit/react-ui/styles.css: Includes predefined styles for the CopilotKit UI components.<html> element with a lang attribute set to en for English.<body> tag, the CopilotKit component is wrapped around the children prop.
This setup:/api/copilotkit..env file to keep your project secure.SELECT * FROM demo_data WHERE email = 'riverashannon@lee.com'; to extract the name of the person, we used an NLP query to achieve the exact same result.Posted Oct 3, 2025
Built an AI-powered tool to convert natural language into SQL queries.
0
2