From e1e8f5cef07c63ebaff238cd89365d794094672e Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 17 Jun 2025 09:42:17 -0500 Subject: [PATCH] Make caption generation title aware --- src/photo/actions.ts | 5 ++++- src/photo/ai/server.ts | 3 ++- src/photo/ai/useAiImageQuery.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/photo/actions.ts b/src/photo/actions.ts index 38a0ccf7..f515303a 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -159,6 +159,7 @@ export const addUploadsAction = async ({ ? AI_TEXT_AUTO_GENERATED_FIELDS .filter(field => field !== 'title') : AI_TEXT_AUTO_GENERATED_FIELDS, + title, ); const form: Partial = { @@ -435,6 +436,7 @@ export const syncPhotoAction = async (photoId: string, isBatch?: boolean) => } = await generateAiImageQueries( imageResizedBase64, photo.syncStatus.missingAiTextFields, + undefined, isBatch, ); @@ -483,12 +485,13 @@ export const clearCacheAction = async () => export const streamAiImageQueryAction = async ( imageBase64: string, query: AiImageQuery, + existingTitle?: string, ) => runAuthenticatedAdminServerAction(async () => { const existingTags = await getUniqueTags(); return streamOpenAiImageQuery( imageBase64, - getAiImageQuery(query, existingTags), + getAiImageQuery(query, existingTags, existingTitle), ); }); diff --git a/src/photo/ai/server.ts b/src/photo/ai/server.ts index d053a355..c26cfbde 100644 --- a/src/photo/ai/server.ts +++ b/src/photo/ai/server.ts @@ -9,6 +9,7 @@ import { getUniqueTags } from '../db/query'; export const generateAiImageQueries = async ( imageBase64?: string, textFieldsToGenerate: AiAutoGeneratedField[] = [], + existingTitle?: string, isBatch?: boolean, ): Promise<{ title?: string @@ -43,7 +44,7 @@ export const generateAiImageQueries = async ( if (textFieldsToGenerate.includes('title')) { title = await generateOpenAiImageQuery( imageBase64, - getAiImageQuery('title'), + getAiImageQuery('title', undefined, existingTitle), isBatch, ); } diff --git a/src/photo/ai/useAiImageQuery.ts b/src/photo/ai/useAiImageQuery.ts index 311d20dc..0bf635ce 100644 --- a/src/photo/ai/useAiImageQuery.ts +++ b/src/photo/ai/useAiImageQuery.ts @@ -6,6 +6,7 @@ import { AiImageQuery } from '.'; export default function useAiImageQuery( imageBase64: string | undefined, query: AiImageQuery, + existingTitle?: string, ) { const [text, setText] = useState(''); const [error, setError] = useState(); @@ -19,6 +20,7 @@ export default function useAiImageQuery( const textStream = await streamAiImageQueryAction( imageBase64, query, + existingTitle, ); for await (const text of readStreamableValue(textStream)) { setText(current => `${current}${text ?? ''}`); @@ -29,7 +31,7 @@ export default function useAiImageQuery( setIsLoading(false); } } - }, [imageBase64, query]); + }, [imageBase64, query, existingTitle]); const reset = useCallback(() => { setText('');