mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 06:15:32 +02:00
better wait skill and enable claude thinking
This commit is contained in:
parent
465a1c56fd
commit
f05b49fb20
2 changed files with 32 additions and 8 deletions
|
@ -111,16 +111,28 @@ export async function craftRecipe(bot, itemName, num=1) {
|
|||
return true;
|
||||
}
|
||||
|
||||
export async function wait(seconds) {
|
||||
export async function wait(bot, milliseconds) {
|
||||
/**
|
||||
* Waits for the given number of seconds.
|
||||
* @param {number} seconds, the number of seconds to wait.
|
||||
* Waits for the given number of milliseconds.
|
||||
* @param {MinecraftBot} bot, reference to the minecraft bot.
|
||||
* @param {number} milliseconds, the number of milliseconds to wait.
|
||||
* @returns {Promise<boolean>} true if the wait was successful, false otherwise.
|
||||
* @example
|
||||
* await skills.wait(10);
|
||||
* await skills.wait(bot, 1000);
|
||||
**/
|
||||
// setTimeout is disabled to prevent unawaited code, so this is a safe alternative
|
||||
await new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
||||
// setTimeout is disabled to prevent unawaited code, so this is a safe alternative that enables interrupts
|
||||
let timeLeft = milliseconds;
|
||||
let startTime = Date.now();
|
||||
|
||||
while (timeLeft > 0) {
|
||||
if (bot.interrupt_code) return false;
|
||||
|
||||
let waitTime = Math.min(2000, timeLeft);
|
||||
await new Promise(resolve => setTimeout(resolve, waitTime));
|
||||
|
||||
let elapsed = Date.now() - startTime;
|
||||
timeLeft = milliseconds - elapsed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,12 @@ export class Claude {
|
|||
try {
|
||||
console.log('Awaiting anthropic api response...')
|
||||
if (!this.params.max_tokens) {
|
||||
this.params.max_tokens = 4096;
|
||||
if (this.params.thinking?.budget_tokens) {
|
||||
this.params.max_tokens = this.params.thinking.budget_tokens + 1000;
|
||||
// max_tokens must be greater than thinking.budget_tokens
|
||||
} else {
|
||||
this.params.max_tokens = 16000;
|
||||
}
|
||||
}
|
||||
const resp = await this.anthropic.messages.create({
|
||||
model: this.model_name || "claude-3-sonnet-20240229",
|
||||
|
@ -32,7 +37,14 @@ export class Claude {
|
|||
});
|
||||
|
||||
console.log('Received.')
|
||||
res = resp.content[0].text;
|
||||
// get first content of type text
|
||||
const textContent = resp.content.find(content => content.type === 'text');
|
||||
if (textContent) {
|
||||
res = textContent.text;
|
||||
} else {
|
||||
console.warn('No text content found in the response.');
|
||||
res = 'No response from Claude.';
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
|
|
Loading…
Add table
Reference in a new issue