Fix AI text generation configuration reporting
This commit is contained in:
parent
3a9e0569c0
commit
b14b8ca2f4
@ -1,68 +1,69 @@
|
||||
/* eslint-disable quotes */
|
||||
import {
|
||||
parseAiAutoGeneratedFieldsText,
|
||||
AI_AUTO_GENERATED_FIELDS_DEFAULT,
|
||||
parseAiAutoGeneratedFieldsString,
|
||||
parseTitleAndCaption,
|
||||
} from "@/photo/ai";
|
||||
|
||||
describe('AI parses', () => {
|
||||
describe('auto-generated fields', () => {
|
||||
it('with spaces', () => {
|
||||
expect(parseAiAutoGeneratedFieldsText())
|
||||
expect(parseAiAutoGeneratedFieldsString())
|
||||
.toStrictEqual(AI_AUTO_GENERATED_FIELDS_DEFAULT);
|
||||
expect(parseAiAutoGeneratedFieldsString('all'))
|
||||
.toStrictEqual(['title', 'caption', 'tags', 'semantic']);
|
||||
expect(parseAiAutoGeneratedFieldsText('all'))
|
||||
.toStrictEqual(['title', 'caption', 'tags', 'semantic']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title'))
|
||||
.toStrictEqual(['title']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title, caption'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title, caption'))
|
||||
.toStrictEqual(['title', 'caption']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title, caption, invalid'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title, caption, invalid'))
|
||||
.toStrictEqual(['title', 'caption']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title, caption, invalid, tags'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title, caption, invalid, tags'))
|
||||
.toStrictEqual(['title', 'caption', 'tags']);
|
||||
expect(parseAiAutoGeneratedFieldsText('none'))
|
||||
expect(parseAiAutoGeneratedFieldsString('none'))
|
||||
.toStrictEqual([]);
|
||||
});
|
||||
it('without spaces', () => {
|
||||
expect(parseAiAutoGeneratedFieldsText('title,caption'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title,caption'))
|
||||
.toStrictEqual(['title', 'caption']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title,caption,invalid'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title,caption,invalid'))
|
||||
.toStrictEqual(['title', 'caption']);
|
||||
expect(parseAiAutoGeneratedFieldsText('title,caption,invalid,tags'))
|
||||
expect(parseAiAutoGeneratedFieldsString('title,caption,invalid,tags'))
|
||||
.toStrictEqual(['title', 'caption', 'tags']);
|
||||
});
|
||||
});
|
||||
it('received titles and captions', () => {
|
||||
// Complex case
|
||||
expect(parseTitleAndCaption(
|
||||
`'Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight."'`
|
||||
`'Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight."'`,
|
||||
)).toStrictEqual({
|
||||
title: 'Ephemeral Beauty',
|
||||
caption: 'Roses bask in fleeting sunlight',
|
||||
});
|
||||
// Without surrounding single quotes
|
||||
expect(parseTitleAndCaption(
|
||||
`Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight."`
|
||||
`Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight."`,
|
||||
)).toStrictEqual({
|
||||
title: 'Ephemeral Beauty',
|
||||
caption: 'Roses bask in fleeting sunlight',
|
||||
});
|
||||
// Without trailing period
|
||||
expect(parseTitleAndCaption(
|
||||
`Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight"`
|
||||
`Title: "Ephemeral Beauty" Caption: "Roses bask in fleeting sunlight"`,
|
||||
)).toStrictEqual({
|
||||
title: 'Ephemeral Beauty',
|
||||
caption: 'Roses bask in fleeting sunlight',
|
||||
});
|
||||
// Without and quotes
|
||||
expect(parseTitleAndCaption(
|
||||
`Title: Ephemeral Beauty Caption: Roses bask in fleeting sunlight`
|
||||
`Title: Ephemeral Beauty Caption: Roses bask in fleeting sunlight`,
|
||||
)).toStrictEqual({
|
||||
title: 'Ephemeral Beauty',
|
||||
caption: 'Roses bask in fleeting sunlight',
|
||||
});
|
||||
// With single space
|
||||
expect(parseTitleAndCaption(
|
||||
`Title: Ephemeral Beauty Caption: Roses bask in fleeting sunlight`
|
||||
`Title: Ephemeral Beauty Caption: Roses bask in fleeting sunlight`,
|
||||
)).toStrictEqual({
|
||||
title: 'Ephemeral Beauty',
|
||||
caption: 'Roses bask in fleeting sunlight',
|
||||
|
||||
@ -21,7 +21,7 @@ export const AI_AUTO_GENERATED_FIELDS_DEFAULT: AiAutoGeneratedField[] = [
|
||||
'semantic',
|
||||
];
|
||||
|
||||
export const parseAiAutoGeneratedFieldsText = (
|
||||
export const parseAiAutoGeneratedFieldsString = (
|
||||
text = AI_AUTO_GENERATED_FIELDS_DEFAULT.join(','),
|
||||
): AiAutoGeneratedField[] => {
|
||||
const textFormatted = text.trim().toLocaleLowerCase();
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import { parseAiAutoGeneratedFieldsText } from '@/photo/ai';
|
||||
import {
|
||||
AI_AUTO_GENERATED_FIELDS_DEFAULT,
|
||||
parseAiAutoGeneratedFieldsString,
|
||||
} from '@/photo/ai';
|
||||
import type { StorageType } from '@/services/storage';
|
||||
import { makeUrlAbsolute, shortenUrl } from '@/utility/url';
|
||||
|
||||
@ -142,7 +145,7 @@ export const CURRENT_STORAGE: StorageType =
|
||||
|
||||
export const AI_TEXT_GENERATION_ENABLED =
|
||||
Boolean(process.env.OPENAI_SECRET_KEY);
|
||||
export const AI_TEXT_AUTO_GENERATED_FIELDS = parseAiAutoGeneratedFieldsText(
|
||||
export const AI_TEXT_AUTO_GENERATED_FIELDS = parseAiAutoGeneratedFieldsString(
|
||||
process.env.AI_TEXT_AUTO_GENERATED_FIELDS);
|
||||
|
||||
// PERFORMANCE
|
||||
@ -265,7 +268,7 @@ export const CONFIG_CHECKLIST_STATUS = {
|
||||
? AI_TEXT_AUTO_GENERATED_FIELDS.length === 0
|
||||
? ['none']
|
||||
: AI_TEXT_AUTO_GENERATED_FIELDS
|
||||
: ['all'],
|
||||
: AI_AUTO_GENERATED_FIELDS_DEFAULT,
|
||||
hasAiTextAutoGeneratedFields:
|
||||
Boolean(process.env.AI_TEXT_AUTO_GENERATED_FIELDS),
|
||||
// Performance
|
||||
|
||||
Loading…
Reference in New Issue
Block a user