From 34fa169585a8323ad40d27b288cf1bfb69f502f1 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Mon, 22 Apr 2024 23:10:11 -0500 Subject: [PATCH] Add copilotkit into layout Copilot components have been added into the layout file. Meanwhile, some key dependencies related to copilot, langchain, and anthropic-ai have been added or modified in the yarn.lock file, ensuring proper functionality and compatibility. --- .../nextjs/app/api/copilotkit/openai/route.ts | 9 + apps/nextjs/app/api/dfda/[dfdaPath]/route.ts | 4 +- apps/nextjs/app/layout.tsx | 7 + apps/nextjs/components/chat-component.tsx | 4 +- apps/nextjs/package.json | 3 + apps/nextjs/yarn.lock | 775 +++++++++++++++++- 6 files changed, 760 insertions(+), 42 deletions(-) create mode 100644 apps/nextjs/app/api/copilotkit/openai/route.ts diff --git a/apps/nextjs/app/api/copilotkit/openai/route.ts b/apps/nextjs/app/api/copilotkit/openai/route.ts new file mode 100644 index 000000000..ecae35fab --- /dev/null +++ b/apps/nextjs/app/api/copilotkit/openai/route.ts @@ -0,0 +1,9 @@ +import { CopilotBackend, OpenAIAdapter } from "@copilotkit/backend"; + +export const runtime = "edge"; + +export async function POST(req: Request): Promise { + const copilotKit = new CopilotBackend(); + + return copilotKit.response(req, new OpenAIAdapter()); +} diff --git a/apps/nextjs/app/api/dfda/[dfdaPath]/route.ts b/apps/nextjs/app/api/dfda/[dfdaPath]/route.ts index 4a1b4219f..bf21eea40 100644 --- a/apps/nextjs/app/api/dfda/[dfdaPath]/route.ts +++ b/apps/nextjs/app/api/dfda/[dfdaPath]/route.ts @@ -39,10 +39,10 @@ async function fetchDfdaApi(req: Request, method: 'GET' | 'POST', context: z.inf const requestBody = await req.json(); init.body = JSON.stringify(requestBody); } - console.log(`Making ${method} request to ${dfdaUrl} with init:`, init); + console.log(`Making ${method} request to ${dfdaUrl}`); // with init:`, init); const response = await fetch(dfdaUrl, init); const data = await response.json(); - console.log("Response data:", data); + //console.log("Response data:", data); return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } }) } catch (error) { return handleError(error); diff --git a/apps/nextjs/app/layout.tsx b/apps/nextjs/app/layout.tsx index de0e7c31a..7cb8072d4 100644 --- a/apps/nextjs/app/layout.tsx +++ b/apps/nextjs/app/layout.tsx @@ -8,6 +8,9 @@ import { siteConfig } from "@/config/site" import { cn } from "@/lib/utils" import { Toaster } from "@/components/ui/toaster" import { ThemeProvider } from "@/components/theme-provider" +import { CopilotKit } from "@copilotkit/react-core"; +import { CopilotSidebar } from "@copilotkit/react-ui"; +//import "@copilotkit/react-ui/styles.css"; const inter = Inter({ subsets: ["latin"] }) @@ -73,6 +76,8 @@ export default async function RootLayout({ children }: RootLayoutProps) { + {/**/} + {/* */}
+ {/* */} + {/**/} diff --git a/apps/nextjs/components/chat-component.tsx b/apps/nextjs/components/chat-component.tsx index 7ecbcc1e1..a551b4bfe 100644 --- a/apps/nextjs/components/chat-component.tsx +++ b/apps/nextjs/components/chat-component.tsx @@ -4,10 +4,10 @@ import { FullPageChat } from 'flowise-embed-react'; export default function ChatComponent() { return