Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Make-ai-tasks-queries-configurable (#2359)

Stanimira019cfa92292
diff --git a/package-lock.json b/package-lock.json
index c76a21abf..c9c1ed84d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -208,7 +208,7 @@
"yarn": "please-use-npm"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.179"
+ "@tagspacespro/tagspacespro": "5.0.180"
}
},
"node_modules/@adobe/css-tools": {
@@ -19352,9 +19352,9 @@
}
},
"node_modules/@tagspacespro/tagspacespro": {
- "version": "5.0.179",
- "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.179/7c0cb8c3f4719d01d89143666d83def50286a636",
- "integrity": "sha512-ndvn+OZK8S0CpuLJzZIZCd55NAnpq3SRB7kAkqHocXkXgP5WqQElLw4gPJgxg47JCAIMtaRC1BiK3qLz7aOzvA==",
+ "version": "5.0.180",
+ "resolved": "https://npm.pkg.github.com/download/@tagspacespro/tagspacespro/5.0.180/edafe287b08c6b1a6ad838bdc0ad9bda875ddfbf",
+ "integrity": "sha512-tLrgSpahLtxcJERO+AOPn12Yt1/g5PEAlf6SdrkMHhP76XDmI9jdUEeot8Vie6lQT7j+C74KxgAzBtsxObzLrQ==",
"license": "Proprietary",
"optional": true
},
diff --git a/package.json b/package.json
index 872da1522..8f53a1b63 100644
--- a/package.json
+++ b/package.json
@@ -246,7 +246,7 @@
"zod-to-json-schema": "^3.24.1"
},
"optionalDependencies": {
- "@tagspacespro/tagspacespro": "5.0.179"
+ "@tagspacespro/tagspacespro": "5.0.180"
},
"devDependencies": {
"@electron/notarize": "^2.5.0",
diff --git a/src/renderer/components/dialogs/components/SettingsAI.tsx b/src/renderer/components/dialogs/components/SettingsAI.tsx
index 1436240b8..b3b54f412 100644
--- a/src/renderer/components/dialogs/components/SettingsAI.tsx
+++ b/src/renderer/components/dialogs/components/SettingsAI.tsx
@@ -33,6 +33,7 @@ import { AIProvider, AIProviders } from '-/components/chat/ChatTypes';
import SelectChatModel from '-/components/chat/SelectChatModel';
import { OllamaIcon } from '-/components/dialogs/components/Ollama';
import { useChatContext } from '-/hooks/useChatContext';
+import { Pro } from '-/pro';
import { AppDispatch } from '-/reducers/app';
import {
actions as SettingsActions,
@@ -40,6 +41,7 @@ import {
getDefaultAIProvider,
} from '-/reducers/settings';
import { openURLExternally } from '-/services/utils-io';
+import { TS } from '-/tagspaces.namespace';
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord';
import {
Accordion,
@@ -62,7 +64,7 @@ import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import Typography from '@mui/material/Typography';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
-import React, { ChangeEvent, useEffect } from 'react';
+import React, { ChangeEvent, useContext, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
@@ -71,7 +73,7 @@ interface Props {
}
function SettingsAI(props: Props) {
- const { i18n, t } = useTranslation();
+ const { t } = useTranslation();
const { closeSettings } = props;
const { changeCurrentModel, checkProviderAlive } = useChatContext();
const aiDefaultProvider: AIProvider = useSelector(getDefaultAIProvider);
@@ -81,8 +83,15 @@ function SettingsAI(props: Props) {
const dispatch: AppDispatch = useDispatch();
const anchorRef = React.useRef<HTMLDivElement>(null);
const providersAlive = React.useRef({});
+ const aiTemplates = React.useRef({});
const [openedNewAIMenu, setOpenedNewAIMenu] = React.useState(false);
+ const aiTemplatesContext = Pro?.contextProviders?.AiTemplatesContext
+ ? useContext<TS.AiTemplatesContextData>(
+ Pro.contextProviders.AiTemplatesContext,
+ )
+ : undefined;
+
useEffect(() => {
checkOllamaAlive();
}, []);
@@ -155,6 +164,19 @@ function SettingsAI(props: Props) {
});
};
+ function saveTemplate(key: string) {
+ const template = aiTemplates.current[key];
+ if (template) {
+ aiTemplatesContext.setTemplate(key, template);
+ aiTemplates.current[key] = undefined;
+ }
+ }
+
+ function cancelSavingTemplate(key: string) {
+ aiTemplates.current[key] = undefined;
+ forceUpdate();
+ }
+
const externalConfig = typeof window.ExtAI !== 'undefined';
return (
@@ -466,6 +488,400 @@ function SettingsAI(props: Props) {
</AccordionDetails>
</Accordion>
))}
+ {Pro && aiTemplatesContext && (
+ <Accordion>
+ <AccordionSummary
+ expandIcon={<ExpandIcon />}
+ aria-controls={'AdvancedContent'}
+ data-tid={'AdvancedTID'}
+ sx={{
+ '& .MuiAccordionSummary-content': { alignItems: 'center' },
+ }}
+ >
+ <Typography>{'Advanced'}</Typography>
+ </AccordionSummary>
+ <AccordionDetails>
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={
+ !(typeof window.ExtDefaultQuestionPrompt === 'undefined')
+ }
+ label={t('defaultQuestionPrompt')}
+ value={
+ aiTemplates.current['DEFAULT_QUESTION_PROMPT'] ??
+ aiTemplatesContext.getTemplate('DEFAULT_QUESTION_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['DEFAULT_QUESTION_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current[
+ 'DEFAULT_QUESTION_PROMPT'
+ ] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ data-tid={'saveDefaultQuestionPromptTID'}
+ onClick={() => saveTemplate('DEFAULT_QUESTION_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ data-tid={'saveDefaultQuestionPromptTID'}
+ onClick={() =>
+ cancelSavingTemplate('DEFAULT_QUESTION_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('defaultSystemPrompt')}
+ value={
+ aiTemplates.current['DEFAULT_SYSTEM_PROMPT'] ??
+ aiTemplatesContext.getTemplate('DEFAULT_SYSTEM_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['DEFAULT_SYSTEM_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current[
+ 'DEFAULT_SYSTEM_PROMPT'
+ ] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('DEFAULT_SYSTEM_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ cancelSavingTemplate('DEFAULT_SYSTEM_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('summarizePrompt')}
+ value={
+ aiTemplates.current['SUMMARIZE_PROMPT'] ??
+ aiTemplatesContext.getTemplate('SUMMARIZE_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['SUMMARIZE_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current['SUMMARIZE_PROMPT'] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('SUMMARIZE_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() => cancelSavingTemplate('SUMMARIZE_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('imageDescription')}
+ value={
+ aiTemplates.current['IMAGE_DESCRIPTION_PROMPT'] ??
+ aiTemplatesContext.getTemplate('IMAGE_DESCRIPTION_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['IMAGE_DESCRIPTION_PROMPT'] =
+ e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current[
+ 'IMAGE_DESCRIPTION_PROMPT'
+ ] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('IMAGE_DESCRIPTION_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ cancelSavingTemplate('IMAGE_DESCRIPTION_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('imageDescriptionStructured')}
+ value={
+ aiTemplates.current['IMAGE_DESCRIPTION_STRUCTURED_PROMPT'] ??
+ aiTemplatesContext.getTemplate(
+ 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT',
+ )
+ }
+ onChange={(e) => {
+ aiTemplates.current['IMAGE_DESCRIPTION_STRUCTURED_PROMPT'] =
+ e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current[
+ 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT'
+ ] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ saveTemplate('IMAGE_DESCRIPTION_STRUCTURED_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ cancelSavingTemplate(
+ 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT',
+ )
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('textDescription')}
+ value={
+ aiTemplates.current['TEXT_DESCRIPTION_PROMPT'] ??
+ aiTemplatesContext.getTemplate('TEXT_DESCRIPTION_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['TEXT_DESCRIPTION_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current[
+ 'TEXT_DESCRIPTION_PROMPT'
+ ] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('TEXT_DESCRIPTION_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ cancelSavingTemplate('TEXT_DESCRIPTION_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('generateImageTags')}
+ value={
+ aiTemplates.current['IMAGE_TAGS_PROMPT'] ??
+ aiTemplatesContext.getTemplate('IMAGE_TAGS_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['IMAGE_TAGS_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current['IMAGE_TAGS_PROMPT'] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('IMAGE_TAGS_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() =>
+ cancelSavingTemplate('IMAGE_TAGS_PROMPT')
+ }
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ <TsTextField
+ fullWidth
+ multiline
+ rows={5}
+ disabled={!(typeof window.ExtDefaultSystemPrompt === 'undefined')}
+ label={t('generateTags')}
+ value={
+ aiTemplates.current['TEXT_TAGS_PROMPT'] ??
+ aiTemplatesContext.getTemplate('TEXT_TAGS_PROMPT')
+ }
+ onChange={(e) => {
+ aiTemplates.current['TEXT_TAGS_PROMPT'] = e.target.value;
+ forceUpdate();
+ }}
+ slotProps={{
+ input: {
+ endAdornment: aiTemplates.current['TEXT_TAGS_PROMPT'] && (
+ <InputAdornment position="end">
+ <TsButton
+ variant="contained"
+ onClick={() => saveTemplate('TEXT_TAGS_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:save')}
+ </TsButton>
+ <TsButton
+ variant="contained"
+ onClick={() => cancelSavingTemplate('TEXT_TAGS_PROMPT')}
+ style={{
+ // @ts-ignore
+ WebkitAppRegion: 'no-drag',
+ }}
+ >
+ {t('core:cancel')}
+ </TsButton>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ </AccordionDetails>
+ </Accordion>
+ )}
</div>
);
}
diff --git a/src/renderer/containers/Root.tsx b/src/renderer/containers/Root.tsx
index cea57f595..ffd531bcd 100644
--- a/src/renderer/containers/Root.tsx
+++ b/src/renderer/containers/Root.tsx
@@ -102,27 +102,31 @@ export default function Root({ store, persistor }: RootType) {
<BrowserHistoryContextProvider>
<FileUploadContextProvider>
<FileUploadDialogContextProvider>
- <ChatContextProvider>
- <HistoryContextProvider>
- {Pro ? (
- <Pro.contextProviders.BookmarksContextProvider>
- <Pro.contextProviders.KanBanImportDialogContextProvider>
- <Pro.contextProviders.ThumbDialogContextProvider>
- <Pro.contextProviders.BgndDialogContextProvider>
- <DialogsRoot>
- <MainPage />
- </DialogsRoot>
- </Pro.contextProviders.BgndDialogContextProvider>
- </Pro.contextProviders.ThumbDialogContextProvider>
- </Pro.contextProviders.KanBanImportDialogContextProvider>
- </Pro.contextProviders.BookmarksContextProvider>
- ) : (
+ <HistoryContextProvider>
+ {Pro ? (
+ <Pro.contextProviders.BookmarksContextProvider>
+ <Pro.contextProviders.KanBanImportDialogContextProvider>
+ <Pro.contextProviders.ThumbDialogContextProvider>
+ <Pro.contextProviders.BgndDialogContextProvider>
+ <Pro.contextProviders.AiTemplatesContextProvider>
+ <ChatContextProvider>
+ <DialogsRoot>
+ <MainPage />
+ </DialogsRoot>
+ </ChatContextProvider>
+ </Pro.contextProviders.AiTemplatesContextProvider>
+ </Pro.contextProviders.BgndDialogContextProvider>
+ </Pro.contextProviders.ThumbDialogContextProvider>
+ </Pro.contextProviders.KanBanImportDialogContextProvider>
+ </Pro.contextProviders.BookmarksContextProvider>
+ ) : (
+ <ChatContextProvider>
<DialogsRoot>
<MainPage />
</DialogsRoot>
- )}
- </HistoryContextProvider>
- </ChatContextProvider>
+ </ChatContextProvider>
+ )}
+ </HistoryContextProvider>
</FileUploadDialogContextProvider>
</FileUploadContextProvider>
</BrowserHistoryContextProvider>
diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsx
index e710747ac..acfbdffcc 100644
--- a/src/renderer/hooks/ChatProvider.tsx
+++ b/src/renderer/hooks/ChatProvider.tsx
@@ -36,6 +36,7 @@ import { generateOptionType } from '-/components/dialogs/hooks/AiGenerationDialo
import { useFileUploadDialogContext } from '-/components/dialogs/hooks/useFileUploadDialogContext';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
import { useIOActionsContext } from '-/hooks/useIOActionsContext';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
@@ -60,6 +61,7 @@ import {
getZodTags,
} from '-/services/zodObjects';
import { TS } from '-/tagspaces.namespace';
+import useFirstRender from '-/utils/useFirstRender';
import { formatDateTime } from '@tagspaces/tagspaces-common/misc';
import {
extractFileExtension,
@@ -74,6 +76,7 @@ import { format } from 'date-fns';
import { ChatRequest, ModelResponse, Ollama } from 'ollama';
import React, {
createContext,
+ useContext,
useEffect,
useMemo,
useReducer,
@@ -82,8 +85,6 @@ import React, {
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { zodToJsonSchema } from 'zod-to-json-schema';
-import useFirstRender from '-/utils/useFirstRender';
-import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';
/*export type TimelineItem = {
request: string;
@@ -226,26 +227,11 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
//const defaultAiProviderId: string = useSelector(getDefaultAIProviderId);
//const aiProviders: AIProvider[] = useSelector(getAIProviders);getDefaultAIProvider(defaultAiProviderId,aiProviders);
const chatHistoryItems = useRef<ChatItem[]>([]);
- const DEFAULT_QUESTION_PROMPT =
- window.ExtDefaultQuestionPrompt ??
- Pro?.UI?.DEFAULT_QUESTION_PROMPT ??
- false;
- const DEFAULT_SYSTEM_PROMPT =
- window.ExtDefaultSystemPrompt ?? Pro?.UI?.DEFAULT_SYSTEM_PROMPT ?? false;
- const SUMMARIZE_PROMPT =
- window.ExtSummarizePrompt ?? Pro?.UI?.SUMMARIZE_PROMPT ?? false;
- const IMAGE_DESCRIPTION =
- window.ExtImageDescription ?? Pro?.UI?.IMAGE_DESCRIPTION ?? false;
- const IMAGE_DESCRIPTION_STRUCTURED =
- window.ExtImageDescriptionStructured ??
- Pro?.UI?.IMAGE_DESCRIPTION_STRUCTURED ??
- false;
- const TEXT_DESCRIPTION =
- window.ExtTextDescription ?? Pro?.UI?.TEXT_DESCRIPTION ?? false;
- const GENERATE_TAGS =
- window.ExtGenerateTags ?? Pro?.UI?.GENERATE_TAGS ?? false;
- const GENERATE_IMAGE_TAGS =
- window.ExtGenerateImageTags ?? Pro?.UI?.GENERATE_IMAGE_TAGS ?? false;
+ const aiTemplatesContext = Pro?.contextProviders?.AiTemplatesContext
+ ? useContext<TS.AiTemplatesContextData>(
+ Pro.contextProviders.AiTemplatesContext,
+ )
+ : undefined;
const isTyping = useRef<boolean>(false);
//const timelineItems = useRef<TimelineItem[]>([]);
const ollamaClient = useRef<Ollama>(undefined);
@@ -799,12 +785,16 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
function getMessage(msg: string, mode: ChatMode) {
if (mode === 'helpful') {
- if (DEFAULT_SYSTEM_PROMPT) {
- return DEFAULT_SYSTEM_PROMPT.replace('{question}', msg);
+ if (aiTemplatesContext) {
+ return aiTemplatesContext
+ .getTemplate('DEFAULT_SYSTEM_PROMPT')
+ .replace('{question}', msg);
}
} else if (mode === 'summary') {
- if (SUMMARIZE_PROMPT) {
- let prompt = SUMMARIZE_PROMPT.replace('{summarize_text}', msg);
+ if (aiTemplatesContext) {
+ let prompt = aiTemplatesContext
+ .getTemplate('SUMMARIZE_PROMPT')
+ .replace('{summarize_text}', msg);
if (selectedEntries && selectedEntries.length > 0) {
prompt = prompt.replace(
'{file_path}',
@@ -835,55 +825,67 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
}
} else if (mode === 'description') {
if (msg) {
- return TEXT_DESCRIPTION?.replace('{input_text}', msg)
- .replace(
- '{max_chars}',
- generationSettings.current.maxChars
- ? 'max ' + generationSettings.current.maxChars + ' characters'
- : '',
- )
- .replace(
- '{language}',
- generationSettings.current.language
- ? generationSettings.current.language
- : 'native',
- );
+ if (aiTemplatesContext) {
+ return aiTemplatesContext
+ .getTemplate('TEXT_DESCRIPTION_PROMPT')
+ ?.replace('{input_text}', msg)
+ .replace(
+ '{max_chars}',
+ generationSettings.current.maxChars
+ ? 'max ' + generationSettings.current.maxChars + ' characters'
+ : '',
+ )
+ .replace(
+ '{language}',
+ generationSettings.current.language
+ ? generationSettings.current.language
+ : 'native',
+ );
+ }
} else {
- if (generationSettings.current.option === 'analyseImages') {
- return IMAGE_DESCRIPTION_STRUCTURED;
+ if (aiTemplatesContext) {
+ if (generationSettings.current.option === 'analyseImages') {
+ return aiTemplatesContext.getTemplate(
+ 'IMAGE_DESCRIPTION_STRUCTURED_PROMPT',
+ );
+ }
+ return aiTemplatesContext
+ .getTemplate('IMAGE_DESCRIPTION_PROMPT')
+ ?.replace('{file_name}', openedEntry ? openedEntry.name : '')
+ .replace(
+ '{language}',
+ generationSettings.current.language
+ ? generationSettings.current.language
+ : 'English',
+ );
}
- return IMAGE_DESCRIPTION?.replace(
- '{file_name}',
- openedEntry ? openedEntry.name : '',
- ).replace(
- '{language}',
- generationSettings.current.language
- ? generationSettings.current.language
- : 'English',
- );
}
} else if (mode === 'tags') {
- if (msg) {
- if (GENERATE_TAGS && openedEntry) {
- return GENERATE_TAGS.replace('{input_text}', msg);
- }
- } else {
- // image
- if (GENERATE_IMAGE_TAGS && openedEntry) {
- return GENERATE_IMAGE_TAGS;
+ if (aiTemplatesContext) {
+ if (msg) {
+ if (openedEntry) {
+ return aiTemplatesContext
+ .getTemplate('TEXT_TAGS_PROMPT')
+ ?.replace('{input_text}', msg);
+ }
+ } else {
+ // image
+ if (openedEntry) {
+ return aiTemplatesContext.getTemplate('IMAGE_TAGS_PROMPT');
+ }
}
}
} else if (mode === 'rephrase') {
- if (DEFAULT_QUESTION_PROMPT) {
+ if (aiTemplatesContext) {
const historyMap = chatHistoryItems.current.map((item) =>
item.role !== 'system'
? `${item.request ? 'Human: ' + item.request : ''}${item.response ? ' Assistant: ' + item.response : ''}`
: '',
);
- return DEFAULT_QUESTION_PROMPT.replace('{question}', msg).replace(
- '{chat_history}',
- historyMap.join(' '),
- );
+ return aiTemplatesContext
+ .getTemplate('DEFAULT_QUESTION_PROMPT')
+ .replace('{question}', msg)
+ .replace('{chat_history}', historyMap.join(' '));
}
}
return msg;
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index b38b206e3..dba83b560 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -979,5 +979,12 @@
"noModelsLoaded": "Error: No AI-models are loaded, please check if the AI-service is running.",
"fileModified": "File was modified, do you want to save the changes?",
"indexDisabledConfirm": "Indexing is currently disabled for this location.\nWould you like to force a reindex?",
+ "defaultQuestionPrompt": "Default Question Prompt",
+ "defaultSystemPrompt": "Default System Prompt",
+ "summarizePrompt": "Summarize Prompt",
+ "imageDescription": "Image Description",
+ "imageDescriptionStructured": "Image Description Structured",
+ "textDescription": "Text Description",
+ "generateImageTags": "Generate Image Tags",
"-": "-"
}
diff --git a/src/renderer/tagspaces.d.ts b/src/renderer/tagspaces.d.ts
index a7a3f65e4..dac0bffe9 100644
--- a/src/renderer/tagspaces.d.ts
+++ b/src/renderer/tagspaces.d.ts
@@ -81,11 +81,11 @@ declare interface Window {
ExtDefaultQuestionPrompt?: string;
ExtDefaultSystemPrompt?: string;
ExtSummarizePrompt?: string;
- ExtImageDescription?: string;
- ExtImageDescriptionStructured?: string;
- ExtTextDescription?: string;
- ExtGenerateTags?: string;
- ExtGenerateImageTags?: string;
+ ExtDescriptionFromTextPrompt?: string;
+ ExtDescriptionFromImageStructuredPrompt?: string;
+ ExtDescriptionFromImagePrompt?: string;
+ ExtTagsFromTextPrompt?: string;
+ ExtTagsFromImagePrompt?: string;
}
declare interface NodeModule {
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 829d6938d..4e54487ac 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -319,6 +319,11 @@ export namespace TS {
closeBgndDialog: () => void;
};
+ type AiTemplatesContextData = {
+ getTemplate: (key: string) => string;
+ setTemplate: (key: string, value: string) => void;
+ };
+
interface EditedEntryPath {
action: EditedEntryAction;
path: string;