tasking creator updates
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 23s
All checks were successful
Deploy Cletus Bot / deploy (push) Successful in 23s
This commit is contained in:
parent
866affe6b3
commit
1d6736ebda
2 changed files with 28 additions and 26 deletions
|
|
@ -1,38 +1,40 @@
|
||||||
// lib/ai-helper.js
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const config = require('../config.json');
|
const config = require('../config.json');
|
||||||
|
|
||||||
async function chatWithAI(message, overrides = {}) {
|
async function chatWithAI(prompt, aiConfig) {
|
||||||
|
const res = await axios.post(aiConfig.ollamaUrl, {
|
||||||
const settings = { ...config.ai, ...overrides };
|
model: aiConfig.model,
|
||||||
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,
|
prompt,
|
||||||
stream: false
|
stream: false
|
||||||
});
|
});
|
||||||
return response.data.response?.trim() || '...';
|
|
||||||
} catch (err) {
|
return res.data.response;
|
||||||
console.error('[AI] Request failed:', err.message);
|
|
||||||
return 'Im confused.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateAndSaveTask(taskName, aiConfig = config.ai) {
|
async function generateAndSaveTask(taskName, aiConfig) {
|
||||||
const prompt = `Write a Mineflayer-compatible JavaScript task named "${taskName}".
|
const prompt = `
|
||||||
The function should be defined as: module.exports = async function(bot, db, say) {...}
|
You are an AI assistant in a Minecraft world. The player wants a new bot task called "${taskName}".
|
||||||
This task will be executed by an AI-powered Minecraft bot.
|
Return only the Node.js code for a module that exports an async function with this signature:
|
||||||
Do not include explanation, only the code.`;
|
\`\`\`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 {
|
try {
|
||||||
const code = await chatWithAI(prompt, aiConfig);
|
const response = await chatWithAI(prompt, aiConfig);
|
||||||
const filePath = path.join(__dirname, '../bot-tasks', `${taskName}.js`);
|
const taskCode = response.trim();
|
||||||
fs.writeFileSync(filePath, code, 'utf8');
|
|
||||||
console.log(`[AI] Task file generated: ${filePath}`);
|
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) {
|
} catch (err) {
|
||||||
console.error('[TASK GENERATION ERROR]', err.message);
|
console.error('[TASK GENERATION ERROR]', err.message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// states/Observe.js
|
// 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 logSurroundings = require('../lib/log-surroundings');
|
||||||
const { chatWithAI } = require('../lib/ai-helper');
|
const { chatWithAI } = require('../lib/ai-helper');
|
||||||
const config = require('../config.json');
|
const config = require('../config.json');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue