tasking creator updates
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 23s

This commit is contained in:
roberts 2025-05-10 20:03:01 -05:00
parent 866affe6b3
commit 1d6736ebda
2 changed files with 28 additions and 26 deletions

View file

@ -1,38 +1,40 @@
// lib/ai-helper.js
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const config = require('../config.json');
async function chatWithAI(message, overrides = {}) {
async function chatWithAI(prompt, aiConfig) {
const res = await axios.post(aiConfig.ollamaUrl, {
model: aiConfig.model,
prompt,
stream: false
});
const settings = { ...config.ai, ...overrides };
const prompt = `You are ${config.bot.name}, ${config.bot.persona}. Keep your responses around ${config.ai.responseLength} words. Respond to: ${message}`;
try {
const response = await axios.post(settings.ollamaUrl, {
model: settings.model,
prompt,
stream: false
});
return response.data.response?.trim() || '...';
} catch (err) {
console.error('[AI] Request failed:', err.message);
return 'Im confused.';
}
return res.data.response;
}
async function generateAndSaveTask(taskName, aiConfig = config.ai) {
const prompt = `Write a Mineflayer-compatible JavaScript task named "${taskName}".
The function should be defined as: module.exports = async function(bot, db, say) {...}
This task will be executed by an AI-powered Minecraft bot.
Do not include explanation, only the code.`;
async function generateAndSaveTask(taskName, aiConfig) {
const prompt = `
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) { ... }
\`\`\`
The function should describe how to perform the task using mineflayer.
Only respond with valid JavaScript and nothing else.
`.trim();
try {
const code = await chatWithAI(prompt, aiConfig);
const filePath = path.join(__dirname, '../bot-tasks', `${taskName}.js`);
fs.writeFileSync(filePath, code, 'utf8');
console.log(`[AI] Task file generated: ${filePath}`);
const response = await chatWithAI(prompt, aiConfig);
const taskCode = response.trim();
if (!taskCode.includes('module.exports')) {
throw new Error('AI response did not include a module export.');
}
const taskPath = path.join(__dirname, '../bot-tasks', `${taskName}.js`);
fs.writeFileSync(taskPath, taskCode);
console.log(`[AI] Task file generated: ${taskPath}`);
} catch (err) {
console.error('[TASK GENERATION ERROR]', err.message);
}

View file

@ -1,5 +1,5 @@
// states/Observe.js
const { getBot, getActiveTask, isCombatLocked, getStateMachine } = require('../core/context');
const { getBot, isCombatLocked, getActiveTask, getStateMachine, setCombatLock } = require('../core/context');
const logSurroundings = require('../lib/log-surroundings');
const { chatWithAI } = require('../lib/ai-helper');
const config = require('../config.json');