Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.
TypeScript ai-meeting-assistantai-notetakerelectrongranola-alternativelinuxllama-cpplocal-ailocal-firstmacosmcpmeeting-minutesmeeting-notesoffline-firstopen-sourceprivacyspeech-to-texttranscriptionwhisperwhisper-cppwindows
The notes engine's memory and fallback lines go to main.log, and the embedding model goes straight to the processor when the card is full (#190)
christianmata8e4d8b5df24
diff --git a/app/src/engine/llm.ts b/app/src/engine/llm.tsindex 157ab7f9..63ada10d 100644--- a/app/src/engine/llm.ts+++ b/app/src/engine/llm.ts@@ -10,11 +10,18 @@ import { outOfGraphicsMemory, type EngineMessage } from '../shared/engine-protocconst toHistory = (messages: EngineMessage[]): ChatHistoryItem[] =>messages.map((m) => (m.role === 'system' ? { type: 'system', text: m.content } : m.role === 'user' ? { type: 'user', text: m.content } : { type: 'model', response: [m.content] }))+/** where the engine's own lines go: the worker sends them to main.log (a utility process's console reaches only a terminal) */+export type EngineLog = (level: 'info' | 'warn', text: string) => void+const toConsole: EngineLog = (level, text) => console[level](text)+/*** The notes model itself: load, count tokens, write. Used by the worker process. Callers run one thing at a time (the worker's serial()).+ * log: only Yogurt's own lines about memory and fallbacks, never meeting text.*/-export function createLlm(o: { platform?: string } = {}) {+export function createLlm(o: { platform?: string; log?: EngineLog } = {}) {const platform = o.platform ?? process.platform+ const log = o.log ?? toConsole+ const warn = (text: string, e: unknown) => log('warn', `${text} (${(e as Error).message})`)let llama: Llama | undefined/** the processor alone, when the graphics have no room at all (#57) */let cpuLlama: Llama | undefined@@ -34,7 +41,7 @@ export function createLlm(o: { platform?: string } = {}) {if (!l.gpu) return lfound = await l.getVramState()const cap = vramCap(found, platform)- if (cap !== null) { await l.setVramCap(cap); console.info(`notes engine: plans for ${(cap / 1024 ** 3).toFixed(1)} GiB of graphics memory`) }+ if (cap !== null) { await l.setVramCap(cap); log('info', `notes engine: plans for ${(cap / 1024 ** 3).toFixed(1)} GiB of graphics memory`) }return l}const getL = async (): Promise<Llama> => {@@ -74,16 +81,16 @@ export function createLlm(o: { platform?: string } = {}) {if (embedder?.path !== modelPath) {await unloadEmbed()const l = await getL()- // The notes model can fill the card first (#190): then the same steps as load(), with no layers on the card, then- // the processor alone. A 300M model is quick there.- const steps: { cpu?: true; gpuLayers?: 0 }[] = [{}, { gpuLayers: 0 }, ...(l.gpu ? [{ cpu: true as const }] : [])]+ // The notes model can fill the card first (#190): then the processor alone, where a 300M model is quick. No layers+ // on the card is no help: node-llama-cpp still plans the context and its buffers on a card with no room left.+ const steps: { cpu?: true }[] = [{}, ...(l.gpu ? [{ cpu: true as const }] : [])]for (const [i, step] of steps.entries()) {const last = i === steps.length - 1const used = step.cpu ? (cpuLlama ??= await getLlama({ gpu: false })) : llet model: LlamaModel- try { model = await used.loadModel(step.gpuLayers === undefined ? { modelPath } : { modelPath, gpuLayers: 0 }) } catch (e) {+ try { model = await used.loadModel({ modelPath }) } catch (e) {if (last) throw e- console.warn('the embedding model did not load; loading it again with fewer layers on the graphics', (e as Error).message)+ warn('the embedding model did not load on the graphics; loading it again on the processor', e)continue}try {@@ -96,7 +103,7 @@ export function createLlm(o: { platform?: string } = {}) {} catch (e) {await model.dispose()if (last || !(e instanceof InsufficientMemoryError || outOfGraphicsMemory((e as Error).message))) throw e- console.warn('the embedding model did not fit on the graphics; loading it again with fewer layers there', (e as Error).message)+ warn('the embedding model did not fit on the graphics; loading it again on the processor', e)}}if (!embedder) throw new Error('The embedding model did not load')@@ -129,12 +136,12 @@ export function createLlm(o: { platform?: string } = {}) {used = step.cpu ? (cpuLlama ??= await getLlama({ gpu: false })) : ltry { model = await used.loadModel(step.gpuLayers === undefined ? { modelPath } : { modelPath, gpuLayers: step.gpuLayers }) } catch (e) {if (last) throw e- console.warn('the notes model did not load; loading it again with fewer layers on the graphics', (e as Error).message)+ warn('the notes model did not load; loading it again with fewer layers on the graphics', e)continue}try { context = await model.createContext({ contextSize: size, ...threads(used) }) } catch (e) {if (!(e instanceof InsufficientMemoryError) || last) throw e- console.warn('the notes did not fit next to the model; loading it again with fewer layers on the graphics', e.message)+ warn('the notes did not fit next to the model; loading it again with fewer layers on the graphics', e)await model.dispose(); model = undefinedcontinue}@@ -143,7 +150,7 @@ export function createLlm(o: { platform?: string } = {}) {// can run out of memory only now, as it first computes (#165): fewer layers again.try { await main.evaluateWithoutGeneratingNewTokens(model.tokenize('Hello')); break } catch (e) {if (!outOfGraphicsMemory((e as Error).message) || last) throw e- console.warn('the graphics card ran out of memory reading in; loading it again with fewer layers on the graphics', (e as Error).message)+ warn('the graphics card ran out of memory reading in; loading it again with fewer layers on the graphics', e)main = undefinedawait context.dispose(); context = undefinedawait model.dispose(); model = undefineddiff --git a/app/src/engine/worker.ts b/app/src/engine/worker.tsindex 6e656f11..7490a8ce 100644--- a/app/src/engine/worker.ts+++ b/app/src/engine/worker.ts@@ -1,7 +1,8 @@import { createLlm } from './llm'import { createHandler } from './handler'-import type { EngineRequest } from '../shared/engine-protocol'+import type { EngineEvent, EngineRequest } from '../shared/engine-protocol'/** The notes model's process: requests from the main process (src/main/engine.ts) */-const handle = createHandler(createLlm(), (e) => process.parentPort.postMessage(e))+const send = (e: EngineEvent) => process.parentPort.postMessage(e)+const handle = createHandler(createLlm({ log: (level, text) => send({ type: 'log', level, text }) }), send)process.parentPort.on('message', ({ data }: { data: EngineRequest }) => { void handle(data) })diff --git a/app/src/main/engine.ts b/app/src/main/engine.tsindex 4e89d6e5..70e6e22f 100644--- a/app/src/main/engine.ts+++ b/app/src/main/engine.ts@@ -171,6 +171,7 @@ export class UtilityEngine implements Engine {const proc = utilityProcess.fork(this.workerPath, [], { serviceName: 'Yogurt Notes', ...(env ? { env } : {}) })this.loaded = falseproc.on('message', (e: EngineEvent) => {+ if (e.type === 'log') { console[e.level]('NOTES', e.text); return }const p = this.pending.get(e.id)if (!p) return// thinking is never shown: only the answer streams. Any token (thinking too) means the model is writing.diff --git a/app/src/shared/engine-protocol.ts b/app/src/shared/engine-protocol.tsindex c180576d..1706512c 100644--- a/app/src/shared/engine-protocol.ts+++ b/app/src/shared/engine-protocol.ts@@ -33,3 +33,5 @@ export type EngineEvent =/** where a reply's time went, for the log */| { id: number; type: 'timing'; text: string }| { id: number; type: 'error'; message: string; code?: 'OOM' }+ /** a line for main.log (a utility process's own console reaches only a terminal): memory and fallbacks, never meeting text */+ | { type: 'log'; level: 'info' | 'warn'; text: string }diff --git a/app/test/engineHandler.test.ts b/app/test/engineHandler.test.tsindex b2f55f85..36423f9b 100644--- a/app/test/engineHandler.test.ts+++ b/app/test/engineHandler.test.ts@@ -93,6 +93,6 @@ describe('holds: does the model already hold this text', () => {const c = handle({ id: 3, type: 'unload-embed' })await Promise.all([a, b, c])expect(order).toEqual(['embed /m/e.gguf', 'load', 'unload embed'])- expect(sent.find((e) => e.id === 1)).toEqual({ id: 1, type: 'result', data: [[2, 0], [4, 0]] })+ expect(sent.find((e) => 'id' in e && e.id === 1)).toEqual({ id: 1, type: 'result', data: [[2, 0], [4, 0]] })})})diff --git a/app/test/engineWatchdog.test.ts b/app/test/engineWatchdog.test.tsindex 8e36402e..cbda8bce 100644--- a/app/test/engineWatchdog.test.ts+++ b/app/test/engineWatchdog.test.ts@@ -193,3 +193,14 @@ describe('Linux: big allocations kept away from Electron\'s allocator (#32)', ()expect(procs[0].env).toBeUndefined()})})++describe('the engine\'s own lines reach main.log (#190)', () => {+ it('a warning or info line from the worker is logged in main, tagged NOTES', () => {+ const e = new UtilityEngine('engine.js', { gpuFallback: true, ...limits })+ void e.count(['a']).catch(() => {})+ procs[0].emit('message', { type: 'log', level: 'warn', text: 'the embedding model did not fit on the graphics' })+ procs[0].emit('message', { type: 'log', level: 'info', text: 'notes engine: plans for 14.7 GiB of graphics memory' })+ expect(console.warn).toHaveBeenCalledWith('NOTES', 'the embedding model did not fit on the graphics')+ expect(console.info).toHaveBeenCalledWith('NOTES', 'notes engine: plans for 14.7 GiB of graphics memory')+ })+})diff --git a/app/test/llm.test.ts b/app/test/llm.test.tsindex 50b253cc..36cbaeac 100644--- a/app/test/llm.test.ts+++ b/app/test/llm.test.ts@@ -142,26 +142,38 @@ describe('the embedding model when the card is full (#190)', () => {expect(await createLlm().embed('embed.gguf', ['a'])).toEqual([[1, 2]])expect(fake.loads).toEqual([undefined])})- it('its context not fitting next to the notes model: loaded again with no layers on the card', async () => {+ // no layers on a full card still failed the same way (node-llama-cpp checks the card's room even then): straight to the processor+ it('its context not fitting next to the notes model: the processor alone', async () => {fake.embedFails = 1expect(await createLlm().embed('embed.gguf', ['a', 'b'])).toEqual([[1, 2], [1, 2]])- expect(fake.loads).toEqual([undefined, 0])- expect(fake.disposed).toBe(1)- })- it('graphics that have no room even with no layers on them: the processor alone', async () => {- fake.embedFails = 2- expect(await createLlm().embed('embed.gguf', ['a'])).toEqual([[1, 2]])- expect(fake.loads).toEqual([undefined, 0, undefined])+ expect(fake.loads).toEqual([undefined, undefined])expect(fake.llamas.at(-1)).toEqual({ gpu: false })+ expect(fake.disposed).toBe(1)})- it('a model that fails to load on the card: fewer layers', async () => {+ it('a model that fails to load on the card: the processor alone', async () => {fake.loadFails = 1expect(await createLlm().embed('embed.gguf', ['a'])).toEqual([[1, 2]])- expect(fake.loads).toEqual([undefined, 0])+ expect(fake.loads).toEqual([undefined, undefined])+ expect(fake.llamas.at(-1)).toEqual({ gpu: false })})- it('running out of memory at the first text: loaded again with fewer layers', async () => {+ it('running out of memory at the first text: the processor alone', async () => {fake.embedReadFails = 1expect(await createLlm().embed('embed.gguf', ['a'])).toEqual([[1, 2]])- expect(fake.loads).toEqual([undefined, 0])+ expect(fake.loads).toEqual([undefined, undefined])+ expect(fake.llamas.at(-1)).toEqual({ gpu: false })+ })+})++describe('what the engine says goes to the log it is given (main.log, #190)', () => {+ it('the fallback and the graphics memory it plans for', async () => {+ fake.vram = { total: 16 * 1024 ** 3, unifiedSize: 0 }+ fake.embedFails = 1+ const lines: [string, string][] = []+ await createLlm({ platform: 'linux', log: (level, text) => lines.push([level, text]) }).embed('embed.gguf', ['a'])+ expect(lines.map(([l, t]) => [l, t.split(' (')[0].split(';')[0]])).toEqual([+ ['info', expect.stringMatching(/^notes engine: plans for [\d.]+ GiB of graphics memory$/)],+ ['warn', 'the embedding model did not fit on the graphics'],+ ])+ expect(lines[1][1]).toContain('A context size of 2048 is too large')})})