Skip to content

An AI-powered search engine with a generative UI

Update model versions and hide model type selector for cloud (#775)

Yoshiki Miurad45c29d6285d
diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts
index 0ef623be..deacf9cb 100644
--- a/app/api/chat/route.ts
+++ b/app/api/chat/route.ts
@@ -4,10 +4,7 @@ import { cookies } from 'next/headers'
import { loadChat } from '@/lib/actions/chat'
import { calculateConversationTurn, trackChatEvent } from '@/lib/analytics'
import { getCurrentUserId } from '@/lib/auth/get-current-user'
-import {
- checkAndEnforceOverallChatLimit,
- checkAndEnforceQualityLimit
-} from '@/lib/rate-limit/chat-limits'
+import { checkAndEnforceOverallChatLimit } from '@/lib/rate-limit/chat-limits'
import { checkAndEnforceGuestLimit } from '@/lib/rate-limit/guest-limit'
import { createChatStreamResponse } from '@/lib/streaming/create-chat-stream-response'
import { createEphemeralChatStreamResponse } from '@/lib/streaming/create-ephemeral-chat-stream-response'
@@ -95,7 +92,9 @@ export async function POST(req: Request) {
? (searchModeCookie as SearchMode)
: 'quick'
- const modelCookieStore = isGuest
+ const isCloudDeployment = process.env.MORPHIC_CLOUD_DEPLOYMENT === 'true'
+ const forceSpeed = isGuest || isCloudDeployment
+ const modelCookieStore = forceSpeed
? ({
get: (name: string) =>
name === 'modelType'
@@ -120,20 +119,14 @@ export async function POST(req: Request) {
)
}
- // Check rate limit for quality mode
+ // Resolve model type from cookie (forced to speed for guests and cloud)
const modelTypeCookie = cookieStore.get('modelType')?.value
const resolvedModelType =
modelTypeCookie === 'quality' || modelTypeCookie === 'speed'
? modelTypeCookie
: undefined
- const modelType = isGuest ? 'speed' : resolvedModelType
+ const modelType = forceSpeed ? 'speed' : resolvedModelType
if (!isGuest) {
- const qualityLimitResponse = await checkAndEnforceQualityLimit(
- userId,
- modelType === 'quality'
- )
- if (qualityLimitResponse) return qualityLimitResponse
-
const overallLimitResponse = await checkAndEnforceOverallChatLimit(userId)
if (overallLimitResponse) return overallLimitResponse
}
diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx
index c268a494..6ae02694 100644
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@ -295,7 +295,9 @@ export function ChatPanel({
<MessageCirclePlus className="size-4 group-hover:rotate-12 transition-all" />
</Button>
)}
- <ModelTypeSelector disabled={isGuest} />
+ {process.env.NEXT_PUBLIC_MORPHIC_CLOUD_DEPLOYMENT !== 'true' && (
+ <ModelTypeSelector disabled={isGuest} />
+ )}
<Button
type={isLoading ? 'button' : 'submit'}
size={'icon'}
diff --git a/config/models/cloud.json b/config/models/cloud.json
index 8d766315..0035de86 100644
--- a/config/models/cloud.json
+++ b/config/models/cloud.json
@@ -4,14 +4,14 @@
"byMode": {
"quick": {
"speed": {
- "id": "gemini-2.5-flash",
- "name": "Gemini 2.5 Flash",
+ "id": "gemini-3-flash-preview",
+ "name": "Gemini 3 Flash Preview",
"provider": "Google",
"providerId": "google"
},
"quality": {
- "id": "gemini-2.5-pro",
- "name": "Gemini 2.5 Pro",
+ "id": "gemini-3-pro",
+ "name": "Gemini 3 Pro",
"provider": "Google",
"providerId": "google"
}
@@ -24,14 +24,14 @@
"providerId": "openai",
"providerOptions": {
"openai": {
- "reasoningEffort": "low",
+ "reasoningEffort": "medium",
"reasoningSummary": "auto"
}
}
},
"quality": {
- "id": "gpt-5",
- "name": "GPT-5",
+ "id": "gpt-5.2",
+ "name": "GPT-5.2",
"provider": "OpenAI",
"providerId": "openai",
"providerOptions": {
diff --git a/config/models/default.json b/config/models/default.json
index 530955c8..fd778866 100644
--- a/config/models/default.json
+++ b/config/models/default.json
@@ -16,8 +16,8 @@
}
},
"quality": {
- "id": "gpt-5",
- "name": "GPT-5",
+ "id": "gpt-5.2",
+ "name": "GPT-5.2",
"provider": "OpenAI",
"providerId": "openai",
"providerOptions": {
@@ -36,14 +36,14 @@
"providerId": "openai",
"providerOptions": {
"openai": {
- "reasoningEffort": "low",
+ "reasoningEffort": "medium",
"reasoningSummary": "auto"
}
}
},
"quality": {
- "id": "gpt-5",
- "name": "GPT-5",
+ "id": "gpt-5.2",
+ "name": "GPT-5.2",
"provider": "OpenAI",
"providerId": "openai",
"providerOptions": {
@@ -56,8 +56,8 @@
}
},
"relatedQuestions": {
- "id": "gpt-4o-mini",
- "name": "GPT-4o mini",
+ "id": "gpt-4.1",
+ "name": "GPT-4.1",
"provider": "OpenAI",
"providerId": "openai"
}
diff --git a/lib/rate-limit/chat-limits.ts b/lib/rate-limit/chat-limits.ts
index 05587aa3..94ea4a5f 100644
--- a/lib/rate-limit/chat-limits.ts
+++ b/lib/rate-limit/chat-limits.ts
@@ -2,69 +2,8 @@ import { Redis } from '@upstash/redis'
import { perfLog } from '@/lib/utils/perf-logging'
-const DAILY_QUALITY_LIMIT = 10
const DAILY_CHAT_LIMIT = 100
-/**
- * Internal function to check rate limit using Upstash Redis
- */
-async function checkQualityChatLimit(userId: string): Promise<{
- allowed: boolean
- remaining: number
- resetAt: number
-}> {
- // If not in cloud deployment mode, allow unlimited requests
- if (process.env.MORPHIC_CLOUD_DEPLOYMENT !== 'true') {
- return { allowed: true, remaining: Infinity, resetAt: 0 }
- }
-
- // If Upstash is not configured, allow unlimited requests
- if (
- !process.env.UPSTASH_REDIS_REST_URL ||
- !process.env.UPSTASH_REDIS_REST_TOKEN
- ) {
- return { allowed: true, remaining: Infinity, resetAt: 0 }
- }
-
- try {
- const redis = new Redis({
- url: process.env.UPSTASH_REDIS_REST_URL,
- token: process.env.UPSTASH_REDIS_REST_TOKEN
- })
-
- // Create daily key with date
- const dateKey = new Date().toISOString().split('T')[0] // YYYY-MM-DD
- const key = `rl:quality:chat:${userId}:${dateKey}`
-
- // Increment counter with timeout
- const count = await Promise.race([
- redis.incr(key),
- new Promise<number>((_, reject) =>
- setTimeout(() => reject(new Error('Redis timeout')), 3000)
- )
- ])
-
- // Set expiry on first request of the day
- if (count === 1) {
- const secondsUntilMidnight = getSecondsUntilMidnight()
- await redis.expire(key, secondsUntilMidnight)
- }
-
- const remaining = Math.max(0, DAILY_QUALITY_LIMIT - count)
- const resetAt = getNextMidnightTimestamp()
-
- return {
- allowed: count <= DAILY_QUALITY_LIMIT,
- remaining,
- resetAt
- }
- } catch (error) {
- // On error, allow request to proceed (availability over strict limiting)
- console.error('Rate limit check failed:', error)
- return { allowed: true, remaining: Infinity, resetAt: 0 }
- }
-}
-
/**
* Get seconds until next midnight UTC
*/
@@ -139,50 +78,7 @@ async function checkOverallChatLimit(userId: string): Promise<{
}
/**
- * Check and enforce quality chat rate limit
- * Returns a 429 Response if limit is exceeded, null if allowed
- */
-export async function checkAndEnforceQualityLimit(
- userId: string,
- isQualityMode: boolean
-): Promise<Response | null> {
- // Only check limit for quality mode
- if (!isQualityMode) {
- return null
- }
-
- const result = await checkQualityChatLimit(userId)
-
- if (!result.allowed) {
- return new Response(
- JSON.stringify({
- error: 'Daily quality limit reached. Please try again tomorrow.',
- remaining: 0,
- resetAt: result.resetAt,
- limit: DAILY_QUALITY_LIMIT
- }),
- {
- status: 429,
- headers: {
- 'Content-Type': 'application/json',
- 'X-RateLimit-Limit': String(DAILY_QUALITY_LIMIT),
- 'X-RateLimit-Remaining': '0',
- 'X-RateLimit-Reset': String(result.resetAt)
- }
- }
- )
- }
-
- // Log usage for debugging
- perfLog(
- `Quality chat usage: ${DAILY_QUALITY_LIMIT - result.remaining}/${DAILY_QUALITY_LIMIT}`
- )
-
- return null
-}
-
-/**
- * Check and enforce speed chat rate limit
+ * Check and enforce chat rate limit
* Returns a 429 Response if limit is exceeded, null if allowed
*/
export async function checkAndEnforceOverallChatLimit(