Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createResumableStreamContext } from "resumable-stream";
import { auth, type UserType } from "@/app/(auth)/auth";
import { entitlementsByUserType } from "@/lib/ai/entitlements";
import { type RequestHints, systemPrompt } from "@/lib/ai/prompts";
import { allowedModelIds } from "@/lib/ai/models";
import { getLanguageModel } from "@/lib/ai/providers";
import { createDocument } from "@/lib/ai/tools/create-document";
import { getWeather } from "@/lib/ai/tools/get-weather";
Expand Down Expand Up @@ -74,6 +75,10 @@ export async function POST(request: Request) {
return new ChatbotError("unauthorized:chat").toResponse();
}

if (!allowedModelIds.has(selectedChatModel)) {
return new ChatbotError("bad_request:api").toResponse();
}

await checkIpRateLimit(ipAddress(request));

const userType: UserType = session.user.type;
Expand Down Expand Up @@ -139,8 +144,9 @@ export async function POST(request: Request) {
}

const isReasoningModel =
selectedChatModel.includes("reasoning") ||
selectedChatModel.includes("thinking");
selectedChatModel.endsWith("-thinking") ||
(selectedChatModel.includes("reasoning") &&
!selectedChatModel.includes("non-reasoning"));

const modelMessages = await convertToModelMessages(uiMessages);

Expand Down Expand Up @@ -179,7 +185,9 @@ export async function POST(request: Request) {
},
});

dataStream.merge(result.toUIMessageStream({ sendReasoning: true }));
dataStream.merge(
result.toUIMessageStream({ sendReasoning: isReasoningModel }),
);

if (titlePromise) {
const title = await titlePromise;
Expand Down
7 changes: 4 additions & 3 deletions components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ const PurePreviewMessage = ({

if (type === "reasoning") {
const hasContent = part.text?.trim().length > 0;
const isStreaming = "state" in part && part.state === "streaming";
if (hasContent || isStreaming) {
if (hasContent) {
const isStreaming =
"state" in part && part.state === "streaming";
return (
<MessageReasoning
isLoading={isLoading || isStreaming}
key={key}
reasoning={part.text || ""}
reasoning={part.text}
/>
);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/ai/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const chatModels: ChatModel[] = [
description: "Fast and cost-effective for simple tasks",
},
{
id: "openai/gpt-5.2",
name: "GPT-5.2",
id: "openai/gpt-5-mini",
name: "GPT-5 Mini",
provider: "openai",
description: "Most capable OpenAI model",
},
Expand Down Expand Up @@ -65,6 +65,8 @@ export const chatModels: ChatModel[] = [
];

// Group models by provider for UI
export const allowedModelIds = new Set(chatModels.map((m) => m.id));

export const modelsByProvider = chatModels.reduce(
(acc, model) => {
if (!acc[model.provider]) {
Expand Down
3 changes: 2 additions & 1 deletion lib/ai/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function getLanguageModel(modelId: string) {
}

const isReasoningModel =
modelId.includes("reasoning") || modelId.endsWith("-thinking");
modelId.endsWith("-thinking") ||
(modelId.includes("reasoning") && !modelId.includes("non-reasoning"));

if (isReasoningModel) {
const gatewayModelId = modelId.replace(THINKING_SUFFIX_REGEX, "");
Expand Down
Loading