fix: remove the legacy "service" & fix some minor bugs

This commit is contained in:
Aurélien Stébé 2024-11-29 16:05:48 -04:00
parent ea10229a7c
commit b9913dfa26
No known key found for this signature in database
GPG key ID: 0C0E6829C7E6B5AC
7 changed files with 25 additions and 65 deletions

View file

@ -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"

View file

@ -44,15 +44,17 @@ export async function doGladdis(context: Context): Promise<void> {
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)

View file

@ -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<string, string> = {}
async onload(): Promise<void> {
@ -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<void> {
this.settings = deepmerge(DEFAULT_SETTINGS, (await this.loadData()) ?? {})
this.settings = deepmerge(defaultSettings, (await this.loadData()) ?? {})
}
async saveSettings(): Promise<void> {
@ -305,9 +303,10 @@ class VaultInterface implements DiskInterface {
}
}
// eslint-disable-next-line @typescript-eslint/require-await
async pathExists(path: string): Promise<boolean> {
return this.vault.getAbstractFileByPath(normalizePath(path)) !== null
return new Promise((resolve) => {
resolve(this.vault.getAbstractFileByPath(normalizePath(path)) !== null)
})
}
async pathEnsure(path: string): Promise<void> {
@ -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()

View file

@ -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} ...`)
})

View file

@ -1 +0,0 @@
export * from '@opendocsg/pdf2md'

View file

@ -1 +0,0 @@
export * from 'puppeteer-core'

View file

@ -29,8 +29,8 @@ export async function webBrowser(content: string, context: Context): Promise<str
pageDoc.head.getElementsByTagName('base')[0].href = pageURL
const article = new Readability(pageDoc, options).parse() ?? { title: '', content: '' }
webPage = article.content.trim() !== '' ? turndown(article.content) : ''
if (article.title.trim() !== '') webPage = `# ${article.title}\n\n${webPage}`
webPage = article.content.trim() !== '' ? turndown(article.content).trim() : ''
if (article.title.trim() !== '') webPage = `# ${article.title.trim()}\n\n${webPage}`
} catch (error: unknown) {
await writeErrorModal(error, 'Web Page Browsing Error', context)
}