Skip to content

Commit

Permalink
fix: run the "parseLinks" utils in parallel with "Promise.all"
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienStebe committed Mar 13, 2024
1 parent 6e1ab98 commit 4f851a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/commands.ts
Expand Up @@ -66,9 +66,11 @@ export async function processContent(context: Context): Promise<void> {
context.whisper.echoOutput = true
context.whisper.deleteFile = false

for (const message of context.user.history) {
message.content = await parseLinks(message.content, context)
}
await Promise.all(
context.user.history.map(async (message) => {
message.content = await parseLinks(message.content, context)
}),
)

context.user.prompt = await parseLinks(context.user.prompt, context)
context.user.prompt = await transcribe(context.user.prompt, context)
Expand Down
12 changes: 8 additions & 4 deletions src/gladdis.ts
Expand Up @@ -25,9 +25,11 @@ export async function doGladdis(context: Context): Promise<void> {
delete chatContext.gladdis
delete chatContext.whisper

for (const message of context.user.history) {
message.content = await parseLinks(message.content, context)
}
await Promise.all(
context.user.history.map(async (message) => {
message.content = await parseLinks(message.content, context)
}),
)

const corePrompt = context.user.env.GLADDIS_CORE_PROMPT ?? defaultCorePrompt
const metaPrompt = context.user.env.GLADDIS_META_PROMPT ?? defaultMetaPrompt
Expand All @@ -37,7 +39,9 @@ export async function doGladdis(context: Context): Promise<void> {
context.user.history.unshift({ role: 'system', content: metadata })
}

context.user.history.unshift({ role: 'system', content: corePrompt })
if (corePrompt.trim() !== '') {
context.user.history.unshift({ role: 'system', content: corePrompt.trim() })
}

context.user.prompt = await parseLinks(context.user.prompt, context)
context.user.prompt = await transcribe(context.user.prompt, context)
Expand Down
8 changes: 5 additions & 3 deletions src/obsidian.ts
Expand Up @@ -76,9 +76,11 @@ export default class GladdisPlugin extends Plugin {
context.whisper.echoOutput = true
context.whisper.deleteFile = false

for (const message of context.user.history) {
message.content = await parseLinks(message.content, context)
}
await Promise.all(
context.user.history.map(async (message) => {
message.content = await parseLinks(message.content, context)
}),
)

context.user.prompt = await parseLinks(context.user.prompt, context)
context.user.prompt = await transcribe(context.user.prompt, context)
Expand Down

0 comments on commit 4f851a7

Please sign in to comment.