An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
refactor: move models to json file
Yoshiki Miuraaa32079a5330
diff --git a/app/page.tsx b/app/page.tsxindex f60160bd..b2a50c95 100644--- a/app/page.tsx+++ b/app/page.tsx@@ -1,7 +1,9 @@import { Chat } from '@/components/chat'+import modelsList from '@/lib/config/models.json'+import { Model } from '@/lib/types/models'import { generateId } from 'ai'export default function Page() {const id = generateId()- return <Chat id={id} />+ return <Chat id={id} models={modelsList.models as Model[]} />}diff --git a/app/search/[id]/page.tsx b/app/search/[id]/page.tsxindex 25a909c2..ebbc3793 100644--- a/app/search/[id]/page.tsx+++ b/app/search/[id]/page.tsx@@ -1,7 +1,9 @@-import { notFound, redirect } from 'next/navigation'import { Chat } from '@/components/chat'import { getChat } from '@/lib/actions/chat'+import modelsList from '@/lib/config/models.json'+import { Model } from '@/lib/types/models'import { convertToUIMessages } from '@/lib/utils'+import { notFound, redirect } from 'next/navigation'export const maxDuration = 60@@ -32,5 +34,11 @@ export default async function SearchPage(props: {notFound()}- return <Chat id={id} savedMessages={messages} />+ return (+ <Chat+ id={id}+ savedMessages={messages}+ models={modelsList.models as Model[]}+ />+ )}diff --git a/app/share/[id]/page.tsx b/app/share/[id]/page.tsxindex c94c688a..bd25a476 100644--- a/app/share/[id]/page.tsx+++ b/app/share/[id]/page.tsx@@ -1,7 +1,9 @@-import { notFound } from 'next/navigation'import { Chat } from '@/components/chat'import { getSharedChat } from '@/lib/actions/chat'+import modelsList from '@/lib/config/models.json'+import { Model } from '@/lib/types/models'import { convertToUIMessages } from '@/lib/utils'+import { notFound } from 'next/navigation'export async function generateMetadata(props: {params: Promise<{ id: string }>@@ -30,5 +32,11 @@ export default async function SharePage(props: {notFound()}- return <Chat id={id} savedMessages={messages} />+ return (+ <Chat+ id={id}+ savedMessages={messages}+ models={modelsList.models as Model[]}+ />+ )}diff --git a/components/chat-panel.tsx b/components/chat-panel.tsxindex 5d711f0b..5d1b1c53 100644--- a/components/chat-panel.tsx+++ b/components/chat-panel.tsx@@ -1,5 +1,6 @@'use client'+import { Model } from '@/lib/types/models'import { cn } from '@/lib/utils'import { Message } from 'ai'import { ArrowUp, MessageCirclePlus, Square } from 'lucide-react'@@ -22,6 +23,7 @@ interface ChatPanelProps {query?: stringstop: () => voidappend: (message: any) => void+ models?: Model[]}export function ChatPanel({@@ -33,7 +35,8 @@ export function ChatPanel({setMessages,query,stop,- append+ append,+ models}: ChatPanelProps) {const [showEmptyScreen, setShowEmptyScreen] = useState(false)const router = useRouter()@@ -130,7 +133,7 @@ export function ChatPanel({{/* Bottom menu area */}<div className="flex items-center justify-between p-3"><div className="flex items-center gap-2">- <ModelSelector />+ <ModelSelector models={models || []} /><SearchModeToggle /></div><div className="flex items-center gap-2">diff --git a/components/chat.tsx b/components/chat.tsxindex 01431e09..7d16278c 100644--- a/components/chat.tsx+++ b/components/chat.tsx@@ -1,6 +1,7 @@'use client'import { CHAT_ID } from '@/lib/constants'+import { Model } from '@/lib/types/models'import { Message, useChat } from 'ai/react'import { useEffect } from 'react'import { toast } from 'sonner'@@ -10,11 +11,13 @@ import { ChatPanel } from './chat-panel'export function Chat({id,savedMessages = [],- query+ query,+ models}: {id: stringsavedMessages?: Message[]query?: string+ models?: Model[]}) {const {messages,@@ -78,6 +81,7 @@ export function Chat({stop={stop}query={query}append={append}+ models={models}/></div>)diff --git a/components/model-selector.tsx b/components/model-selector.tsxindex 979af42b..3f39e306 100644--- a/components/model-selector.tsx+++ b/components/model-selector.tsx@@ -1,6 +1,6 @@'use client'-import { Model, models } from '@/lib/types/models'+import { Model } from '@/lib/types/models'import { getCookie, setCookie } from '@/lib/utils/cookies'import { isReasoningModel } from '@/lib/utils/registry'import { Check, ChevronsUpDown, Lightbulb } from 'lucide-react'@@ -29,25 +29,29 @@ function groupModelsByProvider(models: Model[]) {}, {} as Record<string, Model[]>)}-export function ModelSelector() {+interface ModelSelectorProps {+ models: Model[]+}++export function ModelSelector({ models }: ModelSelectorProps) {const [open, setOpen] = useState(false)- const [selectedModelId, setSelectedModelId] = useState<string>('')+ const [value, setValue] = useState('')useEffect(() => {- const savedModel = getCookie('selected-model')- if (savedModel) {- setSelectedModelId(savedModel)+ const modelId = getCookie('modelId')+ if (modelId) {+ setValue(modelId)}}, [])const handleModelSelect = (id: string) => {- setSelectedModelId(id === selectedModelId ? '' : id)- setCookie('selected-model', id)+ setValue(id === value ? '' : id)+ setCookie('modelId', id)setOpen(false)}+ const selectedModel = models.find(model => createModelId(model) === value)const groupedModels = groupModelsByProvider(models)- const selectedModel = models.find(m => createModelId(m) === selectedModelId)return (<Popover open={open} onOpenChange={setOpen}>@@ -108,9 +112,7 @@ export function ModelSelector() {</div><CheckclassName={`h-4 w-4 ${- selectedModelId === modelId- ? 'opacity-100'- : 'opacity-0'+ value === modelId ? 'opacity-100' : 'opacity-0'}`}/></CommandItem>diff --git a/lib/config/models.json b/lib/config/models.jsonnew file mode 100644index 00000000..44474f2e--- /dev/null+++ b/lib/config/models.json@@ -0,0 +1,149 @@+{+ "models": [+ {+ "id": "claude-3-5-sonnet-latest",+ "name": "Claude 3.5 Sonnet",+ "provider": "Anthropic",+ "providerId": "anthropic",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "claude-3-5-haiku-20241022",+ "name": "Claude 3.5 Haiku",+ "provider": "Anthropic",+ "providerId": "anthropic",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "<AZURE_DEPLOYMENT_NAME>",+ "name": "<AZURE_DEPLOYMENT_NAME>",+ "provider": "Azure",+ "providerId": "azure",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "accounts/fireworks/models/deepseek-r1",+ "name": "DeepSeek R1",+ "provider": "Fireworks",+ "providerId": "fireworks",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "deepseek-r1",+ "name": "DeepSeek R1",+ "provider": "Ollama",+ "providerId": "ollama",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "<OLLAMA_MODEL_ID>",+ "name": "<OLLAMA_MODEL_NAME>",+ "provider": "Ollama",+ "providerId": "ollama",+ "enabled": true,+ "toolCallType": "manual",+ "toolCallModel": "<OLLAMA_MODEL_ID>"+ },+ {+ "id": "deepseek-reasoner",+ "name": "DeepSeek R1",+ "provider": "DeepSeek",+ "providerId": "deepseek",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "deepseek-chat",+ "name": "DeepSeek V3",+ "provider": "DeepSeek",+ "providerId": "deepseek",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "gemini-2.0-pro-exp-02-05",+ "name": "Gemini 2.0 Pro (Exp)",+ "provider": "Google Generative AI",+ "providerId": "google",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "gemini-2.0-flash-thinking-exp-01-21",+ "name": "Gemini 2.0 Flash Thinking (Exp)",+ "provider": "Google Generative AI",+ "providerId": "google",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "gemini-2.0-flash",+ "name": "Gemini 2.0 Flash",+ "provider": "Google Generative AI",+ "providerId": "google",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "deepseek-r1-distill-llama-70b",+ "name": "DeepSeek R1 Distill Llama 70B",+ "provider": "Groq",+ "providerId": "groq",+ "enabled": true,+ "toolCallType": "manual"+ },+ {+ "id": "o3-mini",+ "name": "o3-mini",+ "provider": "OpenAI",+ "providerId": "openai",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "gpt-4o",+ "name": "GPT-4o",+ "provider": "OpenAI",+ "providerId": "openai",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "gpt-4o-mini",+ "name": "GPT-4o mini",+ "provider": "OpenAI",+ "providerId": "openai",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "<OPENAI_COMPATIBLE_MODEL>",+ "name": "<OPENAI_COMPATIBLE_MODEL>",+ "provider": "OpenAI Compatible",+ "providerId": "openai-compatible",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "grok-2-1212",+ "name": "Grok 2",+ "provider": "xAI",+ "providerId": "xai",+ "enabled": true,+ "toolCallType": "native"+ },+ {+ "id": "grok-2-vision-1212",+ "name": "Grok 2 Vision",+ "provider": "xAI",+ "providerId": "xai",+ "enabled": true,+ "toolCallType": "native"+ }+ ]+}diff --git a/lib/types/models.ts b/lib/types/models.tsindex 06c1a7fc..5c6e8b16 100644--- a/lib/types/models.ts+++ b/lib/types/models.ts@@ -3,109 +3,7 @@ export interface Model {name: stringprovider: stringproviderId: string+ enabled: boolean+ toolCallType: 'native' | 'manual'+ toolCallModel?: string}--export const models: Model[] = [- {- id: 'claude-3-5-sonnet-latest',- name: 'Claude 3.5 Sonnet',- provider: 'Anthropic',- providerId: 'anthropic'- },- {- id: 'claude-3-5-haiku-20241022',- name: 'Claude 3.5 Haiku',- provider: 'Anthropic',- providerId: 'anthropic'- },- {- id: process.env.NEXT_PUBLIC_AZURE_DEPLOYMENT_NAME || 'undefined',- name: process.env.NEXT_PUBLIC_AZURE_DEPLOYMENT_NAME || 'Undefined',- provider: 'Azure',- providerId: 'azure'- },- {- id: 'accounts/fireworks/models/deepseek-r1',- name: 'DeepSeek R1',- provider: 'Fireworks',- providerId: 'fireworks'- },- {- id: 'deepseek-reasoner',- name: 'DeepSeek R1',- provider: 'DeepSeek',- providerId: 'deepseek'- },- {- id: 'deepseek-chat',- name: 'DeepSeek V3',- provider: 'DeepSeek',- providerId: 'deepseek'- },- {- id: 'gemini-2.0-pro-exp-02-05',- name: 'Gemini 2.0 Pro (Exp)',- provider: 'Google Generative AI',- providerId: 'google'- },- {- id: 'gemini-2.0-flash-thinking-exp-01-21',- name: 'Gemini 2.0 Flash Thinking (Exp)',- provider: 'Google Generative AI',- providerId: 'google'- },- {- id: 'gemini-2.0-flash',- name: 'Gemini 2.0 Flash',- provider: 'Google Generative AI',- providerId: 'google'- },- {- id: 'deepseek-r1-distill-llama-70b',- name: 'DeepSeek R1 Distill Llama 70B',- provider: 'Groq',- providerId: 'groq'- },- {- id: process.env.NEXT_PUBLIC_OLLAMA_MODEL || 'deepseek-r1',- name: process.env.NEXT_PUBLIC_OLLAMA_MODEL || 'DeepSeek R1',- provider: 'Ollama',- providerId: 'ollama'- },- {- id: 'o3-mini',- name: 'o3-mini',- provider: 'OpenAI',- providerId: 'openai'- },- {- id: 'gpt-4o',- name: 'GPT-4o',- provider: 'OpenAI',- providerId: 'openai'- },- {- id: 'gpt-4o-mini',- name: 'GPT-4o mini',- provider: 'OpenAI',- providerId: 'openai'- },- {- id: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_MODEL || 'undefined',- name: process.env.NEXT_PUBLIC_OPENAI_COMPATIBLE_MODEL || 'Undefined',- provider: 'OpenAI Compatible',- providerId: 'openai-compatible'- },- {- id: 'grok-2-1212',- name: 'Grok 2',- provider: 'xAI',- providerId: 'xai'- },- {- id: 'grok-2-vision-1212',- name: 'Grok 2 Vision',- provider: 'xAI',- providerId: 'xai'- }-]