mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-04 07:35:19 +02:00
better example promise loading
This commit is contained in:
parent
68a2dccb76
commit
768d1da1bb
2 changed files with 21 additions and 20 deletions
|
@ -141,24 +141,18 @@ export class Prompter {
|
|||
}
|
||||
|
||||
async initExamples() {
|
||||
console.log('initializing examples...');
|
||||
try {
|
||||
this.convo_examples = new Examples(this.embedding_model);
|
||||
this.coding_examples = new Examples(this.embedding_model);
|
||||
|
||||
const [convoResult, codingResult] = await Promise.allSettled([
|
||||
// Wait for both examples to load before proceeding
|
||||
await Promise.all([
|
||||
this.convo_examples.load(this.profile.conversation_examples),
|
||||
this.coding_examples.load(this.profile.coding_examples)
|
||||
]);
|
||||
|
||||
// Handle potential failures
|
||||
if (convoResult.status === 'rejected') {
|
||||
console.error('Failed to load conversation examples:', convoResult.reason);
|
||||
throw convoResult.reason;
|
||||
}
|
||||
if (codingResult.status === 'rejected') {
|
||||
console.error('Failed to load coding examples:', codingResult.reason);
|
||||
throw codingResult.reason;
|
||||
}
|
||||
|
||||
console.log('done initializing examples.');
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize examples:', error);
|
||||
throw error;
|
||||
|
|
|
@ -31,19 +31,26 @@ export class Examples {
|
|||
|
||||
async load(examples) {
|
||||
this.examples = examples;
|
||||
if (!this.model) return; // Early return if no embedding model
|
||||
|
||||
try {
|
||||
if (this.model !== null) {
|
||||
const embeddingPromises = this.examples.map(async (example) => {
|
||||
let turn_text = this.turnsToText(example);
|
||||
this.embeddings[turn_text] = await this.model.embed(turn_text);
|
||||
});
|
||||
await Promise.all(embeddingPromises);
|
||||
}
|
||||
console.log('embedding examples...');
|
||||
// Create array of promises first
|
||||
const embeddingPromises = examples.map(example => {
|
||||
const turn_text = this.turnsToText(example);
|
||||
return this.model.embed(turn_text)
|
||||
.then(embedding => {
|
||||
this.embeddings[turn_text] = embedding;
|
||||
});
|
||||
});
|
||||
|
||||
// Wait for all embeddings to complete
|
||||
await Promise.all(embeddingPromises);
|
||||
console.log('done embedding examples.');
|
||||
} catch (err) {
|
||||
console.warn('Error with embedding model, using word overlap instead.');
|
||||
console.warn('Error with embedding model, using word overlap instead:', err);
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getRelevant(turns) {
|
||||
|
|
Loading…
Add table
Reference in a new issue