Skip to content

Commit

Permalink
fix: show toast when selecting models that require auth (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon authored Feb 14, 2025
1 parent 93068bf commit 83e09f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions components/model-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { User } from 'next-auth';
import { startTransition, useMemo, useOptimistic, useState } from 'react';

import { toast } from 'sonner';
import { saveChatModelAsCookie } from '@/app/(chat)/actions';
import { Button } from '@/components/ui/button';
import {
Expand Down Expand Up @@ -55,6 +55,11 @@ export function ModelSelector({
<DropdownMenuItem
key={id}
onSelect={() => {
if (chatModel.requiresAuth && !user) {
toast.error('Please login to use this model!');
return;
}

setOpen(false);

startTransition(() => {
Expand All @@ -66,10 +71,17 @@ export function ModelSelector({
data-active={id === optimisticModelId}
>
<div className="flex flex-col gap-1 items-start">
<div>{chatModel.name}</div>
<div className="flex flex-row gap-2.5">
<div>{chatModel.name}</div>

{chatModel.requiresAuth && !user && (
<div className="text-xs dark:bg-blue-600 h-fit py-0.5 px-1 rounded-md">
Login
</div>
)}
</div>
<div className="text-xs text-muted-foreground">
{chatModel.description}
{chatModel.requiresAuth && !user && ' (login to continue)'}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion lib/ai/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ export const chatModels: Array<ChatModel> = [
id: 'chat-model-reasoning',
name: 'Reasoning model',
description: 'Uses advanced reasoning',
requiresAuth: true,
requiresAuth: false,
},
];

0 comments on commit 83e09f6

Please sign in to comment.