From b2801b018e5196ea91cdb20076a883af0c4e3afa Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 16:45:38 +0100 Subject: [PATCH 01/21] feat(settings): warn modal on using third parties --- .../Chat/QuickSettingsDrawer.svelte | 18 ++++++- src/components/Onboarding/InitButton.svelte | 20 +++++++- src/components/Settings/ConfirmModal.svelte | 33 +++++++++++++ src/components/Settings/ConfirmModal.ts | 48 ++++++++++--------- .../Settings/IncognitoToggle.svelte | 2 + src/main.ts | 32 ++++++++----- src/store.ts | 21 +++++++- 7 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 src/components/Settings/ConfirmModal.svelte diff --git a/src/components/Chat/QuickSettingsDrawer.svelte b/src/components/Chat/QuickSettingsDrawer.svelte index ac834ee..10383f8 100644 --- a/src/components/Chat/QuickSettingsDrawer.svelte +++ b/src/components/Chat/QuickSettingsDrawer.svelte @@ -8,6 +8,8 @@ import Toggle from '../base/Toggle.svelte'; import PullOllamaModel from '../Onboarding/PullOllamaModel.svelte'; import LoadingAnimation from '../base/LoadingAnimation.svelte'; + import { ConfirmModal } from '../Settings/ConfirmModal'; + import { get } from 'svelte/store'; const icon = (node: HTMLElement, iconId: string) => { setIcon(node, iconId); @@ -63,6 +65,20 @@ $data.isChatComfy = !$data.isChatComfy; $plugin.saveSettings(); } + + function initSecondBrain() { + $data.isIncognitoMode + ? $plugin.s2b.init() + : new ConfirmModal( + get(plugin).app, + 'Run via Third-Parties', + 'Are you sure you want to run via third-parties? Your data will be given to third-party servers.', + (result) => { + if (result === 'Yes') $plugin.s2b.init(); + }, + 'hideIncognitoWarning' + ).activate(); + }
Reinitialize Smart Second Brain
with {$data.isIncognitoMode ? 'Ollama' : 'OpenAI'}. + diff --git a/src/components/Settings/ConfirmModal.svelte b/src/components/Settings/ConfirmModal.svelte new file mode 100644 index 0000000..4243c1e --- /dev/null +++ b/src/components/Settings/ConfirmModal.svelte @@ -0,0 +1,33 @@ + + + + + diff --git a/src/components/Settings/ConfirmModal.ts b/src/components/Settings/ConfirmModal.ts index 678afe2..9d86ddf 100644 --- a/src/components/Settings/ConfirmModal.ts +++ b/src/components/Settings/ConfirmModal.ts @@ -1,36 +1,40 @@ -import { App, ButtonComponent, Modal } from 'obsidian'; +import { App, Modal } from 'obsidian'; +import ConfirmComponent from './ConfirmModal.svelte'; +import { get } from 'svelte/store'; +import { data } from '../../store'; +import type { PluginDataKey } from '../../main'; export class ConfirmModal extends Modal { result: string; + title: string; + content: string; + hideModalOption: PluginDataKey | ''; + component: ConfirmComponent; onSubmit: (result: string) => void; - constructor(app: App, onSubmit: (result: string) => void) { + constructor(app: App, title: string, content: string, onSubmit: (result: string) => void, hideModalOption: PluginDataKey | '' = '') { super(app); + this.title = title; + this.content = content; this.onSubmit = onSubmit; + this.hideModalOption = hideModalOption; + } + + activate() { + if (this.hideModalOption !== '' && get(data)[this.hideModalOption]) { + this.onSubmit('Yes'); + return; + } + this.open(); } onOpen() { this.modalEl.parentElement.addClass('mod-confirmation'); - - this.setTitle('Clear Plugin Data'); - - this.setContent( - 'Are you sure you want to delete the plugin data? Note that only the plugin data and the vector store data will be removed. All chat files inside your vault will not be affected.' - ); - - const test = this.modalEl.createDiv({ cls: 'modal-button-container' }); - - new ButtonComponent(test) - .setButtonText('Yes') - .setWarning() - .onClick(() => { - this.close(); - this.onSubmit('Yes'); - }); - - new ButtonComponent(test).setButtonText('No').onClick(() => { - this.close(); - this.onSubmit('No'); + this.component = new ConfirmComponent({ + target: this.contentEl, + props: { + modal: this, + }, }); } diff --git a/src/components/Settings/IncognitoToggle.svelte b/src/components/Settings/IncognitoToggle.svelte index 652a3c1..ab604e5 100644 --- a/src/components/Settings/IncognitoToggle.svelte +++ b/src/components/Settings/IncognitoToggle.svelte @@ -2,6 +2,8 @@ import { Notice } from 'obsidian'; import { plugin, data, papaState, type PapaState } from '../../store'; import { crossfade } from 'svelte/transition'; + import { ConfirmModal } from './ConfirmModal'; + import { get } from 'svelte/store'; const [send, recieve] = crossfade({ duration: 500 }); diff --git a/src/main.ts b/src/main.ts index 4a43438..2a338e1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,8 +31,11 @@ export interface PluginData { isQuickSettingsOpen: boolean; isVerbose: boolean; isOnboarded: boolean; + hideIncognitoWarning: boolean; } +export type PluginDataKey = keyof PluginData; + export const DEFAULT_SETTINGS: Partial = { isChatComfy: true, isUsingRag: true, @@ -63,6 +66,7 @@ export const DEFAULT_SETTINGS: Partial = { isQuickSettingsOpen: true, isVerbose: false, isOnboarded: false, + hideIncognitoWarning: false, }; export default class SecondBrainPlugin extends Plugin { @@ -204,18 +208,24 @@ export default class SecondBrainPlugin extends Plugin { } async clearPluginData() { - new ConfirmModal(get(plugin).app, async (result) => { - if (result === 'Yes') { - await this.saveData({}); - const files = (await this.app.vault.adapter.list(normalizePath(this.manifest.dir))).files; - for (const file of files) { - if (file.endsWith('vector-store.bin')) await this.app.vault.adapter.remove(file); + new ConfirmModal( + get(plugin).app, + 'Clear Plugin Data', + 'Are you sure you want to delete the plugin data? Note that only the plugin data and the vector store data will be removed. All chat files inside your vault will not be affected.', + async (result) => { + if (result === 'Yes') { + await this.saveData({}); + const files = (await this.app.vault.adapter.list(normalizePath(this.manifest.dir))).files; + for (const file of files) { + if (file.endsWith('vector-store.bin')) await this.app.vault.adapter.remove(file); + } + new Notice('Plugin data cleared. Please reload the plugin.', 4000); + } else { + new Notice('Plugin data not cleared.', 4000); } - new Notice('Plugin data cleared. Please reload the plugin.', 4000); - } else { - new Notice('Plugin data not cleared.', 4000); - } - }).open(); + }, + '' + ).activate(); } registerMonkeyPatches() { diff --git a/src/store.ts b/src/store.ts index f0f3bfd..6605521 100644 --- a/src/store.ts +++ b/src/store.ts @@ -10,7 +10,6 @@ export type ChatMessage = { id: string; }; export const plugin = writable(); -export const data = writable(); export const isEditing = writable(false); export const isEditingAssistantMessage = writable(); @@ -58,3 +57,23 @@ function createChatHistory() { } export const chatHistory = createChatHistory(); + +function createData() { + const { subscribe, set, update } = writable(); + + return { + subscribe, + set, + update, + warningOff: (value) => { + update((d) => { + d[value] = true; + console.log('d', d.hideIncognitoWarning); + return d; + }); + get(plugin).saveSettings(); + }, + }; +} + +export const data = createData(); From 25447dbb5ac313db71cc58858c958013892c39bd Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 16:48:16 +0100 Subject: [PATCH 02/21] fix(OpenAI onboarding): API key input updated immediately --- src/components/Onboarding/OpenAI.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Onboarding/OpenAI.svelte b/src/components/Onboarding/OpenAI.svelte index 53574a8..1b46ebe 100644 --- a/src/components/Onboarding/OpenAI.svelte +++ b/src/components/Onboarding/OpenAI.svelte @@ -54,7 +54,7 @@ Date: Mon, 11 Mar 2024 18:14:31 +0100 Subject: [PATCH 03/21] feat(workflows): check for logs --- .github/workflows/console-logs.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/console-logs.yml diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml new file mode 100644 index 0000000..c4ff547 --- /dev/null +++ b/.github/workflows/console-logs.yml @@ -0,0 +1,23 @@ +name: Check Console Logs + +on: + pull_request: + branches: + - main + +jobs: + check-logs: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Check for console.log statements + run: | + if grep -rnw 'src/' -e 'console.log'; then + echo "console.log statement found!" + exit 1 + else + echo "No console.log statements found." + fi + From cebe8c397be898845df282b2e3ed1522c9c84bcc Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 18:17:54 +0100 Subject: [PATCH 04/21] Update console-logs.yml --- .github/workflows/console-logs.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml index c4ff547..6da3818 100644 --- a/.github/workflows/console-logs.yml +++ b/.github/workflows/console-logs.yml @@ -14,10 +14,15 @@ jobs: - name: Check for console.log statements run: | - if grep -rnw 'src/' -e 'console.log'; then - echo "console.log statement found!" + LOGS_FOUND=0 + while IFS= read -r line + do + echo "::error ::console.log found: $line" + LOGS_FOUND=1 + done < <(grep -rnw 'src/' -e 'console.log') + + if [ "$LOGS_FOUND" -ne "0" ]; then exit 1 else echo "No console.log statements found." fi - From 969a678afbfc7c7908d7a729df02b13f819aa30c Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 18:22:46 +0100 Subject: [PATCH 05/21] Update console-logs.yml --- .github/workflows/console-logs.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml index 6da3818..5422259 100644 --- a/.github/workflows/console-logs.yml +++ b/.github/workflows/console-logs.yml @@ -14,15 +14,8 @@ jobs: - name: Check for console.log statements run: | - LOGS_FOUND=0 - while IFS= read -r line - do - echo "::error ::console.log found: $line" - LOGS_FOUND=1 - done < <(grep -rnw 'src/' -e 'console.log') + grep -rnw 'src/' -e 'console.log' | while read line; do + echo "::warning file=${line%%:*},line=${line#*:},col=1::Found console.log" + done - if [ "$LOGS_FOUND" -ne "0" ]; then - exit 1 - else - echo "No console.log statements found." - fi + # The job will complete successfully, but with warnings if console.log statements are found. From 3274be7a9a990551a22d2321a36b5ba9b248dae5 Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 18:27:09 +0100 Subject: [PATCH 06/21] Update console-logs.yml --- .github/workflows/console-logs.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml index 5422259..6da3818 100644 --- a/.github/workflows/console-logs.yml +++ b/.github/workflows/console-logs.yml @@ -14,8 +14,15 @@ jobs: - name: Check for console.log statements run: | - grep -rnw 'src/' -e 'console.log' | while read line; do - echo "::warning file=${line%%:*},line=${line#*:},col=1::Found console.log" - done + LOGS_FOUND=0 + while IFS= read -r line + do + echo "::error ::console.log found: $line" + LOGS_FOUND=1 + done < <(grep -rnw 'src/' -e 'console.log') - # The job will complete successfully, but with warnings if console.log statements are found. + if [ "$LOGS_FOUND" -ne "0" ]; then + exit 1 + else + echo "No console.log statements found." + fi From 82594b84b42de0b9fb3b32351741b34f3845222b Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 18:56:04 +0100 Subject: [PATCH 07/21] Update console-logs.yml --- .github/workflows/console-logs.yml | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml index 6da3818..c79bdd3 100644 --- a/.github/workflows/console-logs.yml +++ b/.github/workflows/console-logs.yml @@ -12,17 +12,14 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Check for console.log statements - run: | - LOGS_FOUND=0 - while IFS= read -r line - do - echo "::error ::console.log found: $line" - LOGS_FOUND=1 - done < <(grep -rnw 'src/' -e 'console.log') + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' - if [ "$LOGS_FOUND" -ne "0" ]; then - exit 1 - else - echo "No console.log statements found." - fi + - name: Run check script + run: | + npm install @octokit/rest @actions/github child_process + node create-check.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ada524a81d863027e37d55d2485844141ef238ce Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Mon, 11 Mar 2024 18:57:10 +0100 Subject: [PATCH 08/21] Create create-check.js --- .github/workflows/create-check.js | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/create-check.js diff --git a/.github/workflows/create-check.js b/.github/workflows/create-check.js new file mode 100644 index 0000000..5f82cf2 --- /dev/null +++ b/.github/workflows/create-check.js @@ -0,0 +1,50 @@ +const { Octokit } = require("@octokit/rest"); +const { execSync } = require("child_process"); +const github = require("@actions/github"); + +async function createCheck() { + const token = process.env.GITHUB_TOKEN; + const octokit = new Octokit({ auth: token }); + const context = github.context; + + // Run grep to find console.log statements + let output; + try { + output = execSync("grep -rnw 'src/' -e 'console.log'").toString().trim(); + } catch (error) { + output = ''; // No console.log statements found + } + + const logLines = output.split('\n').filter(line => line.length); + const annotations = logLines.map(line => { + const [file, lineNo] = line.split(':'); + return { + path: file.replace('src/', ''), // Adjust according to your repo structure + start_line: parseInt(lineNo), + end_line: parseInt(lineNo), + annotation_level: 'warning', + message: 'console.log statement found', + start_column: 1, + end_column: 1 + }; + }); + + await octokit.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'Console Log Check', + head_sha: context.sha, + status: 'completed', + conclusion: logLines.length > 0 ? 'failure' : 'success', + output: { + title: 'Console Log Check', + summary: logLines.length > 0 ? 'Found console.log statements in the following locations:' : 'No console.log statements found.', + annotations: annotations + } + }); +} + +createCheck().catch(err => { + console.error(err); + process.exit(1); +}); From 4f55097e91d9cfb9caf5eb6e57fdde15da7f5aee Mon Sep 17 00:00:00 2001 From: Leo310 Date: Mon, 11 Mar 2024 18:57:50 +0100 Subject: [PATCH 09/21] refactor(lang): everything into en.json --- src/SmartSecondBrain.ts | 35 ++-- src/components/Chat/Chat.svelte | 21 +-- src/components/Chat/Input.svelte | 35 ++-- src/components/Chat/MessageContainer.svelte | 6 +- .../Chat/QuickSettingsDrawer.svelte | 59 +++---- src/components/Onboarding/OllamaApp.svelte | 26 +-- src/components/Onboarding/OllamaDaemon.svelte | 7 +- src/components/Onboarding/OllamaSetup.svelte | 11 +- src/components/Onboarding/Onboarding.svelte | 9 +- src/components/Onboarding/OpenAI.svelte | 27 ++- .../Onboarding/PullOllamaModel.svelte | 3 +- src/components/Settings/ConfirmModal.svelte | 9 +- src/components/Settings/ConfirmModal.ts | 2 +- src/components/Settings/FFExclude.svelte | 3 +- .../Settings/IncognitoToggle.svelte | 12 +- src/components/Settings/Ollama.svelte | 31 ++-- src/components/Settings/OpenAI.svelte | 17 +- .../Settings/SettingContainer.svelte | 8 +- src/components/Settings/Settings.svelte | 38 ++-- src/components/Settings/models.ts | 15 -- src/controller/Messages.ts | 3 +- src/lang/en.json | 165 +++++++++++++++++- src/lang/i18n.ts | 4 +- src/main.ts | 10 +- src/store.ts | 2 +- 25 files changed, 343 insertions(+), 215 deletions(-) diff --git a/src/SmartSecondBrain.ts b/src/SmartSecondBrain.ts index f9e4d63..cd5a44c 100644 --- a/src/SmartSecondBrain.ts +++ b/src/SmartSecondBrain.ts @@ -6,6 +6,7 @@ import { isOllamaRunning, getOllamaModels } from './controller/Ollama'; import { isAPIKeyValid } from './controller/OpenAI'; import Log, { LogLvl } from './logging'; import { data, papaState, errorState, papaIndexingProgress, chatHistory, serializeChatHistory, runState, runContent } from './store'; +import { _ } from 'svelte-i18n'; export default class SmartSecondBrain { private papa: Papa; @@ -20,23 +21,29 @@ export default class SmartSecondBrain { async init() { const d = get(data); - if (get(papaState) === 'running') return new Notice('Smart Second Brain is still running.', 4000); + const t = get(_); + if (get(papaState) === 'running') return new Notice(t('notice.still_running'), 4000); else if (get(papaState) === 'indexing' || get(papaState) === 'loading') { - return new Notice('Please wait for the indexing to finish', 4000); + return new Notice(t('notice.still_indexing'), 4000); } else if (d.isIncognitoMode && !(await isOllamaRunning())) { papaState.set('error'); errorState.set('ollama-not-running'); - return new Notice('Please make sure Ollama is running before initializing Smart Second Brain.', 4000); + return new Notice(t('notice.ollama_not_running'), 4000); } else if (d.isIncognitoMode) { const models = await getOllamaModels(); if (!models.includes(d.ollamaGenModel.model)) { papaState.set('error'); - errorState.set('ollama-model-not-installed'); - return new Notice('Ollama model not installed. Please install the model before initializing Smart Second Brain.', 4000); + errorState.set('ollama-gen-model-not-installed'); + return new Notice(t('notice.ollama_gen_model'), 4000); + } + if (!models.includes(d.ollamaEmbedModel.model)) { + papaState.set('error'); + errorState.set('ollama-embed-model-not-installed'); + return new Notice(t('notice.ollama_embed_model'), 4000); } } else if (!d.isIncognitoMode && !(await isAPIKeyValid(d.openAIGenModel.openAIApiKey))) { papaState.set('error'); - return new Notice('Please make sure OpenAI API Key is valid before initializing Smart Second Brain.', 4000); + return new Notice(t('notice.openai_key'), 4000); } if (get(papaState) !== 'indexing-pause') { papaState.set('loading'); @@ -58,7 +65,7 @@ export default class SmartSecondBrain { } catch (e) { Log.error(e); papaState.set('error'); - return new Notice('Failed to initialize Smart Second Brain (Error: ' + e + '). Please retry.', 4000); + return new Notice(t('notice.failed', { values: { error: e } }), 4000); } // check if vector store data exists if (await this.app.vault.adapter.exists(this.getVectorStorePath())) { @@ -75,7 +82,6 @@ export default class SmartSecondBrain { }) ); papaState.set('indexing'); - // const embedNotice = new Notice('Indexing notes into your smart second brain...', 0); let needsSave = false; try { for await (const result of this.papa.embedDocuments(docs)) { @@ -93,23 +99,24 @@ export default class SmartSecondBrain { Log.error(e); papaState.set('error'); // TODO add error state - new Notice('Failed to index notes into your smart second brain. Please retry.', 4000); + new Notice(t('notice.failed_indexing'), 4000); } this.needsToSaveVectorStoreData = needsSave; this.saveVectorStoreData(); if (get(papaIndexingProgress) === 100) { - new Notice('Smart Second Brain initialized.', 2000); + new Notice(t('notice.done'), 2000); papaIndexingProgress.set(0); papaState.set('idle'); } } canRunPapa() { - if (get(papaState) === 'running') return new Notice('Please wait for the current query to finish', 4000) && false; + const t = get(_); + if (get(papaState) === 'running') return new Notice(t('notice.still_running'), 4000) && false; else if (get(papaState) === 'indexing' || get(papaState) === 'indexing-pause' || get(papaState) === 'loading') - return new Notice('Please wait for the indexing to finish', 4000) && false; - else if (get(papaState) === 'error') return new Notice('Please wait for the error to resolve', 4000) && false; - else if (get(papaState) !== 'idle') return new Notice('Please initialize your Smart Second Brain first', 4000) && false; + return new Notice(t('notice.still_indexing'), 4000) && false; + else if (get(papaState) === 'error') return new Notice(t('notice.error'), 4000) && false; + else if (get(papaState) !== 'idle') return new Notice(t('notice.not_initialized'), 4000) && false; return true; } diff --git a/src/components/Chat/Chat.svelte b/src/components/Chat/Chat.svelte index 8f49d85..015f55e 100644 --- a/src/components/Chat/Chat.svelte +++ b/src/components/Chat/Chat.svelte @@ -5,6 +5,7 @@ import { afterUpdate } from 'svelte'; import DotAnimation from '../base/DotAnimation.svelte'; import MessageContainer from './MessageContainer.svelte'; + import { t } from 'svelte-i18n'; import { papaState, chatHistory, @@ -45,7 +46,7 @@ }); $: if ($runState === 'retrieving' && $runContent == '0') { - new Notice('No notes retrieved. Maybe lower the similarity threshold.'); + new Notice($t('notice.no_notes_retrieved')); } let editElem: HTMLSpanElement; @@ -90,11 +91,11 @@
{#if $isEditing && editMessageId === message.id} - + {:else} wrapperEditMessage(message, textarea)} use:icon={'pencil-line'} @@ -116,12 +117,12 @@ {#if !$isEditingAssistantMessage} - toClipboard(message.content)} use:icon={'copy'} /> + toClipboard(message.content)} use:icon={'copy'} /> {#if $chatHistory.indexOf(message) !== 0} redoGeneration(message)} use:icon={'refresh-cw'} @@ -131,7 +132,7 @@ editInitialAssistantMessage(message.content, textarea)} use:icon={'pencil-line'} @@ -141,7 +142,7 @@ cancelEditingInitialAssistantMessage(initialAssistantMessageSpan)} use:icon={'x-circle'} @@ -149,7 +150,7 @@ resetInitialAssistantMessage(initialAssistantMessageSpan)} use:icon={'rotate-ccw'} @@ -164,9 +165,9 @@ {#if $runState === 'startup'} {:else if $runState === 'retrieving'} -

Retrieving

+

{$t('chat.retrieving')}

{:else if $runState === 'reducing'} -

Reducing {$runContent} Notes

+

{$t('chat.reducing', { values: { num: $runContent } })}

{:else if $runState === 'generating' && $runContent} diff --git a/src/components/Chat/Input.svelte b/src/components/Chat/Input.svelte index 24f9219..968a903 100644 --- a/src/components/Chat/Input.svelte +++ b/src/components/Chat/Input.svelte @@ -1,7 +1,6 @@ @@ -86,18 +82,12 @@ {#if $chatHistory.length > 1} -
$plugin.saveChat()} - hidden={$papaState === 'running'} - /> +
$plugin.saveChat()} hidden={$papaState === 'running'} /> {/if}
{:else}
-
User
+
{$t('chat.user')}
{/if} @@ -31,7 +33,7 @@ ? 'bg-[--background-secondary]' : 'bg-[--background-primary]'}" > -
Smart2Brain
+
{$t('chat.assistant')}
{/if} diff --git a/src/components/Chat/QuickSettingsDrawer.svelte b/src/components/Chat/QuickSettingsDrawer.svelte index 10383f8..73d185a 100644 --- a/src/components/Chat/QuickSettingsDrawer.svelte +++ b/src/components/Chat/QuickSettingsDrawer.svelte @@ -71,8 +71,8 @@ ? $plugin.s2b.init() : new ConfirmModal( get(plugin).app, - 'Run via Third-Parties', - 'Are you sure you want to run via third-parties? Your data will be given to third-party servers.', + $t('init_third_party_modal.title'), + $t('init_third_party_modal.description'), (result) => { if (result === 'Yes') $plugin.s2b.init(); }, @@ -89,52 +89,55 @@ {#if $papaState === 'loading' || $papaState === 'uninitialized'} {:else if $papaState === 'indexing'} -

Indexing vault

+

{$t('quick_settings.indexing_vault')}

{:else if $papaState === 'indexing-pause'} -

Indexing vault

+

{$t('quick_settings.indexing_vault')}

{:else if $papaState === 'error'} - {#if $errorState === 'ollama-model-not-installed'} -

Install {$data.ollamaGenModel.model} first.

+ {#if $errorState === 'ollama-gen-model-not-installed'} +

{$t('install_model', { values: { model: $data.ollamaGenModel.model } })}

+ ($papaState = 'settings-change')} /> + {:else if $errorState === 'ollama-embed-model-not-installed'}} +

{$t('install_model', { values: { model: $data.ollamaEmbedModel.model } })}

($papaState = 'settings-change')} /> {:else} -

An error occured.
Please retry initialization...

+

{$t('quick_settings.error.other')}

{$t('onboarding.test')} {/if}
@@ -45,14 +47,14 @@ {#if isRunning} {#if osType === 'Darwin'} -
  • Set Ollama origins to enable streaming responses
  • +
  • {$t('onboarding.ollama.app.set_origins')}
  • - Restart the Ollama service + {$t('onboarding.ollama.app.restart')}
  • {:else} -
  • Quit Ollama
  • -
  • Start the Ollama service with origins
  • +
  • {$t('onboarding.ollama.app.quit')}
  • +
  • {$t('onboarding.ollama.app.start_origins')}
  • {/if} diff --git a/src/components/Onboarding/OllamaDaemon.svelte b/src/components/Onboarding/OllamaDaemon.svelte index d8081e7..b3038cd 100644 --- a/src/components/Onboarding/OllamaDaemon.svelte +++ b/src/components/Onboarding/OllamaDaemon.svelte @@ -5,6 +5,7 @@ import { plugin, data } from '../../store'; import { changeOllamaBaseUrl } from '../../controller/Ollama'; import OllamaSetup from './OllamaSetup.svelte'; + import { t } from 'svelte-i18n'; export let osType: string; @@ -15,7 +16,7 @@
      -
    1. Install Ollama
    2. +
    3. {$t('onboarding.ollama.deamon.install')}
    4. {#if osType === 'Darwin'}
      {:else if osType === 'Linux'} @@ -27,11 +28,11 @@
    5. - Set the BaseUrl + {$t('onboarding.ollama.deamon.set_baseurl')}
    6. -
    7. Start the Ollama service with origins
    8. +
    9. {$t('onboarding.ollama.deamon.start')}
    diff --git a/src/components/Onboarding/OllamaSetup.svelte b/src/components/Onboarding/OllamaSetup.svelte index d8e0522..3ed702c 100644 --- a/src/components/Onboarding/OllamaSetup.svelte +++ b/src/components/Onboarding/OllamaSetup.svelte @@ -6,6 +6,7 @@ import { plugin, data } from '../../store'; import DropdownComponent from '../base/Dropdown.svelte'; import { isOllamaOriginsSet } from '../../controller/Ollama'; + import { t } from 'svelte-i18n'; import PullOllamaModel from './PullOllamaModel.svelte'; let model: string = ''; @@ -24,7 +25,7 @@
  • - Test if the origins are set correctly: + {$t('onboarding.ollama.test_origins')}
    {#if isOriginsTested} {#if isOrigin} @@ -40,7 +41,7 @@ isOrigin = await isOllamaOriginsSet(); isOriginsTested = true; ollamaModels = await getOllamaModels(); - }}>Test{$t('onboarding.test')} {/if}
    @@ -48,9 +49,9 @@
  • {#if isOrigin}
  • - Install an Ollama Embedding Model.
    + {$t('onboarding.ollama.install_model')}
    - Recomended: + {$t('onboarding.ollama.recommended_models')}
    @@ -58,7 +59,7 @@ {#if ollamaModels.length}
  • - Set your embed Model: + {$t('onboarding.ollama.set_model')}
    {$t('onboarding.test')} {/if}
    diff --git a/src/components/Onboarding/PullOllamaModel.svelte b/src/components/Onboarding/PullOllamaModel.svelte index 2d0696f..b8a5a83 100644 --- a/src/components/Onboarding/PullOllamaModel.svelte +++ b/src/components/Onboarding/PullOllamaModel.svelte @@ -2,6 +2,7 @@ import { Notice } from 'obsidian'; import { data } from '../../store'; import { pullOllamaModel } from '../../controller/Ollama'; + import { t } from 'svelte-i18n'; import ProgressBar from '../base/ProgressBar.svelte'; export let onSuccessfulPull: () => void = () => {}; @@ -24,7 +25,7 @@ isPullingModel = false; } catch (e) { isPullingError = true; - new Notice(e); + new Notice($t('notice.error_pulling_model', { values: { error: e.message } })); } } function formatBytes(bytes: number, decimals = 2) { diff --git a/src/components/Settings/ConfirmModal.svelte b/src/components/Settings/ConfirmModal.svelte index 4243c1e..dbe0153 100644 --- a/src/components/Settings/ConfirmModal.svelte +++ b/src/components/Settings/ConfirmModal.svelte @@ -2,6 +2,7 @@ import ButtonComponent from '../base/Button.svelte'; import { type ConfirmModal } from './ConfirmModal'; import { data } from '../../store'; + import { t } from 'svelte-i18n'; export let modal: ConfirmModal; @@ -12,18 +13,18 @@ {#if modal.hideModalOption !== ''}
    data.warningOff(modal.hideModalOption)} /> - +
    {/if} { modal.close(); - modal.onSubmit('No'); + modal.onSubmit('Cancel'); }} /> { modal.close(); diff --git a/src/components/Settings/ConfirmModal.ts b/src/components/Settings/ConfirmModal.ts index 9d86ddf..9ed911b 100644 --- a/src/components/Settings/ConfirmModal.ts +++ b/src/components/Settings/ConfirmModal.ts @@ -39,7 +39,7 @@ export class ConfirmModal extends Modal { } onClose() { - let { contentEl } = this; + const { contentEl } = this; contentEl.empty(); } } diff --git a/src/components/Settings/FFExclude.svelte b/src/components/Settings/FFExclude.svelte index 22f04a5..4e3abde 100644 --- a/src/components/Settings/FFExclude.svelte +++ b/src/components/Settings/FFExclude.svelte @@ -4,6 +4,7 @@ import { FileSelectModal } from './FuzzyModal'; import ButtonComponent from '../base/Button.svelte'; import type { FuzzySuggestModal, TAbstractFile } from 'obsidian'; + import { t } from 'svelte-i18n'; let buttonComp: ButtonComponent; @@ -14,4 +15,4 @@ }); - fileSelectModal.open()} buttonText="Add" /> + fileSelectModal.open()} buttonText={$t('settings.excludeff_add')} /> diff --git a/src/components/Settings/IncognitoToggle.svelte b/src/components/Settings/IncognitoToggle.svelte index ab604e5..18a7ee2 100644 --- a/src/components/Settings/IncognitoToggle.svelte +++ b/src/components/Settings/IncognitoToggle.svelte @@ -2,17 +2,15 @@ import { Notice } from 'obsidian'; import { plugin, data, papaState, type PapaState } from '../../store'; import { crossfade } from 'svelte/transition'; - import { ConfirmModal } from './ConfirmModal'; - import { get } from 'svelte/store'; + import { t } from 'svelte-i18n'; const [send, recieve] = crossfade({ duration: 500 }); let oldPapaState: PapaState; function setIncognitoMode(incognito: boolean) { if (incognito === $data.isIncognitoMode) return; - if ($papaState === 'running') return new Notice('Please wait for the current query to finish', 4000); - else if ($papaState === 'indexing' || $papaState === 'indexing-pause' || $papaState === 'loading') - return new Notice('Please wait for the indexing to finish', 4000); + if ($papaState === 'running') return new Notice($t('notice.still_running'), 4000); + else if ($papaState === 'indexing' || $papaState === 'indexing-pause' || $papaState === 'loading') return new Notice($t('notice.still_indexing'), 4000); $data.isIncognitoMode = incognito; $plugin.saveSettings(); if ($papaState === 'mode-change') { @@ -32,7 +30,7 @@ class="flex h-full flex-col items-center justify-center rounded-md p-2 text-center font-bold hover:bg-[--background-modifier-hover]" on:click={() => setIncognitoMode(true)} > - Run on your machine + {$t('incognito_toggle.enable')} {#if $data.isIncognitoMode}
    {/if} @@ -43,7 +41,7 @@ class="flex h-full flex-col items-center justify-center rounded-md p-2 text-center font-bold hover:bg-[--background-modifier-hover]" on:click={() => setIncognitoMode(false)} > - Run via Third-Parties + {$t('incognito_toggle.disable')} {#if !$data.isIncognitoMode}
    {/if} diff --git a/src/components/Settings/Ollama.svelte b/src/components/Settings/Ollama.svelte index eb98ddb..bfa50f2 100644 --- a/src/components/Settings/Ollama.svelte +++ b/src/components/Settings/Ollama.svelte @@ -1,12 +1,13 @@ - + { isRunning = await isOllamaRunning(); - if (!isRunning) return new Notice('Ollama is not running', 4000); + if (!isRunning) return new Notice($t('notice.ollama_not_running'), 4000); installedOllamaModels = await getOllamaModels(); ollamaModels = [...new Set(installedOllamaModels.concat(OllamaGenModelNames).concat(OllamaEmbedModelNames))]; }} @@ -66,7 +67,7 @@ > - + {#if isRunning} - + - + -
    -
    -

    {$t('quick_settings.creativity')}

    - +
    + {$t('quick_settings.creativity')} +
    + {temperature}% + +
    + {#if $data.isUsingRag} +
    + {$t('quick_settings.similarity_threshold')} +
    + {similarityThreshold}% + +
    +
    + {/if}
    {/if} {/if} diff --git a/src/components/Onboarding/InitButton.svelte b/src/components/Onboarding/InitButton.svelte index 4eae8f4..ef91f3e 100644 --- a/src/components/Onboarding/InitButton.svelte +++ b/src/components/Onboarding/InitButton.svelte @@ -1,6 +1,7 @@ {$t('onboarding.init')} diff --git a/src/components/Onboarding/Onboarding.svelte b/src/components/Onboarding/Onboarding.svelte index 4de0258..19f4fd1 100644 --- a/src/components/Onboarding/Onboarding.svelte +++ b/src/components/Onboarding/Onboarding.svelte @@ -22,7 +22,7 @@ {#if $data.isIncognitoMode}

    - {$t('onboarding.privacy_mode_note')}} + {$t('onboarding.privacy_mode_note')}

    {#if osType === 'Darwin'} diff --git a/src/lang/en.json b/src/lang/en.json index 748a8d6..80fbc97 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -54,6 +54,8 @@ "test": "Test", "privacy_mode_note": "Your assistant is running in privacy mode. That means it is not connected to the internet and is running fully locally by leveraging Ollama.", "openai_mode_note": "Your assistant is using third party services to run. That means you will have to share all your personal information with these services and your Smart Second Brain needs to be connected to the internet to leverage OpenAIs large language models like ChatGPT.", + "init": "Initialize your Smart Second Brain", + "init_label": "Click to initialize", "ollama": { "deamon": { "install": "Install Ollama", @@ -152,8 +154,8 @@ "reinitialize": "Reinitialize Smart Second Brain", "chat_via": "Chat via {model}", "chatview": "Comfy Chatview", - "similarity_threshold": "Relevancy in %", - "creativity": "Creativity in %", + "similarity_threshold": "Relevancy", + "creativity": "Creativity", "settings_changed": "Settings changed.\nReinitialize Smart Second Brain.", "open": "Open quick settings", "close": "Close quick settings", From f9a690f66103ba3179b22416b80eb7571da38abf Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Wed, 13 Mar 2024 13:54:56 +0100 Subject: [PATCH 13/21] feat(settings): indicate wrong url or api key --- .github/workflows/console-logs.yml | 25 ------------- .github/workflows/create-check.js | 50 ------------------------- .github/workflows/logs.yml | 26 +++++++++++++ src/components/Settings/Ollama.svelte | 4 +- src/components/Settings/OpenAI.svelte | 6 ++- src/components/Settings/Settings.svelte | 1 - src/components/base/Text.svelte | 2 +- src/controller/Ollama.ts | 11 +----- src/logging.ts | 2 - src/store.ts | 1 - 10 files changed, 36 insertions(+), 92 deletions(-) delete mode 100644 .github/workflows/console-logs.yml delete mode 100644 .github/workflows/create-check.js create mode 100644 .github/workflows/logs.yml diff --git a/.github/workflows/console-logs.yml b/.github/workflows/console-logs.yml deleted file mode 100644 index c79bdd3..0000000 --- a/.github/workflows/console-logs.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Check Console Logs - -on: - pull_request: - branches: - - main - -jobs: - check-logs: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Node.js - uses: actions/setup-node@v2 - with: - node-version: '14' - - - name: Run check script - run: | - npm install @octokit/rest @actions/github child_process - node create-check.js - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/create-check.js b/.github/workflows/create-check.js deleted file mode 100644 index 5f82cf2..0000000 --- a/.github/workflows/create-check.js +++ /dev/null @@ -1,50 +0,0 @@ -const { Octokit } = require("@octokit/rest"); -const { execSync } = require("child_process"); -const github = require("@actions/github"); - -async function createCheck() { - const token = process.env.GITHUB_TOKEN; - const octokit = new Octokit({ auth: token }); - const context = github.context; - - // Run grep to find console.log statements - let output; - try { - output = execSync("grep -rnw 'src/' -e 'console.log'").toString().trim(); - } catch (error) { - output = ''; // No console.log statements found - } - - const logLines = output.split('\n').filter(line => line.length); - const annotations = logLines.map(line => { - const [file, lineNo] = line.split(':'); - return { - path: file.replace('src/', ''), // Adjust according to your repo structure - start_line: parseInt(lineNo), - end_line: parseInt(lineNo), - annotation_level: 'warning', - message: 'console.log statement found', - start_column: 1, - end_column: 1 - }; - }); - - await octokit.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'Console Log Check', - head_sha: context.sha, - status: 'completed', - conclusion: logLines.length > 0 ? 'failure' : 'success', - output: { - title: 'Console Log Check', - summary: logLines.length > 0 ? 'Found console.log statements in the following locations:' : 'No console.log statements found.', - annotations: annotations - } - }); -} - -createCheck().catch(err => { - console.error(err); - process.exit(1); -}); diff --git a/.github/workflows/logs.yml b/.github/workflows/logs.yml new file mode 100644 index 0000000..22f0739 --- /dev/null +++ b/.github/workflows/logs.yml @@ -0,0 +1,26 @@ +name: Check for console.logs + +on: + pull_request: + branches: + - main + +jobs: + check-logs: + runs-on: ubuntu-latest + steps: + - name: get the sources + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Install dependencies + run: npm ci + + - name: Run check script + run: node .github/workflows/create-check.js + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/components/Settings/Ollama.svelte b/src/components/Settings/Ollama.svelte index bfa50f2..916c5f3 100644 --- a/src/components/Settings/Ollama.svelte +++ b/src/components/Settings/Ollama.svelte @@ -20,6 +20,7 @@ installedOllamaModels = await getOllamaModels(); ollamaModels = [...new Set(installedOllamaModels.concat(OllamaGenModelNames).concat(OllamaEmbedModelNames))]; isRunning = await isOllamaRunning(); + styleOllamaBaseUrl = isRunning ? '' : '!bg-[--background-modifier-error]'; }); $: if (ollamaBaseUrl.trim() === '' && $data.ollamaGenModel.baseUrl !== '') { @@ -30,6 +31,7 @@ ollamaBaseUrl = DEFAULT_SETTINGS.ollamaGenModel.baseUrl; await changeOllamaBaseUrl(ollamaBaseUrl); isRunning = await isOllamaRunning(); + styleOllamaBaseUrl = isRunning ? '' : '!bg-[--background-modifier-error]'; }; const ollamaGenChange = (selected: string) => { $data.ollamaGenModel.model = selected; @@ -66,7 +68,6 @@ /> - { await changeOllamaBaseUrl(newBaseUrl); isRunning = await isOllamaRunning(); + styleOllamaBaseUrl = isRunning ? '' : '!bg-[--background-modifier-error]'; }} /> diff --git a/src/components/Settings/OpenAI.svelte b/src/components/Settings/OpenAI.svelte index b671852..937c465 100644 --- a/src/components/Settings/OpenAI.svelte +++ b/src/components/Settings/OpenAI.svelte @@ -10,11 +10,13 @@ let openAIApiKey: string; let isOpenAIAPIKeyValid = false; + let apiKeyStyles: string = ''; onMount(async () => { isOpenAIAPIKeyValid = await isAPIKeyValid($data.openAIGenModel.openAIApiKey); openAIApiKey = $data.openAIGenModel.openAIApiKey; hideApiKey(); + apiKeyStyles = isOpenAIAPIKeyValid ? '' : '!bg-[--background-modifier-error]'; }); const changeApiKey = async (newApiKey: string) => { @@ -25,6 +27,7 @@ $data.openAIEmbedModel.openAIApiKey = newApiKey; $plugin.saveSettings(); $papaState = 'settings-change'; + apiKeyStyles = isOpenAIAPIKeyValid ? '' : '!bg-[--background-modifier-error]'; }; const hideApiKey = () => { @@ -52,8 +55,7 @@ - - + {#if isOpenAIAPIKeyValid} diff --git a/src/components/Settings/Settings.svelte b/src/components/Settings/Settings.svelte index 6d24bd6..83eceda 100644 --- a/src/components/Settings/Settings.svelte +++ b/src/components/Settings/Settings.svelte @@ -117,7 +117,6 @@ - $plugin.clearPluginData()} /> diff --git a/src/components/base/Text.svelte b/src/components/base/Text.svelte index 158a947..eefc81a 100644 --- a/src/components/base/Text.svelte +++ b/src/components/base/Text.svelte @@ -10,7 +10,7 @@ {#if inputType === 'text'} { const plugin = get(p); newBaseUrl.trim(); if (newBaseUrl.endsWith('/')) newBaseUrl = newBaseUrl.slice(0, -1); - try { - // check if url is valid - new URL(newBaseUrl); - d.ollamaGenModel.baseUrl = newBaseUrl; - d.ollamaEmbedModel.baseUrl = newBaseUrl; - //styleOllamaBaseUrl = 'bg-[--background-modifier-form-field]'; - } catch (_) { - //styleOllamaBaseUrl = 'bg-[--background-modifier-error]'; - } + d.ollamaGenModel.baseUrl = newBaseUrl; + d.ollamaEmbedModel.baseUrl = newBaseUrl; await plugin.saveSettings(); papaState.set('settings-change'); }; diff --git a/src/logging.ts b/src/logging.ts index 1316a5a..d6fbfd3 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -1,5 +1,3 @@ -// TODO eslint rule to remove all console.logs before production - export enum LogLvl { DEBUG = 1, INFO = 2, diff --git a/src/store.ts b/src/store.ts index 966327d..dc95f14 100644 --- a/src/store.ts +++ b/src/store.ts @@ -68,7 +68,6 @@ function createData() { warningOff: (value) => { update((d) => { d[value] = true; - console.log('d', d.hideIncognitoWarning); return d; }); get(plugin).saveSettings(); From 8af9bdf479f7c415accd575f571c45cf9348e9af Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Wed, 13 Mar 2024 14:05:06 +0100 Subject: [PATCH 14/21] feat: install set model Co-authored-by: Leo310 --- src/components/Onboarding/OllamaSetup.svelte | 2 +- src/components/Onboarding/PullOllamaModel.svelte | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Onboarding/OllamaSetup.svelte b/src/components/Onboarding/OllamaSetup.svelte index 3ed702c..b3c2116 100644 --- a/src/components/Onboarding/OllamaSetup.svelte +++ b/src/components/Onboarding/OllamaSetup.svelte @@ -54,7 +54,7 @@ {$t('onboarding.ollama.recommended_models')}
    - +
  • {#if ollamaModels.length}
  • diff --git a/src/components/Onboarding/PullOllamaModel.svelte b/src/components/Onboarding/PullOllamaModel.svelte index b8a5a83..2dc7fd6 100644 --- a/src/components/Onboarding/PullOllamaModel.svelte +++ b/src/components/Onboarding/PullOllamaModel.svelte @@ -6,6 +6,7 @@ import ProgressBar from '../base/ProgressBar.svelte'; export let onSuccessfulPull: () => void = () => {}; + export let pullModel: string; let isPullingModel = false; let total: number = 0; @@ -16,7 +17,7 @@ async function pullOllamaModelStream() { isPullingModel = true; try { - for await (const chunk of pullOllamaModel($data.ollamaGenModel.model)) { + for await (const chunk of pullOllamaModel(pullModel)) { status = chunk.status; if (chunk.total) total = chunk.total; if (chunk.completed) progress = Math.floor((chunk.completed / total) * 100); From 58713aa2b45f20621ddd8e9feb79bd06e2f11c56 Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Wed, 13 Mar 2024 18:44:40 +0100 Subject: [PATCH 15/21] feat: cancel model download --- src/components/Chat/QuickSettingsDrawer.svelte | 12 ++++++------ src/components/Onboarding/PullOllamaModel.svelte | 14 +++++++++++++- src/controller/Ollama.ts | 12 ++++++++++-- src/store.ts | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/components/Chat/QuickSettingsDrawer.svelte b/src/components/Chat/QuickSettingsDrawer.svelte index 712d257..ae01f70 100644 --- a/src/components/Chat/QuickSettingsDrawer.svelte +++ b/src/components/Chat/QuickSettingsDrawer.svelte @@ -121,10 +121,10 @@ {:else if $papaState === 'error'} {#if $errorState === 'ollama-gen-model-not-installed'}

    {$t('install_model', { values: { model: $data.ollamaGenModel.model } })}

    - ($papaState = 'settings-change')} /> + ($papaState = 'settings-change')} /> {:else if $errorState === 'ollama-embed-model-not-installed'}}

    {$t('install_model', { values: { model: $data.ollamaEmbedModel.model } })}

    - ($papaState = 'settings-change')} /> + ($papaState = 'settings-change')} /> {:else}

    {$t('quick_settings.error.other')}

  • - {#if ollamaModels.length} + {#if ollamaModels.length > 0}
  • {$t('onboarding.ollama.set_model')} @@ -66,7 +67,7 @@ bind:this={ollamaModelComponent} selected={model} options={ollamaModels.map((model) => ({ display: model, value: model }))} - changeFunc={(selected) => (model = selected)} + changeFunc={(selected) => ($data.ollamaEmbedModel.model = selected)} />
  • diff --git a/src/components/Onboarding/PullOllamaModel.svelte b/src/components/Onboarding/PullOllamaModel.svelte index f82b608..6321a9a 100644 --- a/src/components/Onboarding/PullOllamaModel.svelte +++ b/src/components/Onboarding/PullOllamaModel.svelte @@ -26,6 +26,7 @@ if (chunk.completed) progress = Math.floor((chunk.completed / total) * 100); } if (progress === 100) onSuccessfulPull(); + isPullingModel = false; } catch (e) { isPullingError = true; From 180cdd93d77e4761cc1b6d0c3c388566401d6541 Mon Sep 17 00:00:00 2001 From: Leo310 Date: Thu, 14 Mar 2024 11:45:54 +0100 Subject: [PATCH 17/21] refactor(chat): message spacing --- src/components/Chat/Chat.svelte | 8 +------- src/components/Chat/MessageContainer.svelte | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/Chat/Chat.svelte b/src/components/Chat/Chat.svelte index 015f55e..6fb51e0 100644 --- a/src/components/Chat/Chat.svelte +++ b/src/components/Chat/Chat.svelte @@ -106,13 +106,7 @@ - +
    {#if !$isEditingAssistantMessage} diff --git a/src/components/Chat/MessageContainer.svelte b/src/components/Chat/MessageContainer.svelte index 9c1fb89..c5be6c8 100644 --- a/src/components/Chat/MessageContainer.svelte +++ b/src/components/Chat/MessageContainer.svelte @@ -9,7 +9,7 @@ {#if $data.isChatComfy}
    -
    +
    @@ -21,7 +21,7 @@ {/if} {:else if $data.isChatComfy}
    From 97f20e72748887209f38708c27b95afe9f5e76a5 Mon Sep 17 00:00:00 2001 From: Leo310 Date: Thu, 14 Mar 2024 13:00:12 +0100 Subject: [PATCH 18/21] refactor(settings): now disabled functionality --- src/components/Settings/Ollama.svelte | 72 ++++++++++--------- src/components/Settings/OpenAI.svelte | 43 ++++++----- .../Settings/SettingContainer.svelte | 3 +- src/lang/en.json | 8 +-- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/src/components/Settings/Ollama.svelte b/src/components/Settings/Ollama.svelte index 916c5f3..0610419 100644 --- a/src/components/Settings/Ollama.svelte +++ b/src/components/Settings/Ollama.svelte @@ -56,7 +56,7 @@ }; - + { @@ -81,35 +81,41 @@ }} /> -{#if isRunning} - - - - - - - - -{/if} + + + + + + + + diff --git a/src/components/Settings/OpenAI.svelte b/src/components/Settings/OpenAI.svelte index 937c465..fae8887 100644 --- a/src/components/Settings/OpenAI.svelte +++ b/src/components/Settings/OpenAI.svelte @@ -57,22 +57,27 @@ - -{#if isOpenAIAPIKeyValid} - - - ({ display: model, value: model }))} - changeFunc={openAIGenChange} - /> - - - - ({ display: model, value: model }))} - changeFunc={openAIEmbedChange} - /> - -{/if} + + + ({ display: model, value: model }))} + changeFunc={openAIGenChange} + /> + + + + ({ display: model, value: model }))} + changeFunc={openAIEmbedChange} + /> + diff --git a/src/components/Settings/SettingContainer.svelte b/src/components/Settings/SettingContainer.svelte index a6fcf13..a842335 100644 --- a/src/components/Settings/SettingContainer.svelte +++ b/src/components/Settings/SettingContainer.svelte @@ -2,9 +2,10 @@ export let name: string; export let isHeading: boolean = false; export let desc: string = ''; + export let isDisabled: boolean = false; -
    +
    {name}
    {desc}
    diff --git a/src/lang/en.json b/src/lang/en.json index 80fbc97..68d2ba6 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -24,9 +24,7 @@ "api_key_invalid": "API Key is invalid!", "error_pulling_model": "Failed to pull model from Ollama (Error: {error}). Please retry.", "copied_to_clipboard": "Copied to clipboard:\n{text}", - "no_notes_retrieved": "No notes retrieved. Maybe lower the similarity threshold.", - "using_papa": "Now chatting with your Notes.", - "using_llm": "Now chatting with plain LLM." + "no_notes_retrieved": "No notes retrieved. Maybe lower the similarity threshold." }, "chat": { "edit": "Edit query and regenerate answer", @@ -111,7 +109,7 @@ "langsmith_key": "Langsmith API Key", "verbose": "Developer Console logging", "openai": { - "description": "Incognito Mode is disabled. OpenAI is enabled.", + "description": " ", "api_key": "API Key", "gen_model": "Chat Model", "embed_model": "Embedding Model", @@ -125,7 +123,7 @@ } }, "ollama": { - "description": "Incognito Mode is enabled. Ollama is enabled.", + "description": "Refresh if your started Ollama.", "gen_model": "Chat Model", "embed_model": "Embedding Model", "recommended": "Recommended", From 306fc6ad1f0cf990cf10e3fdd48fdc755b9c2145 Mon Sep 17 00:00:00 2001 From: Leo310 Date: Thu, 14 Mar 2024 13:00:50 +0100 Subject: [PATCH 19/21] feat: new Logo --- src/components/Chat/Input.svelte | 13 +-- src/components/Onboarding/Onboarding.svelte | 6 +- src/components/base/Logo.svelte | 114 ++++++++++++++++++++ 3 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 src/components/base/Logo.svelte diff --git a/src/components/Chat/Input.svelte b/src/components/Chat/Input.svelte index 968a903..fd0a0fb 100644 --- a/src/components/Chat/Input.svelte +++ b/src/components/Chat/Input.svelte @@ -16,6 +16,7 @@ } from '../../store'; import ProgressCircle from '../base/ProgressCircle.svelte'; import { addMessage } from '../../controller/Messages'; + import Logo from '../base/Logo.svelte'; export let textarea: HTMLTextAreaElement; @@ -50,7 +51,6 @@ function handleRAGToggle() { $data.isUsingRag = !$data.isUsingRag; $plugin.saveSettings(); - new Notice($data.isUsingRag ? $t('notice.using_papa') : $t('notice.using_llm')); } function handelEnter(event: KeyboardEvent) { @@ -75,9 +75,9 @@
    {#if $chatHistory.length > 1} @@ -89,11 +89,12 @@
    + > + +
    {#if $chatHistory.length > 1} diff --git a/src/components/Onboarding/Onboarding.svelte b/src/components/Onboarding/Onboarding.svelte index 19f4fd1..c1e6bdd 100644 --- a/src/components/Onboarding/Onboarding.svelte +++ b/src/components/Onboarding/Onboarding.svelte @@ -5,9 +5,9 @@ import AppComponent from './OllamaApp.svelte'; import OpenAiComponent from './OpenAI.svelte'; import DaemonComponent from './OllamaDaemon.svelte'; - import { icon } from '../../controller/Messages'; import IncognitoToggle from '../Settings/IncognitoToggle.svelte'; import { t } from 'svelte-i18n'; + import Logo from '../base/Logo.svelte'; const osType = os.type(); @@ -16,7 +16,9 @@
    -
    +
    + +

    {$t('onboarding.setup')}

    diff --git a/src/components/base/Logo.svelte b/src/components/base/Logo.svelte new file mode 100644 index 0000000..394edb5 --- /dev/null +++ b/src/components/base/Logo.svelte @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9a14470ce00f52cc660436c1712a88287421886d Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Thu, 14 Mar 2024 15:15:27 +0100 Subject: [PATCH 20/21] fix(settings): api key, url error bg --- src/components/Settings/Ollama.svelte | 6 +----- src/components/Settings/OpenAI.svelte | 4 ++-- src/controller/Ollama.ts | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/Settings/Ollama.svelte b/src/components/Settings/Ollama.svelte index 0610419..e137191 100644 --- a/src/components/Settings/Ollama.svelte +++ b/src/components/Settings/Ollama.svelte @@ -11,7 +11,7 @@ import { onMount } from 'svelte'; let styleOllamaBaseUrl: string; - let ollamaBaseUrl: string = ''; + let ollamaBaseUrl: string = $data.ollamaGenModel.baseUrl; let installedOllamaModels: string[] = []; let ollamaModels: string[] = []; let isRunning: boolean = false; @@ -23,10 +23,6 @@ styleOllamaBaseUrl = isRunning ? '' : '!bg-[--background-modifier-error]'; }); - $: if (ollamaBaseUrl.trim() === '' && $data.ollamaGenModel.baseUrl !== '') { - ollamaBaseUrl = $data.ollamaGenModel.baseUrl; - } - const resetOllamaBaseUrl = async () => { ollamaBaseUrl = DEFAULT_SETTINGS.ollamaGenModel.baseUrl; await changeOllamaBaseUrl(ollamaBaseUrl); diff --git a/src/components/Settings/OpenAI.svelte b/src/components/Settings/OpenAI.svelte index fae8887..cd16d4f 100644 --- a/src/components/Settings/OpenAI.svelte +++ b/src/components/Settings/OpenAI.svelte @@ -16,7 +16,7 @@ isOpenAIAPIKeyValid = await isAPIKeyValid($data.openAIGenModel.openAIApiKey); openAIApiKey = $data.openAIGenModel.openAIApiKey; hideApiKey(); - apiKeyStyles = isOpenAIAPIKeyValid ? '' : '!bg-[--background-modifier-error]'; + apiKeyStyles = openAIApiKey && !isOpenAIAPIKeyValid ? '!bg-[--background-modifier-error]' : ''; }); const changeApiKey = async (newApiKey: string) => { @@ -27,7 +27,7 @@ $data.openAIEmbedModel.openAIApiKey = newApiKey; $plugin.saveSettings(); $papaState = 'settings-change'; - apiKeyStyles = isOpenAIAPIKeyValid ? '' : '!bg-[--background-modifier-error]'; + apiKeyStyles = openAIApiKey && !isOpenAIAPIKeyValid ? '!bg-[--background-modifier-error]' : ''; }; const hideApiKey = () => { diff --git a/src/controller/Ollama.ts b/src/controller/Ollama.ts index 39c1f4e..b6e48a1 100644 --- a/src/controller/Ollama.ts +++ b/src/controller/Ollama.ts @@ -6,10 +6,12 @@ import Log from '../logging'; export async function isOllamaRunning() { const d = get(data); try { - const response = await requestUrl(d.ollamaGenModel.baseUrl + '/api/tags'); + const url = new URL(d.ollamaGenModel.baseUrl); + const response = await requestUrl(url + '/api/tags'); if (response.status === 200) { return true; } else { + console.log(d.ollamaGenModel.baseUrl); Log.debug(`IsOllamaRunning, Unexpected status code: ${response.status}`); return false; } @@ -53,6 +55,23 @@ export async function getOllamaModels(): Promise { } } +export async function deleteOllamaModels(): Promise { + const d = get(data); + try { + const modelsRes = await requestUrl({ + url: d.ollamaGenModel.baseUrl + '/api/delete', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }); + //TODO langugage + modelsRes.status === 404 ? new Notice('No models to delete') : new Notice('Models deleted'); + } catch (error) { + Log.debug('Ollama is not running', error); + } +} + export const changeOllamaBaseUrl = async (newBaseUrl: string) => { const d = get(data); const plugin = get(p); From cd5936bd9f45dac465c42c9d2437035fb438ef46 Mon Sep 17 00:00:00 2001 From: nicobrauchtgit Date: Thu, 14 Mar 2024 15:18:25 +0100 Subject: [PATCH 21/21] manifest version up --- manifest.json | 2 +- versions.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 07512a0..053c399 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "description": "Interact with your privacy focused assistant, leveraging Ollama or OpenAI, making your second brain even smarter.", "author": "Leo310, nicobrauchtgit", "authorUrl": "https://github.com/nicobrauchtgit", - "version": "0.3.2", + "version": "0.4.2", "minAppVersion": "1.5.0", "isDesktopOnly": true } diff --git a/versions.json b/versions.json index 84818ce..2985ffa 100644 --- a/versions.json +++ b/versions.json @@ -10,5 +10,6 @@ "0.2.5": "1.5.0" "0.2.6": "1.5.0" "0.2.7": "1.5.0" - "0.2.8": "1.5.8" + "0.2.8": "1.5.0" + "0.4.0": "1.5.0" }