Skip to content

An AI-powered search engine with a generative UI

refactor: update getModels to use fetch instead of fs

Yoshiki Miurabbe7ef0ddcd6
diff --git a/app/page.tsx b/app/page.tsx
index fd8d62cb..bd5844a8 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -2,8 +2,8 @@ import { Chat } from '@/components/chat'
import { getModels } from '@/lib/config/models'
import { generateId } from 'ai'
-export default function Page() {
+export default async function Page() {
const id = generateId()
- const models = getModels()
+ const models = await getModels()
return <Chat id={id} models={models} />
}
diff --git a/app/search/[id]/page.tsx b/app/search/[id]/page.tsx
index 954eb619..7244c20d 100644
--- a/app/search/[id]/page.tsx
+++ b/app/search/[id]/page.tsx
@@ -34,6 +34,6 @@ export default async function SearchPage(props: {
notFound()
}
- const models = getModels()
+ const models = await getModels()
return <Chat id={id} savedMessages={messages} models={models} />
}
diff --git a/app/search/page.tsx b/app/search/page.tsx
index 47d1405a..b1533fe4 100644
--- a/app/search/page.tsx
+++ b/app/search/page.tsx
@@ -14,6 +14,6 @@ export default async function SearchPage(props: {
}
const id = generateId()
- const models = getModels()
+ const models = await getModels()
return <Chat id={id} query={q} models={models} />
}
diff --git a/app/share/[id]/page.tsx b/app/share/[id]/page.tsx
index a940f3a4..d9fbc624 100644
--- a/app/share/[id]/page.tsx
+++ b/app/share/[id]/page.tsx
@@ -29,7 +29,7 @@ export default async function SharePage(props: {
return notFound()
}
- const models = getModels()
+ const models = await getModels()
return (
<Chat
id={chat.id}
diff --git a/lib/config/models.ts b/lib/config/models.ts
index ab826c2f..64471c22 100644
--- a/lib/config/models.ts
+++ b/lib/config/models.ts
@@ -1,6 +1,4 @@
import { Model } from '@/lib/types/models'
-import { existsSync, readFileSync } from 'fs'
-import { join } from 'path'
export function validateModel(model: any): model is Model {
return (
@@ -14,11 +12,10 @@ export function validateModel(model: any): model is Model {
)
}
-export function getModels(): Model[] {
- const configPath = join(process.cwd(), 'public', 'config', 'models.json')
-
+export async function getModels(): Promise<Model[]> {
try {
- const config = JSON.parse(readFileSync(configPath, 'utf-8'))
+ const response = await fetch('/config/models.json')
+ const config = await response.json()
if (Array.isArray(config.models) && config.models.every(validateModel)) {
return config.models
}