Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show toast when selecting models that require auth #796

Merged
merged 2 commits into from
Feb 14, 2025
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
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,
},
];