mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Memoize image model filters
This commit is contained in:
3 files changed
+33
-29
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -33,6 +33,20 @@ export function ImageModelDialog({ open, onOpenChange }: ImageModelDialogProps)
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const imageModelFilter = useCallback((model: { type?: 'chat' | 'image'; modalities?: string[] }) => {
|
||||
// Filter out models that are definitely NOT image models
|
||||
// If type is "chat", exclude it
|
||||
if (model.type === 'chat') {
|
||||
return false;
|
||||
}
|
||||
// If modalities exist but don't include "image", exclude it
|
||||
if (model.modalities && !model.modalities.includes('image')) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise include it (type is "image", modalities includes "image", or both are undefined)
|
||||
return true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[500px]">
|
||||
@@ -50,19 +64,7 @@ export function ImageModelDialog({ open, onOpenChange }: ImageModelDialogProps)
|
||||
value={selectedModel}
|
||||
onChange={setSelectedModel}
|
||||
className="flex-1"
|
||||
modelFilter={(model) => {
|
||||
// Filter out models that are definitely NOT image models
|
||||
// If type is "chat", exclude it
|
||||
if (model.type === 'chat') {
|
||||
return false;
|
||||
}
|
||||
// If modalities exist but don't include "image", exclude it
|
||||
if (model.modalities && !model.modalities.includes('image')) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise include it (type is "image", modalities includes "image", or both are undefined)
|
||||
return true;
|
||||
}}
|
||||
modelFilter={imageModelFilter}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -172,7 +172,7 @@ Shakespeare supports AI-powered image generation. Users can configure an image m
|
||||
**Important Notes:**
|
||||
- Models that support image generation can use either the chat completions endpoint (for models with "image" output modality) or the dedicated images generation endpoint
|
||||
- If users experience issues with image generation, they should try selecting a different image model in Settings > AI
|
||||
- Recommended models include gpt-image-1, dall-e-3, or similar high-quality yet affordable options
|
||||
- Recommended models include gpt-image-1 and gemini-3-pro-image
|
||||
- The generate_image tool will only be available once a compatible image model is configured
|
||||
|
||||
## Available Tools
|
||||
|
||||
+16
-14
@@ -1,4 +1,4 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown, RotateCcw, FileText, Plus, Edit, ExternalLink, X } from 'lucide-react';
|
||||
import {
|
||||
@@ -335,6 +335,20 @@ export function AISettings() {
|
||||
const configuredProviderIds = settings.providers.map(p => p.id);
|
||||
const availablePresets = AI_PROVIDER_PRESETS.filter(preset => !configuredProviderIds.includes(preset.id));
|
||||
|
||||
const imageModelFilter = useCallback((model: { type?: 'chat' | 'image'; modalities?: string[] }) => {
|
||||
// Filter out models that are definitely NOT image models
|
||||
// If type is "chat", exclude it
|
||||
if (model.type === 'chat') {
|
||||
return false;
|
||||
}
|
||||
// If modalities exist but don't include "image", exclude it
|
||||
if (model.modalities && !model.modalities.includes('image')) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise include it (type is "image", modalities includes "image", or both are undefined)
|
||||
return true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6 pb-16">
|
||||
{isMobile && (
|
||||
@@ -685,19 +699,7 @@ export function AISettings() {
|
||||
value={settings.imageModel || ''}
|
||||
onChange={(value) => updateSettings({ imageModel: value || undefined })}
|
||||
className="flex-1"
|
||||
modelFilter={(model) => {
|
||||
// Filter out models that are definitely NOT image models
|
||||
// If type is "chat", exclude it
|
||||
if (model.type === 'chat') {
|
||||
return false;
|
||||
}
|
||||
// If modalities exist but don't include "image", exclude it
|
||||
if (model.modalities && !model.modalities.includes('image')) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise include it (type is "image", modalities includes "image", or both are undefined)
|
||||
return true;
|
||||
}}
|
||||
modelFilter={imageModelFilter}
|
||||
/>
|
||||
{settings.imageModel && (
|
||||
<Button
|
||||
|
||||
Reference in new issue
Block a user