Skip to content
Snippets Groups Projects
Commit 47c3405f authored by thucpn's avatar thucpn
Browse files

able to config frontend via window object

parent 24fd6c94
No related branches found
No related tags found
No related merge requests found
/* eslint-disable @typescript-eslint/no-explicit-any */
"use client";
/**
* A helper function to get environment variables from the window object
* @param name - The name of the environment variable to get
* @returns The value of the environment variable
*/
export const getEnv = (name: string) => {
if (typeof window === "undefined") return undefined;
return (window as any).LLAMAINDEX[name];
};
......@@ -14,6 +14,7 @@ export default function RootLayout({
return (
<html lang="en">
<body>{children}</body>
<script async src="./config.js"></script>
</html>
);
}
"use client";
import { ChatSection } from "@llamaindex/chat-ui";
import { useChat } from "ai/react";
import { getEnv } from "./env";
export default function Page() {
const handler = useChat();
const handler = useChat({ api: getEnv("CHAT_API") });
return (
<div className="h-screen flex items-center justify-center">
<div className="flex h-screen items-center justify-center">
<ChatSection
className="h-[72vh] w-[72vw] shadow-2xl rounded-2xl"
className="h-[72vh] w-[72vw] rounded-2xl shadow-2xl"
handler={handler}
/>
</div>
......
......@@ -2,6 +2,7 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = {
distDir: "../.next",
output: "export",
};
export default nextConfig;
window.LLAMAINDEX = {
CHAT_API: "http://localhost:3000/api/chat",
};
......@@ -21,6 +21,7 @@ export type AgentInput = {
*/
export type ServerWorkflow =
| Workflow<null, AgentInput, ChatResponseChunk>
// | Workflow<AgentWorkflowContext, AgentInputData, string>
| AgentWorkflow;
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment