Skip to content

Commit

Permalink
new prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
nbonamy committed Oct 27, 2024
1 parent 602d623 commit 58ac7eb
Show file tree
Hide file tree
Showing 29 changed files with 426 additions and 361 deletions.
2 changes: 1 addition & 1 deletion build/build_number.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
310
319
2 changes: 1 addition & 1 deletion css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
--sidebar-scroll-thumb-color: var(--scrollbar-thumb-color);
--sidebar-icon-color: var(--icon-color);
--sidebar-selected-color: var(--highlight-color);
--sidebar-search-bg-color: rgb(44, 64, 84);
--sidebar-search-bg-color: rgb(64, 74, 84);
--sidebar-search-border-color: rgb(76, 96, 116);
--sidebar-section-title-color: var(--icon-color);

Expand Down
10 changes: 6 additions & 4 deletions defaults/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"firstRun": true,
"keepRunning": true,
"hideOnStartup": false,
"autoSavePrompt": false,
"language": "",
"tips": {
"trayIcon": true,
"engineSelector": true,
"modelSelector": true,
"scratchpad": true,
"conversation": true,
"computerUse": true
"computerUse": true,
"newPrompt": true
},
"confirm": {
"retryGeneration": true
Expand Down Expand Up @@ -67,10 +69,10 @@
"alt": true,
"ctrl": true
},
"anywhere": {
"key": "Space",
"prompt": {
"key": "P",
"shift": true,
"ctrl": true
"meta": true
},
"transcribe": {
"key": "Space",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "witsy",
"productName": "Witsy",
"version": "1.21.2",
"version": "1.22.0",
"description": "Witsy: desktop AI assistant",
"repository": {
"type": "git",
Expand Down
20 changes: 11 additions & 9 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<component :is="currentView" :extra="queryParams" :data-tint="tint"/>
<component :is="currentView" :extra="queryParams" />
</template>

<script setup>
Expand Down Expand Up @@ -36,7 +36,6 @@ const routes = {
}
const theme = ref('light')
const tint = ref('black')
const currentPath = ref(window.location.hash)
const currentView = computed(() => {
Expand All @@ -53,23 +52,26 @@ const queryParams = computed(() => {
return queryParams;
})
const loadTint = () => {
const config = window.api.config.load()
tint.value = config.appearance.tint || 'black'
const setTint = (tint) => {
if (!tint) {
const config = window.api.config.load()
tint = config.appearance.tint || 'black'
}
document.querySelector('body').setAttribute('data-tint', tint)
}
// add platform name
onMounted(() => {
// events
onEvent('appearance-tint-changed', (t) => {
tint.value = t
onEvent('appearance-tint-changed', (tint) => {
setTint(tint)
})
// config change may lead to tint change
window.api.on('file-modified', (signal) => {
if (signal === 'settings') {
loadTint()
setTint()
}
})
Expand All @@ -86,7 +88,7 @@ onMounted(() => {
// init theme
theme.value = appearanceTheme.getTheme()
loadTint()
setTint()
// watch for theme change
if (window.matchMedia) {
Expand Down
77 changes: 14 additions & 63 deletions src/automations/anywhere.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@

import { Configuration } from 'types/config.d'
import { App } from 'electron'
import { loadSettings } from '../main/config'
import { igniteEngine } from '../llms/llm'
import { removeMarkdown } from '@excalidraw/markdown-to-text'
import { LlmEngine, LlmResponse } from 'multi-llm-ts'
import Automator from './automator'
import Message from '../models/message'
import * as window from '../main/window'
import process from 'process'

export default class PromptAnywhere {

private llm: LlmEngine
private cancelled: boolean

constructor(llm?: LlmEngine) {
this.llm = llm
this.cancelled = false
}

cancel = async (): Promise<void> => {

// close stuff
await window.closeWaitingPanel();
await window.restoreWindows();
await window.releaseFocus();

// record
this.cancelled = true;

constructor() {
}

static initPrompt = async (): Promise<void> => {
Expand All @@ -53,43 +30,18 @@ export default class PromptAnywhere {
foremostApp: foremostApp
});
}

execPrompt = async (app: App, prompt: string): Promise<void> => {
static insert = async (app: App, response: string): Promise<void> => {

try {

// config
const config: Configuration = loadSettings(app);
const engine = config.llm.engine;
const model = config.getActiveModel();

// open waiting panel
window.openWaitingPanel();

// we need an llm
if (!this.llm) {
this.llm = igniteEngine(engine, config);
if (!this.llm) {
throw new Error(`Invalid LLM engine: ${engine}`)
}
}

// now prompt llm
console.debug(`Prompting with ${prompt.slice(0, 50)}…`);
const response = await this.promptLlm(model, prompt);
const result = removeMarkdown(response.content, {
const result = removeMarkdown(response, {
stripListLeaders: false,
listUnicodeChar: ''
});

// if cancelled
if (this.cancelled) {
console.debug('Discarding LLM output as command was cancelled');
return
}

// done
await window.closeWaitingPanel();
await window.closePromptAnywhere();
await window.releaseFocus();

// now paste
Expand All @@ -115,17 +67,16 @@ export default class PromptAnywhere {

}

private promptLlm = (model: string, prompt: string): Promise<LlmResponse> => {

// build messages
const messages: Message[] = [
new Message('user', prompt)
]
static continueAsChat = async (app: App, chatId: string): Promise<void> => {

// now get it
return this.llm.complete(messages, { model: model })
// done with this
await window.closePromptAnywhere();
await window.restoreWindows();
await window.releaseFocus();

// now open main
await window.openMainWindow({ queryParams: { chatId: chatId } });

}


}
}
2 changes: 1 addition & 1 deletion src/components/ChatList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defineExpose({
})
const visibleChats = computed(() => store.chats.filter((c) => {
if (c.title.toLowerCase().includes(props.filter.toLowerCase())) return true
if (c.title?.toLowerCase().includes(props.filter.toLowerCase())) return true
if (c.messages.some(m => m.content?.toLowerCase().includes(props.filter.toLowerCase()))) return true
return false
}).toSorted((a,b) => b.lastModified - a.lastModified))
Expand Down
21 changes: 19 additions & 2 deletions src/composables/tips_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Store } from 'types/index.d'
import Dialog from './dialog'

export type TipId = 'scratchpad' | 'conversation' | 'computerUse'
export type TipId = 'scratchpad' | 'conversation' | 'computerUse' | 'newPrompt'

class TipsManager {

Expand Down Expand Up @@ -30,7 +30,7 @@ class TipsManager {
return
}

const tipsToShow: TipId[] = [ 'scratchpad' ]
const tipsToShow: TipId[] = [ 'scratchpad', 'newPrompt' ]

for (const tip of tipsToShow) {
const shouldShow = this.store.config.general.tips[tip]
Expand All @@ -49,6 +49,7 @@ class TipsManager {
'scratchpad': this.showScratchpadTip,
'conversation': this.showConversationTip,
'computerUse': this.showComputerUseWarning,
'newPrompt': this.showNewPromptTip,
}

// get the callback
Expand Down Expand Up @@ -91,6 +92,22 @@ class TipsManager {
text: 'Use at your own risk!',
})
}

showNewPromptTip = () => {
Dialog.show({
title: 'The Prompt Anywhere feature has been completely redesigned and gives you faster than ever to Generative AI!',
text: 'Do you want to check it now? It is available in the Witsy menu when you need it!',
confirmButtonText: 'Yes!',
cancelButtonText: 'Later',
showCancelButton: true,
}).then((result: any) => {
if (result.isConfirmed) {
window.api.anywhere.prompt()
}
})

}

}

export default function useTipsManager(store: Store) {
Expand Down
56 changes: 9 additions & 47 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import * as menu from './main/menu';
import * as text from './main/text';

let commander: Commander = null
let anywhere: PromptAnywhere = null
let docRepo: DocumentRepository = null
//let onlineStorage: OnlineStorage = null
let nestor: Nestor = null
Expand Down Expand Up @@ -87,9 +86,9 @@ if (!process.mas) {
// this is going to be called later
const registerShortcuts = () => {
shortcuts.registerShortcuts(app, {
prompt: PromptAnywhere.initPrompt,
chat: window.openMainWindow,
command: Commander.initCommand,
anywhere: PromptAnywhere.initPrompt,
readaloud: ReadAloud.read,
transcribe: Transcriber.initTranscription,
scratchpad: window.openScratchPad,
Expand Down Expand Up @@ -128,6 +127,7 @@ app.whenReady().then(() => {
menu.installMenu(app, {
quit: app.quit,
checkForUpdates: autoUpdater.check,
newPrompt: PromptAnywhere.initPrompt,
newChat: window.openMainWindow,
newScratchpad: window.openScratchPad,
settings: window.openSettingsWindow,
Expand Down Expand Up @@ -430,58 +430,20 @@ ipcMain.on('code-python-run', async (event, payload) => {
}
})

ipcMain.on('anywhere-prompt', async (event, payload) => {

// if cancel on prompt window
await window.closePromptAnywhere();

// cancel previous
if (anywhere != null) {
await anywhere.cancel();
}

// do it
anywhere = new PromptAnywhere();
anywhere.execPrompt(app, JSON.parse(payload));

})

ipcMain.on('anywhere-resize', (_, height) => {
window.resizePromptAnywhere(height);
})

ipcMain.on('anywhere-show-experts', async () => {
await window.showExpertsPalette();
})

ipcMain.on('anywhere-close-experts', async () => {
await window.closeExpertsPalette();
})

ipcMain.on('anywhere-toggle-experts', async () => {
await window.toggleExpertsPalette();
})
ipcMain.on('anywhere-prompt', async () => {
await PromptAnywhere.initPrompt();
});

ipcMain.on('anywhere-is-experts-open', (event) => {
event.returnValue = window.isExpertsPaletteOpen();
ipcMain.on('anywhere-insert', async (event, payload) => {
await PromptAnywhere.insert(app, payload);
})

ipcMain.on('anywhere-on-expert', async (_, expertId) => {
await window.setPromptAnywhereExpertPrompt(JSON.parse(expertId));
await window.closeExpertsPalette();
ipcMain.on('anywhere-continue-as-chat', async (_, chatId) => {
await PromptAnywhere.continueAsChat(app, chatId);
})

ipcMain.on('anywhere-cancel', async () => {

// if cancel on prompt window
await window.closePromptAnywhere();

// if cancel on waiting panel
if (anywhere != null) {
console.log('Cancelling anywhere')
await anywhere.cancel();
anywhere = null;
}
})

ipcMain.on('readaloud-get-text', (event, payload) => {
Expand Down
Loading

0 comments on commit 58ac7eb

Please sign in to comment.