mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +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>
|
||||
|
||||
Reference in new issue
Block a user