mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 23:26:02 +00:00
generation count behavior
This commit is contained in:
1 parent
586e6f10d0
commit
4b53badf3b
4 files changed
+31
-18
No files matched your search
@@ -174,13 +174,14 @@ export const PromptBoxImage = ({
|
||||
}, [imageMediaId, url]);
|
||||
|
||||
useEffect(() => {
|
||||
const caps = getCapabilitiesForModel(selectedModel);
|
||||
const defaultCount = Math.min(
|
||||
Math.max(1, caps.defaultGenerationCount ?? 1),
|
||||
caps.maxGenerationCount,
|
||||
);
|
||||
setGenerationCount(defaultCount);
|
||||
}, [selectedModel]);
|
||||
if (selectedModel?.isValidGenerationCount(generationCount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultGenerations = selectedModel?.defaultGenerationCount || 4;
|
||||
|
||||
setGenerationCount(defaultGenerations);
|
||||
}, [selectedModel, generationCount]);
|
||||
|
||||
useEffect(() => {
|
||||
setAspectRatioList((prev) =>
|
||||
|
||||
@@ -19,14 +19,15 @@ export const GenerationCountPicker = ({
|
||||
}: GenerationCountPickerProps) => {
|
||||
|
||||
const maxGenerationCount = currentModel?.maxGenerationCount || DEFAULT_GENERATION_COUNT;
|
||||
const hasCustomOptions = !!currentModel?.generationCountOptions;
|
||||
const hasPredefinedOptions = !!currentModel?.predefinedGenerationCounts;
|
||||
|
||||
let generationCountOptions: PopoverItem[];
|
||||
|
||||
if (hasCustomOptions) {
|
||||
generationCountOptions = buildCustomCountOptions(currentModel?.generationCountOptions || [], currentCount);
|
||||
// Count pickers either have a "[1,2, ... max]" set of options, or a pre-defined list of options.
|
||||
if (hasPredefinedOptions) {
|
||||
generationCountOptions = buildPredefinedCountOptions(currentModel?.predefinedGenerationCounts || [], currentCount);
|
||||
} else {
|
||||
generationCountOptions = buildCountOptions(maxGenerationCount, currentCount);
|
||||
generationCountOptions = buildSequentialCountOptions(maxGenerationCount, currentCount);
|
||||
}
|
||||
|
||||
const onSelect = (item: PopoverItem) => {
|
||||
@@ -64,7 +65,7 @@ export const GenerationCountPicker = ({
|
||||
)
|
||||
}
|
||||
|
||||
const buildCountOptions = (maxCount: number, currentCount: number): PopoverItem[] => {
|
||||
const buildSequentialCountOptions = (maxCount: number, currentCount: number): PopoverItem[] => {
|
||||
const options = [];
|
||||
for (let i = 0; i < maxCount; i++) {
|
||||
const count = i + 1;
|
||||
@@ -76,7 +77,7 @@ const buildCountOptions = (maxCount: number, currentCount: number): PopoverItem[
|
||||
return options;
|
||||
}
|
||||
|
||||
const buildCustomCountOptions = (options: number[], currentCount: number): PopoverItem[] => {
|
||||
const buildPredefinedCountOptions = (options: number[], currentCount: number): PopoverItem[] => {
|
||||
const result: PopoverItem[] = [];
|
||||
options.forEach(option => {
|
||||
result.push({
|
||||
|
||||
@@ -18,7 +18,7 @@ export class ImageModel extends Model {
|
||||
readonly defaultGenerationCount: number;
|
||||
|
||||
// If set, use this instead of `maxGenerationCount`.
|
||||
readonly generationCountOptions?: number[];
|
||||
readonly predefinedGenerationCounts?: number[];
|
||||
|
||||
// Signals image editing models that focus on editing a single image.
|
||||
readonly canEditImages: boolean;
|
||||
@@ -66,7 +66,7 @@ export class ImageModel extends Model {
|
||||
selectorBadges: string[];
|
||||
maxGenerationCount: number;
|
||||
defaultGenerationCount: number;
|
||||
generationCountOptions?: number[];
|
||||
predefinedGenerationCounts?: number[];
|
||||
canEditImages?: boolean;
|
||||
usesInpaintingMask?: boolean;
|
||||
editingIsInpainting?: boolean;
|
||||
@@ -95,7 +95,7 @@ export class ImageModel extends Model {
|
||||
super(args);
|
||||
this.maxGenerationCount = args.maxGenerationCount;
|
||||
this.defaultGenerationCount = args.defaultGenerationCount;
|
||||
this.generationCountOptions = args.generationCountOptions;
|
||||
this.predefinedGenerationCounts = args.predefinedGenerationCounts;
|
||||
this.canEditImages = args.canEditImages ?? false;
|
||||
this.usesInpaintingMask = args.usesInpaintingMask ?? false;
|
||||
this.editingIsInpainting = args.editingIsInpainting ?? false;
|
||||
@@ -130,4 +130,13 @@ export class ImageModel extends Model {
|
||||
&& this.aspectRatios
|
||||
&& this.aspectRatios.length > 0;
|
||||
}
|
||||
|
||||
// Return whether the count of generations is valid for this model
|
||||
isValidGenerationCount(count: number): boolean {
|
||||
if (this.predefinedGenerationCounts) {
|
||||
return this.predefinedGenerationCounts.includes(count);
|
||||
} else {
|
||||
return count >= 1 && count <= this.maxGenerationCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,10 @@ export const IMAGE_MODELS: ImageModel[] = [
|
||||
selectorName: "Grok",
|
||||
selectorDescription: "Fast af",
|
||||
selectorBadges: ["10 sec."],
|
||||
// NB: Grok only supports 6 images at a time
|
||||
defaultGenerationCount: 6,
|
||||
maxGenerationCount: 6,
|
||||
generationCountOptions: [6],
|
||||
predefinedGenerationCounts: [6],
|
||||
canUseImagePrompt: false,
|
||||
maxImagePromptCount: 6,
|
||||
progressBarTime: 10000,
|
||||
@@ -45,9 +46,10 @@ export const IMAGE_MODELS: ImageModel[] = [
|
||||
selectorName: "Midjourney",
|
||||
selectorDescription: "Stunning style and quality",
|
||||
selectorBadges: ["45 sec."],
|
||||
// NB: Midjourney only supports 4 images at a time
|
||||
maxGenerationCount: 4,
|
||||
defaultGenerationCount: 4,
|
||||
generationCountOptions: [4],
|
||||
predefinedGenerationCounts: [4],
|
||||
canUseImagePrompt: false,
|
||||
maxImagePromptCount: 6,
|
||||
progressBarTime: 45000,
|
||||
|
||||
Reference in new issue
Block a user