mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
bug fix: models<5 disappear when clicked
This commit is contained in:
1 parent
1ad9a45103
commit
33782a773d
8 files changed
+55
-22
No files matched your search
@@ -111,11 +111,13 @@ describe('ModelSelector', () => {
|
||||
// Recently used section should NOT be visible
|
||||
expect(screen.queryByText('Recently Used')).not.toBeInTheDocument();
|
||||
|
||||
// provider1 should be hidden since all its models are in recently used
|
||||
expect(screen.queryByText('provider1')).not.toBeInTheDocument();
|
||||
// provider1 should still be visible (models appear in both sections now)
|
||||
expect(screen.getByText('provider1')).toBeInTheDocument();
|
||||
expect(screen.getByText('model1')).toBeInTheDocument();
|
||||
expect(screen.getByText('model2')).toBeInTheDocument();
|
||||
|
||||
// provider2 should still show with model3
|
||||
expect(screen.getByText('provider2/model3')).toBeInTheDocument();
|
||||
expect(screen.getByText('model3')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows recently used section when less than 5 models but some recently used are not available', async () => {
|
||||
@@ -160,11 +162,17 @@ describe('ModelSelector', () => {
|
||||
|
||||
// Wait for the dropdown to open
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('provider1')).toBeInTheDocument();
|
||||
// provider1 appears in both recently used and available sections
|
||||
const provider1Elements = screen.queryAllByText('provider1');
|
||||
expect(provider1Elements.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// Recently used section SHOULD be visible
|
||||
expect(screen.getByText('Recently Used')).toBeInTheDocument();
|
||||
|
||||
// provider1 should appear in both sections (recently used and available)
|
||||
const provider1Elements = screen.queryAllByText('provider1');
|
||||
expect(provider1Elements.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
it('shows recently used section when 5 or more models are available', async () => {
|
||||
@@ -217,13 +225,22 @@ describe('ModelSelector', () => {
|
||||
// Recently used section SHOULD be visible
|
||||
expect(screen.getByText('Recently Used')).toBeInTheDocument();
|
||||
|
||||
// provider1 should be hidden since all its models are in recently used
|
||||
expect(screen.queryByText('provider1')).not.toBeInTheDocument();
|
||||
// provider1 should still be visible (models appear in both sections now)
|
||||
// Use queryAllByText since provider1 appears as a heading in both sections
|
||||
const provider1Elements = screen.queryAllByText('provider1');
|
||||
expect(provider1Elements.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// Models should be visible (display text is just the model name, not full ID)
|
||||
// model1 and model2 appear in both recently used and available sections
|
||||
const model1Elements = screen.queryAllByText('model1');
|
||||
expect(model1Elements.length).toBeGreaterThanOrEqual(1);
|
||||
const model2Elements = screen.queryAllByText('model2');
|
||||
expect(model2Elements.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
// provider2 and provider3 should still show
|
||||
expect(screen.getByText('provider2/model3')).toBeInTheDocument();
|
||||
expect(screen.getByText('provider2/model4')).toBeInTheDocument();
|
||||
expect(screen.getByText('provider3/model5')).toBeInTheDocument();
|
||||
// provider2 and provider3 should still show (only in available section)
|
||||
expect(screen.getByText('model3')).toBeInTheDocument();
|
||||
expect(screen.getByText('model4')).toBeInTheDocument();
|
||||
expect(screen.getByText('model5')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides recently used section when no recently used models exist', async () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useMemo, useEffect, memo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Decimal } from 'decimal.js';
|
||||
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings, TriangleAlert } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -23,8 +24,8 @@ type ModelType = {
|
||||
description?: string;
|
||||
contextLength?: number;
|
||||
pricing?: {
|
||||
prompt: any;
|
||||
completion: any;
|
||||
prompt: Decimal;
|
||||
completion: Decimal;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -91,20 +92,24 @@ interface ModelSelectorProps {
|
||||
}
|
||||
|
||||
// Render a model item in the list
|
||||
const ModelItem = memo(({ model, currentValue, onSelect }: {
|
||||
const ModelItem = memo(({ model, currentValue, onSelect, valuePrefix = '' }: {
|
||||
model: ModelType;
|
||||
currentValue: string;
|
||||
onSelect: (value: string) => void;
|
||||
valuePrefix?: string;
|
||||
}) => {
|
||||
const parsed = parseModelId(model.fullId);
|
||||
const displayText = parsed.company
|
||||
? `${parsed.company}/${parsed.modelName}`
|
||||
: parsed.modelName;
|
||||
|
||||
// Use prefix to make value unique (prevents both recently used and available from highlighting together)
|
||||
const uniqueValue = valuePrefix ? `${valuePrefix}-${model.fullId}` : model.fullId;
|
||||
|
||||
return (
|
||||
<CommandItem
|
||||
key={model.fullId}
|
||||
value={model.fullId}
|
||||
value={uniqueValue}
|
||||
keywords={[model.fullId]}
|
||||
onSelect={() => onSelect(model.fullId)}
|
||||
className="cursor-pointer"
|
||||
@@ -154,13 +159,10 @@ export const ModelSelector = memo(function ModelSelector({
|
||||
|
||||
const recentlyUsedModels = useMemo(() => settings.recentlyUsedModels || [], [settings.recentlyUsedModels]);
|
||||
|
||||
// Create a Set of recently used model IDs for efficient lookup
|
||||
const recentlyUsedSet = useMemo(() => new Set(recentlyUsedModels), [recentlyUsedModels]);
|
||||
|
||||
// Group models by provider
|
||||
const modelGroups = useMemo(() =>
|
||||
groupModelsByProvider(models, recentlyUsedSet),
|
||||
[models, recentlyUsedSet]
|
||||
// Group models by provider (don't exclude recently used - they should appear in both sections)
|
||||
const modelGroups = useMemo(
|
||||
() => groupModelsByProvider(models, new Set()),
|
||||
[models]
|
||||
);
|
||||
|
||||
// Determine if we should show the "Recently Used" section
|
||||
@@ -428,6 +430,7 @@ export const ModelSelector = memo(function ModelSelector({
|
||||
model={model}
|
||||
currentValue={value}
|
||||
onSelect={handleSelect}
|
||||
valuePrefix="recent"
|
||||
/>
|
||||
))}
|
||||
</CommandGroup>
|
||||
@@ -438,7 +441,7 @@ export const ModelSelector = memo(function ModelSelector({
|
||||
|
||||
{/* Available Models section */}
|
||||
{!isLoading && modelGroups.length > 0 && (
|
||||
<CommandGroup heading="Available Models" />
|
||||
<CommandGroup heading={t('availableModels')} />
|
||||
)}
|
||||
|
||||
{/* Loading state */}
|
||||
@@ -477,6 +480,13 @@ export const ModelSelector = memo(function ModelSelector({
|
||||
</CommandGroup>
|
||||
)}
|
||||
|
||||
{/* No models available state */}
|
||||
{!isLoading && !error && !shouldShowRecentlyUsed && modelGroups.length === 0 && (
|
||||
<div className="py-12 text-center text-sm text-muted-foreground">
|
||||
<p>{t('noModelsFound')}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Provider models */}
|
||||
{!isLoading && modelGroups.map((group) => (
|
||||
<CommandGroup key={group.provider} heading={group.provider}>
|
||||
|
||||
@@ -281,6 +281,7 @@
|
||||
"noModelsFound": "No models found.",
|
||||
"tryCustomModel": "Try using a custom model instead.",
|
||||
"recentlyUsed": "Recently Used",
|
||||
"availableModels": "Available Models",
|
||||
"errorLoadingModels": "Error Loading Models",
|
||||
"apiAuthenticationFailed": "API Authentication Failed",
|
||||
"invalidApiKey": "Invalid API key for {{provider}}. Please check your API key in Settings.",
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
"noModelsFound": "Ba a sami samfura ba.",
|
||||
"tryCustomModel": "Gwada amfani da samfuri na musamman.",
|
||||
"recentlyUsed": "An yi amfani da su kwanan nan",
|
||||
"availableModels": "Samfura Masu Samuwa",
|
||||
"errorLoadingModels": "Kuskure wajen Lodin Samfura",
|
||||
"apiAuthenticationFailed": "Gazawar Tabbatarwar API",
|
||||
"invalidApiKey": "Maɓallin API na {{provider}} ba daidai ba ne. Da fatan za a duba maɓallin API a cikin Saitunan.",
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
"noModelsFound": "Ahụghị ụdịdị ọ bụla.",
|
||||
"tryCustomModel": "Gbalịa iji ụdịdị omenala kama.",
|
||||
"recentlyUsed": "Ejiri Na Nso Nso A",
|
||||
"availableModels": "Ụdịdị Dị",
|
||||
"errorLoadingModels": "Njehie Na-ebu Ụdịdị",
|
||||
"contextUsage": "Ojiji ọnọdụ: {{tokens}} / {{total}} tokens ({{percentage}}%)",
|
||||
"totalCostSession": "Mkpokọta ọnụ ahịa maka oge nkata a",
|
||||
|
||||
@@ -277,6 +277,7 @@
|
||||
"noModelsFound": "Nenhum modelo encontrado.",
|
||||
"tryCustomModel": "Tente usar um modelo personalizado.",
|
||||
"recentlyUsed": "Usados Recentemente",
|
||||
"availableModels": "Modelos Disponíveis",
|
||||
"errorLoadingModels": "Erro ao Carregar Modelos",
|
||||
"apiAuthenticationFailed": "Falha na Autenticação da API",
|
||||
"invalidApiKey": "Chave de API inválida para {{provider}}. Verifique sua chave de API nas Configurações.",
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
"noModelsFound": "Ko si awọn awoṣe ti a ri.",
|
||||
"tryCustomModel": "Gbiyanju lilo awoṣe aṣa dipo.",
|
||||
"recentlyUsed": "Ti a Lo Laipẹ",
|
||||
"availableModels": "Awọn awoṣe Ti O Wa",
|
||||
"errorLoadingModels": "Aṣiṣe Gbigbe Awọn awoṣe",
|
||||
"contextUsage": "Lilo aaye oro: {{tokens}} / {{total}} awọn token ({{percentage}}%)",
|
||||
"totalCostSession": "Lapapọ iye owo fun igba ibaraẹnisọrọ yii",
|
||||
|
||||
@@ -277,6 +277,7 @@
|
||||
"noModelsFound": "未找到模型。",
|
||||
"tryCustomModel": "尝试使用自定义模型。",
|
||||
"recentlyUsed": "最近使用",
|
||||
"availableModels": "可用模型",
|
||||
"errorLoadingModels": "加载模型时出错",
|
||||
"apiAuthenticationFailed": "API身份验证失败",
|
||||
"invalidApiKey": "{{provider}}的API密钥无效。请在设置中检查您的API密钥。",
|
||||
|
||||
Reference in new issue
Block a user