diff --git a/src/photo/ai/index.ts b/src/photo/ai/index.ts index bd55576c..b073850c 100644 --- a/src/photo/ai/index.ts +++ b/src/photo/ai/index.ts @@ -80,6 +80,37 @@ export const getAiImageQuery = ( } }; +const getAiImageQueryForField = ( + field: AiAutoGeneratedField, + existingTags: Tags = [], + existingTitle?: string, +) => { + switch(field) { + case 'title': return `TITLE: ${getAiImageQuery('title', existingTags, existingTitle)}`; + case 'caption': return `CAPTION: ${getAiImageQuery('caption', existingTags, existingTitle)}`; + case 'tags': return `TAGS: ${getAiImageQuery('tags', existingTags, existingTitle)}`; + case 'semantic': return `SEMANTIC: ${getAiImageQuery('description-small', existingTags, existingTitle)}`; + } +}; + +export const getAiImageryQuerySet = ( + fields: AiAutoGeneratedField[], + existingTags: Tags = [], + existingTitle?: string, +) => { + const query = ['Generate a suite of structured meta content for the attached image:' + '\n']; + + fields.forEach(field => { + query.push(getAiImageQueryForField(field, existingTags, existingTitle)); + }); + + query.push(`\nRespond with a valid JSON object with the following format: { ${fields.map(field => `${field}: 'string'`).join(', ')} }`); + + console.log(query.join('\n')); + + return query.join('\n'); +}; + export const parseTitleAndCaption = (text: string) => { const matches = text.includes('Title') ? text.match(/^[`'"]*Title: ["']*(.*?)["']*[ ]*Caption: ["']*(.*?)\.*["']*[`'"]*$/) diff --git a/src/photo/color/server.ts b/src/photo/color/server.ts index 24bf6f65..126a8152 100644 --- a/src/photo/color/server.ts +++ b/src/photo/color/server.ts @@ -119,7 +119,7 @@ export const getColorFieldsForPhotoForm = async ( export const getColorFromAI = async ( _url: string, - useBatch?: boolean, + isBatch?: boolean, ) => { const url = getOptimizedPhotoUrlForManipulation(_url, IS_PREVIEW); const image = await getImageBase64FromUrl(url); @@ -128,7 +128,7 @@ export const getColorFromAI = async ( If yes, what is the approximate hex color of the subject. If not, what is the approximate hex color of the background? Respond only with a hex color value: - `, useBatch); + `, isBatch); const hex = hexColor?.match(/#*([a-f0-9]{6})/i)?.[1]; if (hex) { return convertHexToOklch(`#${hex}`);