Skip to content

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

fix ai chat issues

sytolk1b0f262e5e1c
diff --git a/src/renderer/components/chat/AiGenTagsButton.tsx b/src/renderer/components/chat/AiGenTagsButton.tsx
index 4bb4d2ed9..e0cccb650 100644
--- a/src/renderer/components/chat/AiGenTagsButton.tsx
+++ b/src/renderer/components/chat/AiGenTagsButton.tsx
@@ -21,7 +21,11 @@ import TsButton, { TSButtonProps } from '-/components/TsButton';
import { AIProvider } from '-/components/chat/ChatTypes';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useChatContext } from '-/hooks/useChatContext';
-import { actions as SettingsActions } from '-/reducers/settings';
+import {
+ actions as SettingsActions,
+ getTagColor,
+ getTagTextColor,
+} from '-/reducers/settings';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useTaggingActionsContext } from '-/hooks/useTaggingActionsContext';
@@ -35,6 +39,7 @@ import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { AIIcon } from '../CommonIcons';
import { AppDispatch } from '-/reducers/app';
+import { getTagColors } from '-/services/taglibrary-utils';
type Props = TSButtonProps & {
variant?: OverridableStringUnion<
@@ -50,6 +55,8 @@ function AiGenTagsButton(props: Props) {
const dispatch: AppDispatch = useDispatch();
const { openedEntry } = useOpenedEntryContext();
const defaultAiProvider: AIProvider = useSelector(getDefaultAIProvider);
+ const defaultBackgroundColor = useSelector(getTagColor);
+ const defaultTextColor = useSelector(getTagTextColor);
const { generate, openedEntryModel, newChatMessage } = useChatContext();
const { addTagsToFsEntry } = useTaggingActionsContext();
const { showNotification } = useNotificationContext();
@@ -75,10 +82,13 @@ function AiGenTagsButton(props: Props) {
if (response) {
try {
const regex = /\{([^}]+)\}/g;
- const tags: TS.Tag[] = [...response.matchAll(regex)].map((match) => ({
- title: match[1].trim().replace(/^,|,$/g, '').toLowerCase(),
- type: 'sidecar',
- }));
+ const tags: TS.Tag[] = [...response.matchAll(regex)].map((match) => {
+ const tagTitle = match[1].trim().replace(/^,|,$/g, '').toLowerCase();
+ return {
+ title: tagTitle,
+ ...getTagColors(tagTitle, defaultTextColor, defaultBackgroundColor),
+ };
+ });
addTagsToFsEntry(openedEntry, tags).then(() =>
dispatch(
SettingsActions.setEntryContainerTab(TabNames.propertiesTab),
@@ -119,7 +129,7 @@ function AiGenTagsButton(props: Props) {
handleGenerationResults(results),
);
} else if (AppConfig.aiSupportedFiletypes.text.includes(ext)) {
- generate(ext === 'pdf' ? 'image' : 'text', 'tags').then((results) =>
+ generate('text', 'tags').then((results) =>
handleGenerationResults(results),
);
}
diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsx
index 4650ea078..6fb0d7a5b 100644
--- a/src/renderer/hooks/ChatProvider.tsx
+++ b/src/renderer/hooks/ChatProvider.tsx
@@ -166,7 +166,7 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
useEffect(() => {
if (AppConfig.isElectron) {
- refreshOllamaModels();
+ //refreshOllamaModels();
window.electronIO.ipcRenderer.on(
'PullModel',
(message: PullModelResponse) => {
@@ -303,7 +303,8 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
const model = findModel(modelName);
if (model) {
return setModel(model);
- } else if (currentModel.current === undefined) {
+ } else {
+ //if (currentModel.current === undefined) {
//set defaultTextModel if not found
return setModel(defaultAiProvider.defaultTextModel);
}
@@ -721,7 +722,9 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
return currentLocation
.getFileContentPromise(
openedEntry.path,
- fileContent === 'text' ? 'text' : 'arraybuffer',
+ fileContent === 'text' && !openedEntry.path.endsWith('.pdf')
+ ? 'text'
+ : 'arraybuffer',
)
.then((content) => getFileContent(content))
.then((content) =>
diff --git a/src/renderer/services/taglibrary-utils.ts b/src/renderer/services/taglibrary-utils.ts
index 05c96319a..a5e53c437 100644
--- a/src/renderer/services/taglibrary-utils.ts
+++ b/src/renderer/services/taglibrary-utils.ts
@@ -88,15 +88,14 @@ export const getTagColors = (
defaultTextColor: string,
defaultBackgroundColor: string,
) => {
- const tagColors = {
- textcolor: defaultTextColor,
- color: defaultBackgroundColor,
- };
- getAllTags().forEach((tag: TS.Tag) => {
- if (tag.title === tagTitle) {
- tagColors.textcolor = tag.textcolor;
- tagColors.color = tag.color;
- }
- });
- return tagColors;
+ const tagExist = getAllTags().find((tag: TS.Tag) => tag.title === tagTitle);
+ return tagExist
+ ? {
+ textcolor: tagExist.textcolor || defaultTextColor,
+ color: tagExist.color || defaultBackgroundColor,
+ }
+ : {
+ textcolor: defaultTextColor,
+ color: defaultBackgroundColor,
+ };
};