From b9913dfa26848cd9db2ef73a9729124f0802cf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20St=C3=A9b=C3=A9?= Date: Fri, 29 Nov 2024 16:05:48 -0400 Subject: [PATCH] fix: remove the legacy "service" & fix some minor bugs --- example.env | 1 - src/gladdis.ts | 18 ++++++++++-------- src/obsidian.ts | 24 +++++++++++++----------- src/service.ts | 41 ----------------------------------------- src/tools/opendocsg.ts | 1 - src/tools/puppeteer.ts | 1 - src/utils/browser.ts | 4 ++-- 7 files changed, 25 insertions(+), 65 deletions(-) delete mode 100644 src/service.ts delete mode 100644 src/tools/opendocsg.ts delete mode 100644 src/tools/puppeteer.ts diff --git a/example.env b/example.env index 3c436f2..5de9abd 100644 --- a/example.env +++ b/example.env @@ -9,7 +9,6 @@ GLADDIS_TEMPERATURE=0 GLADDIS_TOP_P_PARAM=100 GLADDIS_FREQ_PENALTY=0 GLADDIS_PRES_PENALTY=0 -GLADDIS_SERVER_PORT=3000 GLADDIS_WHISPER_INPUT="Gladdis" #GLADDIS_WHISPER_CONFIG="Whisper" diff --git a/src/gladdis.ts b/src/gladdis.ts index eb9a48a..20deede 100644 --- a/src/gladdis.ts +++ b/src/gladdis.ts @@ -44,15 +44,17 @@ export async function doGladdis(context: Context): Promise { context.user.history.unshift({ role: 'system', content: corePrompt.trim() }) } - context.user.prompt = await transcribe(context.user.prompt, context) - context.user.prompt = await parseLinks(context.user.prompt, context) - context.user.prompt = await webBrowser(context.user.prompt, context) + if (context.user.prompt !== '') { + context.user.prompt = await transcribe(context.user.prompt, context) + context.user.prompt = await parseLinks(context.user.prompt, context) + context.user.prompt = await webBrowser(context.user.prompt, context) - context.user.history.push({ - role: 'user', - content: context.user.prompt, - name: context.user.label, - }) + context.user.history.push({ + role: 'user', + content: context.user.prompt, + name: context.user.label, + }) + } context = await callGladdis(context) diff --git a/src/obsidian.ts b/src/obsidian.ts index bb52283..a7e3333 100755 --- a/src/obsidian.ts +++ b/src/obsidian.ts @@ -86,10 +86,10 @@ interface GladdisSettings { GLADDIS_WHISPER_DELETE_FILE: string } -const DEFAULT_SETTINGS: GladdisSettings = { +const defaultSettings: GladdisSettings = { GLADDIS_DATA_PATH: 'Gladdis', GLADDIS_NAME_LABEL: 'Gladdis', - GLADDIS_DEFAULT_USER: 'User', + GLADDIS_DEFAULT_USER: 'Hooman', GLADDIS_DEFAULT_MODEL: 'gpt-4o-mini', GLADDIS_TEMPERATURE: '42', GLADDIS_TOP_P_PARAM: '100', @@ -103,7 +103,7 @@ const DEFAULT_SETTINGS: GladdisSettings = { } export default class GladdisPlugin extends Plugin { - settings: GladdisSettings = DEFAULT_SETTINGS + settings: GladdisSettings = defaultSettings secrets: Record = {} async onload(): Promise { @@ -191,8 +191,6 @@ export default class GladdisPlugin extends Plugin { }, }) - this.registerExtensions(['txt'], 'markdown') - this.addSettingTab(new GladdisSettingTab(this.app, this)) } @@ -215,7 +213,7 @@ export default class GladdisPlugin extends Plugin { } async loadSettings(): Promise { - this.settings = deepmerge(DEFAULT_SETTINGS, (await this.loadData()) ?? {}) + this.settings = deepmerge(defaultSettings, (await this.loadData()) ?? {}) } async saveSettings(): Promise { @@ -305,9 +303,10 @@ class VaultInterface implements DiskInterface { } } - // eslint-disable-next-line @typescript-eslint/require-await async pathExists(path: string): Promise { - return this.vault.getAbstractFileByPath(normalizePath(path)) !== null + return new Promise((resolve) => { + resolve(this.vault.getAbstractFileByPath(normalizePath(path)) !== null) + }) } async pathEnsure(path: string): Promise { @@ -440,7 +439,12 @@ class GladdisSettingTab extends PluginSettingTab { fragment.appendText(' or ') fragment.createEl('a', { href: 'https://ollama.com/library', - text: 'local model', + text: 'local', + }) + fragment.appendText(' ') + fragment.createEl('a', { + href: 'https://localai.io/gallery.html', + text: 'model', }) fragment.appendText(' from the ') fragment.createEl('a', { @@ -601,7 +605,6 @@ class GladdisSettingTab extends PluginSettingTab { .setName('Default "live" suffix') .setDesc('The default suffix, inserted after "on the fly" transcriptions.') .addText((text) => { - text.inputEl.style.width = '24ch' text.setValue(this.plugin.settings.GLADDIS_WHISPER_LIVE_SUFFIX).onChange(async (value) => { this.plugin.settings.GLADDIS_WHISPER_LIVE_SUFFIX = value await this.plugin.saveSettings() @@ -612,7 +615,6 @@ class GladdisSettingTab extends PluginSettingTab { .setName('Default "read" suffix') .setDesc('The default suffix, inserted after already seen transcriptions.') .addText((text) => { - text.inputEl.style.width = '24ch' text.setValue(this.plugin.settings.GLADDIS_WHISPER_READ_SUFFIX).onChange(async (value) => { this.plugin.settings.GLADDIS_WHISPER_READ_SUFFIX = value await this.plugin.saveSettings() diff --git a/src/service.ts b/src/service.ts deleted file mode 100644 index 09a03e1..0000000 --- a/src/service.ts +++ /dev/null @@ -1,41 +0,0 @@ -import 'dotenv/config' -import express from 'express' - -import { chatWithGladdis, processContent, processPrompt } from './commands.js' - -import type { Context } from './types/context.js' - -const app = express() - -app.use(express.json()) - -app.post('/chatWithGladdis', (req, res) => { - void (async () => { - await chatWithGladdis(req.body as Context) - })() - - res.status(200).end() -}) - -app.post('/processContent', (req, res) => { - void (async () => { - await processContent(req.body as Context) - })() - - res.status(200).end() -}) - -app.post('/processPrompt', (req, res) => { - void (async () => { - await processPrompt(req.body as Context) - })() - - res.status(200).end() -}) - -const name = process.env.GLADDIS_NAME_LABEL ?? 'Gladdis' -const port = Number(process.env.GLADDIS_SERVER_PORT ?? 3000) - -app.listen(port, () => { - console.log(`${name} is listening on port ${port} ...`) -}) diff --git a/src/tools/opendocsg.ts b/src/tools/opendocsg.ts deleted file mode 100644 index 498bca9..0000000 --- a/src/tools/opendocsg.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@opendocsg/pdf2md' diff --git a/src/tools/puppeteer.ts b/src/tools/puppeteer.ts deleted file mode 100644 index 69c08d7..0000000 --- a/src/tools/puppeteer.ts +++ /dev/null @@ -1 +0,0 @@ -export * from 'puppeteer-core' diff --git a/src/utils/browser.ts b/src/utils/browser.ts index 775c47d..9cec5b6 100644 --- a/src/utils/browser.ts +++ b/src/utils/browser.ts @@ -29,8 +29,8 @@ export async function webBrowser(content: string, context: Context): Promise