forked from vercel/ai-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vercel:main' into main
- Loading branch information
Showing
41 changed files
with
2,348 additions
and
798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { openai } from "@ai-sdk/openai"; | ||
import { experimental_wrapLanguageModel as wrapLanguageModel } from "ai"; | ||
import { customMiddleware } from "./custom-middleware"; | ||
import { openai } from '@ai-sdk/openai'; | ||
import { experimental_wrapLanguageModel as wrapLanguageModel } from 'ai'; | ||
|
||
export const customModel = wrapLanguageModel({ | ||
model: openai("gpt-4o"), | ||
middleware: customMiddleware, | ||
}); | ||
import { type Model } from '@/lib/model'; | ||
|
||
import { customMiddleware } from './custom-middleware'; | ||
|
||
export const customModel = (modelName: Model['name']) => { | ||
return wrapLanguageModel({ | ||
model: openai(modelName), | ||
middleware: customMiddleware, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use server'; | ||
|
||
import { cookies } from 'next/headers'; | ||
|
||
export async function saveModel(model: string) { | ||
const cookieStore = await cookies(); | ||
cookieStore.set('model', model); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { cookies } from 'next/headers'; | ||
|
||
import { AppSidebar } from '@/components/custom/app-sidebar'; | ||
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'; | ||
|
||
import { auth } from '../(auth)/auth'; | ||
|
||
export default async function Layout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const [session, cookieStore] = await Promise.all([auth(), cookies()]); | ||
const isCollapsed = cookieStore.get('sidebar:state')?.value !== 'true'; | ||
|
||
return ( | ||
<SidebarProvider defaultOpen={!isCollapsed}> | ||
<AppSidebar user={session?.user} /> | ||
<SidebarInset>{children}</SidebarInset> | ||
</SidebarProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import { Chat } from "@/components/custom/chat"; | ||
import { generateUUID } from "@/lib/utils"; | ||
import { cookies } from 'next/headers'; | ||
|
||
import { Chat } from '@/components/custom/chat'; | ||
import { DEFAULT_MODEL_NAME, models } from '@/lib/model'; | ||
import { generateUUID } from '@/lib/utils'; | ||
|
||
export default async function Page() { | ||
const id = generateUUID(); | ||
return <Chat key={id} id={id} initialMessages={[]} />; | ||
|
||
const cookieStore = await cookies(); | ||
const value = cookieStore.get('model')?.value; | ||
const selectedModelName = | ||
models.find((m) => m.name === value)?.name || DEFAULT_MODEL_NAME; | ||
|
||
return ( | ||
<Chat | ||
key={id} | ||
id={id} | ||
initialMessages={[]} | ||
selectedModelName={selectedModelName} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.