Skip to content

Commit

Permalink
Merge pull request #55 from your-papa/dev
Browse files Browse the repository at this point in the history
Release 0.6.0
  • Loading branch information
Leo310 authored Mar 26, 2024
2 parents 82d3c65 + 214b4a7 commit 19339b5
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 233 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0",
"version": "0.5.1",
"minAppVersion": "1.5.0",
"isDesktopOnly": true
}
26 changes: 16 additions & 10 deletions src/SmartSecondBrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class SmartSecondBrain {
} catch (e) {
Log.error(e);
papaState.set('error');
// TODO add error state
errorState.set('failed-indexing');
new Notice(t('notice.failed_indexing'), 4000);
}

Expand Down Expand Up @@ -139,29 +139,26 @@ export default class SmartSecondBrain {

async runPapa() {
papaState.set('running');
const cH = get(chatHistory);
const userQuery = cH[cH.length - 1].content;
try {
const cH = get(chatHistory);
const userQuery = cH[cH.length - 1].content;
const responseStream = this.papa.run({
isRAG: get(data).isUsingRag,
userQuery,
chatHistory: serializeChatHistory(cH.slice(0, cH.length - 1)),
lang: get(data).assistantLanguage,
});

for await (const response of responseStream) {
runState.set(response.status);
runContent.set(response.content);
if (get(runState) === 'stopped') {
papaState.set('idle');
return; // when used break it somehow returns the whole function
}
}
} catch (error) {
Log.error(error);
const errorMsg = get(_)('notice.run_failed', { values: { error } });
// Log.error(errorMsg);
runContent.set(errorMsg);
// papaState.set('error');
// errorState.set('run-failed');
new Notice(get(_)('notice.failed_run', { values: { error } }), 4000);
new Notice(errorMsg, 4000);
}
papaState.set('idle');
}
Expand Down Expand Up @@ -214,6 +211,15 @@ export default class SmartSecondBrain {
if (this.papa) this.papa.setSimilarityThreshold(value);
}

stopRun() {
if (this.papa) this.papa.stopRun();
papaState.set('idle');
}

setNumOfDocsToRetrieve(k: number) {
if (this.papa) this.papa.setNumOfDocsToRetrieve(k);
}

setGenModel(genModel: GenModel) {
if (this.papa) this.papa.setGenModel(genModel);
}
Expand Down
60 changes: 18 additions & 42 deletions src/components/Chat/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
import InputComponent from './Input.svelte';
import QuickSettingsDrawer from './QuickSettingsDrawer.svelte';
import { Notice } from 'obsidian';
import { afterUpdate } from 'svelte';
import DotAnimation from '../base/DotAnimation.svelte';
import MessageContainer from './MessageContainer.svelte';
import { t } from 'svelte-i18n';
import {
papaState,
chatHistory,
isChatInSidebar,
chatInput,
isEditing,
isEditingAssistantMessage,
type ChatMessage,
runContent,
runState,
data,
} from '../../store';
import { papaState, chatHistory, chatInput, isEditing, isEditingAssistantMessage, type ChatMessage, runContent, runState, data } from '../../store';
import {
onClick,
onMouseOver,
Expand All @@ -41,9 +29,9 @@
}
let contentNode: HTMLElement;
afterUpdate(() => {
if (contentNode && $runState === 'generating' && $runContent) renderMarkdown(contentNode, $runContent);
});
$: if (contentNode && ($runState === 'generating' || $runState === 'stopped') && $runContent) {
renderMarkdown(contentNode, $runContent);
}
$: if ($runState === 'retrieving' && $runContent == '0') {
new Notice($t('notice.no_notes_retrieved'));
Expand Down Expand Up @@ -71,29 +59,22 @@

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<div class="--background-modifier-border flex h-full flex-col gap-1">
<QuickSettingsDrawer />
<div
bind:this={chatWindow}
on:scroll={() => (isAutoScrolling = chatWindow.scrollTop + chatWindow.clientHeight + 1 >= chatWindow.scrollHeight)}
class="chat-window w-full flex-grow select-text overflow-y-scroll rounded-md border border-solid border-[--background-modifier-border] {$isChatInSidebar
? 'bg-[--background-secondary]'
: 'bg-[--background-primary]'}"
class="chat-window w-full flex-grow select-text overflow-y-scroll rounded-md border border-solid border-[--background-modifier-border] bg-[--background-primary]"
>
{#each $chatHistory as message (message.id)}
<MessageContainer role={message.role}>
{#if message.role === 'User'}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<span bind:this={editElem} on:mouseover={onMouseOver} on:click={onClick} use:renderMarkdown={message.content} />
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="flex {$data.isChatComfy ? 'justify-end' : ''} gap-1 opacity-0 group-hover:opacity-100">
{#if $isEditing && editMessageId === message.id}
<span aria-label={$t('chat.copy')} class={iconStyle} on:click|preventDefault={cancelEditing} use:icon={'x-circle'} />
{:else}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<span
aria-label={$t('chat.edit')}
class={iconStyle}
Expand All @@ -103,18 +84,11 @@
{/if}
</div>
{:else}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<span on:mouseover={onMouseOver} use:renderMarkdown={message.content} on:click={onClick} bind:this={initialAssistantMessageSpan} />
<div class="flex gap-1 opacity-0 group-hover:opacity-100">
{#if !$isEditingAssistantMessage}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span aria-label={$t('chat.copy')} class={iconStyle} on:click={() => toClipboard(message.content)} use:icon={'copy'} />
{#if $chatHistory.indexOf(message) !== 0}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span
aria-label={$t('chat.regenerate')}
class={iconStyle}
Expand All @@ -123,8 +97,6 @@
/>
{/if}
{#if $chatHistory.length === 1}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span
aria-label={$t('chat.change_assistant_prompt')}
class={iconStyle}
Expand All @@ -133,16 +105,12 @@
/>
{/if}
{:else}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<span
aria-label={$t('chat.cancel_edit')}
class={iconStyle}
on:click|preventDefault={() => cancelEditingInitialAssistantMessage(initialAssistantMessageSpan)}
use:icon={'x-circle'}
/>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<span
aria-label={$t('chat.reset_assistant_prompt')}
class={iconStyle}
Expand All @@ -162,13 +130,21 @@
<p>{$t('chat.retrieving')}<DotAnimation /></p>
{:else if $runState === 'reducing'}
<p>{$t('chat.reducing', { values: { num: $runContent } })}<DotAnimation /></p>
{:else if $runState === 'generating' && $runContent}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
{:else if $runState === 'generating'}
<span bind:this={contentNode} style="background: transparent;" />
{/if}
</MessageContainer>
{:else if $papaState === 'idle' && $runState === 'stopped'}
<MessageContainer role="Assistant">
<span bind:this={contentNode} style="background: transparent;" />
<p>{$t('chat.stopped')}</p>
<span
aria-label={$t('chat.regenerate')}
class={iconStyle + ' opacity-0 group-hover:opacity-100'}
on:click|preventDefault={() => redoGeneration()}
use:icon={'refresh-cw'}
/>
</MessageContainer>
{/if}
</div>
<InputComponent bind:textarea />
Expand Down
17 changes: 6 additions & 11 deletions src/components/Chat/Input.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Notice, setIcon } from 'obsidian';
import { setIcon } from 'obsidian';
import { t } from 'svelte-i18n';
import {
plugin,
Expand All @@ -10,13 +10,12 @@
papaState,
papaIndexingProgress,
isChatInSidebar,
runState,
runContent,
isEditing,
} from '../../store';
import ProgressCircle from '../base/ProgressCircle.svelte';
import { addMessage } from '../../controller/Messages';
import Logo from '../base/Logo.svelte';
import Logo from '../Logos/LogoSimple.svelte';
export let textarea: HTMLTextAreaElement;
Expand Down Expand Up @@ -73,21 +72,19 @@
</script>

<!-- save delete and rag settings slightly above input field -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div class="relative">
<div
class="absolute -top-[62px] left-1/2 flex -translate-x-1/2 items-center gap-3 rounded-t-2xl border border-solid border-x-[--background-modifier-border] border-b-transparent border-t-[--background-modifier-border] {$isChatInSidebar
? 'bg-[--background-secondary]'
: 'bg-[--background-primary]'} pt-2 px-2"
>
{#if $chatHistory.length > 1}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div aria-label={$t('chat.save')} class={iconStyle} use:icon={'save'} on:click={() => $plugin.saveChat()} hidden={$papaState === 'running'} />
{/if}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
aria-label={$data.isUsingRag ? $t('chat.toggle_llm') : $t('chat.toggle_papa')}
aria-label={$data.isUsingRag ? $t('chat.toggle_papa') : $t('chat.toggle_llm')}
on:click={handleRAGToggle}
class={`h-[48px] w-[48px] *:!h-[48px] *:!w-[48px] hover:text-[--text-accent-hover] hover:scale-110 transform duration-300 ease-in-out ${
$data.isUsingRag ? 'text-[--color-accent]' : 'text-[--text-normal]'
Expand All @@ -96,8 +93,6 @@
<Logo />
</div>
{#if $chatHistory.length > 1}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
aria-label={$t('chat.delete')}
class={iconStyle}
Expand All @@ -120,7 +115,7 @@
{#if $papaState === 'running'}
<button
aria-label={$t('chat.stop')}
on:click={() => ($runState = 'stopped')}
on:click={() => $plugin.s2b.stopRun()}
class="h-8 rounded-r-md px-4 py-2 transition duration-300 ease-in-out hover:bg-[--text-accent-hover]"
use:icon={'stop-circle'}
/>
Expand Down
10 changes: 3 additions & 7 deletions src/components/Chat/MessageContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { data, isChatInSidebar } from '../../store';
import { data } from '../../store';
import { t } from 'svelte-i18n';
export let role: 'User' | 'Assistant';
Expand All @@ -20,15 +20,11 @@
</div>
{/if}
{:else if $data.isChatComfy}
<div class="group ml-4 mt-4 w-fit max-w-[80%] rounded-t-lg rounded-br-lg bg-[--background-primary-alt] px-4 pb-1 pt-[1px] [&_p]:mb-2">
<div class="group my-4 ml-4 w-fit max-w-[80%] rounded-t-lg rounded-br-lg bg-[--background-primary-alt] px-4 pb-1 pt-[1px] [&_p]:mb-2">
<slot />
</div>
{:else}
<div
class="group border-x-0 border-b border-t-0 border-solid border-[--background-modifier-border] p-2 pr-4 {$isChatInSidebar
? 'bg-[--background-secondary-alt]'
: 'bg-[--background-primary-alt]'}"
>
<div class="group border-x-0 border-b border-t-0 border-solid border-[--background-modifier-border] bg-[--background-primary-alt] p-2 pr-4">
<div class="mt-2 font-bold text-[--text-accent]">{$t('chat.assistant')}</div>
<slot />
</div>
Expand Down
Loading

0 comments on commit 19339b5

Please sign in to comment.