Skip to content

Commit

Permalink
Resolving merge conflicts with Task Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninot1Quyi committed Nov 4, 2024
1 parent 615af11 commit 82b37e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/agent/action_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class ActionManager {
console.error("Code execution triggered catch: " + err);
await this.stop();

let message = this._getBotOutputSummary() + '!!Code threw exception!! Error: ' + err;
err = err.toString();
let relevant_skill_docs = await this.agent.prompter.getRelevantSkillDocs(err,5);
let message = this._getBotOutputSummary() + '!!Code threw exception!! Error: ' + err+'\n'+relevant_skill_docs;
let interrupted = this.agent.bot.interrupt_code;
this.agent.clearBotLogs();
if (!interrupted && !this.agent.coder.generating) {
Expand Down
46 changes: 30 additions & 16 deletions src/agent/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,28 @@ export class Coder {
}

async checkCode(code) {
let result = '#### CODE ERROR INFO ###\n';
// Extract everything in the code between the beginning of 'skills./world.' and the '('
const skillRegex = /(?:skills|world)\.(.*?)\(/g;
const skills = [];
let match;
while ((match = skillRegex.exec(code)) !== null) {
skills.push(match[1]);
}
const allDocs = await this.agent.prompter.getRelevantSkillDocs();
//Check if the function exists
const missingSkills = skills.filter(skill => !allDocs.includes(skill));
if (missingSkills.length > 0) {
result += 'These functions do not exist. Please modify the correct function name and try again.\n';
result += '### FUNCTIONS NOT FOUND ###\n';
result += missingSkills.join('\n');
console.log(result)
return result;
}

const eslint = new ESLint();
const results = await eslint.lintText(code);
const codeLines = code.split('\n');
let result = '#### CODE ERROR INFO ###\n';
const exceptions = results.map(r => r.messages).flat();

if (exceptions.length > 0) {
Expand All @@ -40,10 +58,10 @@ export class Coder {
result += `#ERROR ${index + 1}\n`;
result += `Message: ${exc.message}\n`;
result += `Location: Line ${exc.line}, Column ${exc.column}\n`;
result += `Related Code Line: ${errorLine}\n\n`;
result += `Related Code Line: ${errorLine}\n`;
}
});
result += 'The code contains exceptions and cannot continue execution.\n';
result += 'The code contains exceptions and cannot continue execution.';
} else {
return null;//no error
}
Expand Down Expand Up @@ -172,14 +190,14 @@ export class Coder {
code = res.substring(res.indexOf('```')+3, res.lastIndexOf('```'));
const result = await this.stageCode(code);
const executionModuleExports = result.func;
let src_check_copy = result.src_check_copy;
const analysisResult = await this.checkCode(src_check_copy);
if (analysisResult) {
const message = 'Error: Code syntax error. Please try again:'+'\n'+analysisResult+'\n'+await this.agent.prompter.getRelevantSkillDocs(analysisResult,3);
messages.push({ role: 'system', content: message });
continue;
}
if (!executionModuleExports) {
let src_check_copy = result.src_check_copy;
const analysisResult = await this.checkCode(src_check_copy);
if (analysisResult) {
const message = 'Error: Code syntax error. Please try again:'+'\n'+analysisResult+'\n'+await this.agent.prompter.getRelevantSkillDocs(analysisResult,3);
messages.push({ role: 'system', content: message });
continue;
}
agent_history.add('system', 'Failed to stage code, something is wrong.');
return {success: false, message: null, interrupted: false, timedout: false};
}
Expand All @@ -189,10 +207,10 @@ export class Coder {
}, { timeout: settings.code_timeout_mins });
if (code_return.interrupted && !code_return.timedout)
return { success: false, message: null, interrupted: true, timedout: false };
console.log("Code generation result:", code_return.success, code_return.message);
console.log("Code generation result:", code_return.success, code_return.message.toString());

if (code_return.success) {
const summary = "Summary of newAction\nAgent wrote this code: \n```" + this.sanitizeCode(code) + "```\nCode Output:\n" + code_return.message;
const summary = "Summary of newAction\nAgent wrote this code: \n```" + this.sanitizeCode(code) + "```\nCode Output:\n" + code_return.message.toString();
return { success: true, message: summary, interrupted: false, timedout: false };
}

Expand All @@ -207,8 +225,4 @@ export class Coder {
}
return { success: false, message: null, interrupted: false, timedout: true };
}
//err = err.toString();
// let relevant_skill_docs = await this.agent.prompter.getRelevantSkillDocs(err,5);
// let message = this.formatOutput(this.agent.bot) + '!!Code threw exception!! Error: ' + err+'\n'+relevant_skill_docs;
//
}
9 changes: 6 additions & 3 deletions src/agent/prompter.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export class Prompter {
}

async getRelevantSkillDocs(message, select_num) {
let latest_message_embedding = await this.embedding_model.embed(message);
let latest_message_embedding = '';
if(message) //message is not empty, get the relevant skill docs, else return all skill docs
latest_message_embedding = await this.embedding_model.embed(message);

let skill_doc_similarities = Object.keys(this.skill_docs_embeddings)
.map(doc_key => ({
Expand All @@ -149,8 +151,9 @@ export class Prompter {
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.\nSkillDocs:\n';
relevant_skill_docs += selected_docs.map(doc => `${doc.doc_key}`).join('\n');
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');
return relevant_skill_docs;
}

Expand Down

0 comments on commit 82b37e0

Please sign in to comment.