From e5e900c75dada870df180bf8dbd7d0b68950c7f4 Mon Sep 17 00:00:00 2001 From: MaxRobinsonTheGreat Date: Thu, 20 Mar 2025 21:33:35 -0500 Subject: [PATCH] fix dumb skill docs that were never working in the first place --- src/agent/library/skill_library.js | 46 +++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/agent/library/skill_library.js b/src/agent/library/skill_library.js index 370c60d..2728b93 100644 --- a/src/agent/library/skill_library.js +++ b/src/agent/library/skill_library.js @@ -8,6 +8,7 @@ export class SkillLibrary { this.embedding_model = embedding_model; this.skill_docs_embeddings = {}; this.skill_docs = null; + this.always_show_skills = ['skills.placeBlock', 'skills.wait'] } async initSkillLibrary() { const skillDocs = getSkillDocs(); @@ -26,6 +27,10 @@ export class SkillLibrary { this.embedding_model = null; } } + this.always_show_skills_docs = {}; + for (const skillName of this.always_show_skills) { + this.always_show_skills_docs[skillName] = this.skill_docs.find(doc => doc.includes(skillName)); + } } async getAllSkillDocs() { @@ -36,16 +41,24 @@ export class SkillLibrary { if(!message) // use filler message if none is provided message = '(no message)'; let skill_doc_similarities = []; - if (!this.embedding_model) { - skill_doc_similarities = Object.keys(this.skill_docs) + + if (select_num === -1) { + skill_doc_similarities = Object.keys(this.skill_docs_embeddings) + .map(doc_key => ({ + doc_key, + similarity_score: 0 + })); + } + else if (!this.embedding_model) { + skill_doc_similarities = Object.keys(this.skill_docs_embeddings) .map(doc_key => ({ doc_key, - similarity_score: wordOverlapScore(message, this.skill_docs[doc_key]) + similarity_score: wordOverlapScore(message, this.skill_docs_embeddings[doc_key]) })) .sort((a, b) => b.similarity_score - a.similarity_score); } else { - let latest_message_embedding = ''; + let latest_message_embedding = await this.embedding_model.embed(message); skill_doc_similarities = Object.keys(this.skill_docs_embeddings) .map(doc_key => ({ doc_key, @@ -55,15 +68,26 @@ export class SkillLibrary { } let length = skill_doc_similarities.length; - if (typeof select_num !== 'number' || isNaN(select_num) || select_num < 0) { + if (select_num === -1 || select_num > length) { select_num = length; - } else { - select_num = Math.min(Math.floor(select_num), length); } - let selected_docs = skill_doc_similarities.slice(0, select_num); - let relevant_skill_docs = '#### RELEVENT DOCS INFO ###\nThe following functions are listed in descending order of relevance.\n'; - relevant_skill_docs += 'SkillDocs:\n' - relevant_skill_docs += selected_docs.map(doc => `${doc.doc_key}`).join('\n### '); + // Get initial docs from similarity scores + let selected_docs = new Set(skill_doc_similarities.slice(0, select_num).map(doc => doc.doc_key)); + + // Add always show docs + Object.values(this.always_show_skills_docs).forEach(doc => { + if (doc) { + selected_docs.add(doc); + } + }); + + let relevant_skill_docs = '#### RELEVANT CODE DOCS ###\nThe following functions are available to use:\n'; + relevant_skill_docs += Array.from(selected_docs).join('\n### '); + + console.log('Selected skill docs:', Array.from(selected_docs).map(doc => { + const first_line_break = doc.indexOf('\n'); + return first_line_break > 0 ? doc.substring(0, first_line_break) : doc; + })); return relevant_skill_docs; } }