mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-29 19:44:53 +02:00
Merge pull request #130 from Ninot1Quyi/main
Load sample text in parallel for faster loading
This commit is contained in:
commit
ce5bfbc3bc
2 changed files with 10 additions and 6 deletions
|
@ -93,12 +93,15 @@ export class Prompter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async initExamples() {
|
async initExamples() {
|
||||||
console.log('Loading examples...')
|
// Using Promise.all to implement concurrent processing
|
||||||
|
// Create Examples instances
|
||||||
this.convo_examples = new Examples(this.embedding_model);
|
this.convo_examples = new Examples(this.embedding_model);
|
||||||
await this.convo_examples.load(this.profile.conversation_examples);
|
|
||||||
this.coding_examples = new Examples(this.embedding_model);
|
this.coding_examples = new Examples(this.embedding_model);
|
||||||
await this.coding_examples.load(this.profile.coding_examples);
|
// Use Promise.all to load examples concurrently
|
||||||
console.log('Examples loaded.');
|
await Promise.all([
|
||||||
|
this.convo_examples.load(this.profile.conversation_examples),
|
||||||
|
this.coding_examples.load(this.profile.coding_examples),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async replaceStrings(prompt, messages, examples=null, prev_memory=null, to_summarize=[], last_goals=null) {
|
async replaceStrings(prompt, messages, examples=null, prev_memory=null, to_summarize=[], last_goals=null) {
|
||||||
|
|
|
@ -32,10 +32,11 @@ export class Examples {
|
||||||
async load(examples) {
|
async load(examples) {
|
||||||
this.examples = examples;
|
this.examples = examples;
|
||||||
if (this.model !== null) {
|
if (this.model !== null) {
|
||||||
for (let example of this.examples) {
|
const embeddingPromises = this.examples.map(async (example) => {
|
||||||
let turn_text = this.turnsToText(example);
|
let turn_text = this.turnsToText(example);
|
||||||
this.embeddings[turn_text] = await this.model.embed(turn_text);
|
this.embeddings[turn_text] = await this.model.embed(turn_text);
|
||||||
}
|
});
|
||||||
|
await Promise.all(embeddingPromises);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue