diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts
index 6c2eb7d..e9951c0 100644
--- a/app/api/chat/route.ts
+++ b/app/api/chat/route.ts
@@ -1,9 +1,9 @@
-import { getOpenAIApiInstance } from "@/lib/OpenAiCompletaions"
-import { errorHandler } from "@/lib/utils";
+import { getOpenAIApiInstance } from "@/libs/OpenAiCompletaions"
+import { errorHandler } from "@/libs/utils";
// export const dynamic = 'force-dynamic'
-const apikey = process.env.NEXT_OPENAI_API_KEY
+const apikey = process.env.NEXT_PUBLIC_OPENAI_API_KEY
export async function POST(requset: Request) {
const messages = await requset.json()
diff --git a/app/api/langchain/route.ts b/app/api/langchain/route.ts
new file mode 100644
index 0000000..c561269
--- /dev/null
+++ b/app/api/langchain/route.ts
@@ -0,0 +1,69 @@
+import { NextRequest, NextResponse } from "next/server";
+
+import { z } from "zod";
+
+import { createStructuredOutputChainFromZod } from "langchain/chains/openai_functions";
+import { PromptTemplate } from "@langchain/core/prompts";
+import { createOpenAIModel } from "@/libs/Langchain";
+import { getIP } from "@/libs/utils";
+import { checkRateLimit } from "@/store/rateLimitStore";
+
+export const runtime = "edge";
+
+const TEMPLATE = `Generate a compelling social media bio for user centered around context which them provide you.
+The bio should be concise (150-200 characters) and capture the essence of user in a way that resonates with context.
+Include elements that showcase personality, passion, and any relevant hashtags or keywords.
+Feel free to add a touch of creativity to make it engaging.
+
+{input}`;
+
+
+const apikey = process.env.NEXT_PUBLIC_OPENAI_API_KEY
+
+
+export async function POST(req: NextRequest) {
+ try {
+
+ const ip = getIP(req);
+ if (!checkRateLimit(ip as string)) {
+ return NextResponse.json({ error: "شما بیش از حد مجاز از سرویس استفاده کرده اید. چند ساعت بعد امتحان کنید" }, { status: 429 });
+ }
+
+ const messages = await req.json()
+
+ const prompt = PromptTemplate.fromTemplate<{ input: string }>(TEMPLATE);
+
+ const model = createOpenAIModel(apikey)
+
+ const schema = z.object({
+ output: z.array(
+ z.object({
+ id: z.string(),
+ content: z.string(),
+ })
+ ),
+
+ });
+
+
+ const chain = createStructuredOutputChainFromZod(schema, {
+ llm: model,
+ prompt,
+ outputKey: "output",
+ });
+ console.log(chain)
+
+ const result = await chain.call({
+ input: messages,
+ });
+ console.log(result)
+
+ return NextResponse.json(result.output, { status: 200 });
+ } catch (e: any) {
+ console.log(e)
+ if (e.message.includes("API key")){
+ return NextResponse.json({ error: "سرویس فعلا در دسترس نیست" }, { status: 500 });
+ }
+ return NextResponse.json({ error: e.message }, { status: 500 });
+ }
+}
diff --git a/app/error.tsx b/app/error.tsx
new file mode 100644
index 0000000..2bc908d
--- /dev/null
+++ b/app/error.tsx
@@ -0,0 +1,25 @@
+'use client' // Error components must be Client Components
+
+import { useEffect } from 'react'
+
+export default function Error({
+ error,
+ reset,
+}: {
+ error: Error & { digest?: string }
+ reset: () => void
+}) {
+ useEffect(() => {
+ // Log the error to an error reporting service
+ console.error(error)
+ }, [error])
+
+ return (
+ یه مشکلی به وجود اومده ⚠️
+ {error.message}
+