This commit is contained in:
parent
1d6736ebda
commit
1e239ef9ff
1 changed files with 11 additions and 5 deletions
|
|
@ -18,18 +18,24 @@ async function generateAndSaveTask(taskName, aiConfig) {
|
|||
You are an AI assistant in a Minecraft world. The player wants a new bot task called "${taskName}".
|
||||
Return only the Node.js code for a module that exports an async function with this signature:
|
||||
\`\`\`js
|
||||
module.exports = async function(bot, db, say) { ... }
|
||||
module.exports = async function(bot, db, say) {
|
||||
// Implement the logic here
|
||||
};
|
||||
\`\`\`
|
||||
The function should describe how to perform the task using mineflayer.
|
||||
Only respond with valid JavaScript and nothing else.
|
||||
Only return valid JavaScript. Do not include explanation or extra text.
|
||||
`.trim();
|
||||
|
||||
try {
|
||||
const response = await chatWithAI(prompt, aiConfig);
|
||||
const taskCode = response.trim();
|
||||
let taskCode = response.trim();
|
||||
|
||||
// Strip surrounding triple backticks if present
|
||||
if (taskCode.startsWith('```')) {
|
||||
taskCode = taskCode.replace(/```[a-z]*\n?/i, '').replace(/```$/, '').trim();
|
||||
}
|
||||
|
||||
if (!taskCode.includes('module.exports')) {
|
||||
throw new Error('AI response did not include a module export.');
|
||||
throw new Error('AI did not return a valid module.exports function.');
|
||||
}
|
||||
|
||||
const taskPath = path.join(__dirname, '../bot-tasks', `${taskName}.js`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue