From d94dfd4e8c0f3d9fea837afdb948c29e0e2e249c Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Thu, 9 Jan 2025 17:50:38 +0800 Subject: [PATCH] chore: slight change --- services/minecraft/src/libs/mineflayer/index.ts | 4 ++-- services/minecraft/src/mineflayer/llm-agent.ts | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/services/minecraft/src/libs/mineflayer/index.ts b/services/minecraft/src/libs/mineflayer/index.ts index fcb6f9e28..8f3573a1f 100644 --- a/services/minecraft/src/libs/mineflayer/index.ts +++ b/services/minecraft/src/libs/mineflayer/index.ts @@ -38,8 +38,8 @@ export class Health { } } -abstract class OneLinerable { - public abstract toOneLiner(): string +interface OneLinerable { + toOneLiner: () => string } export class Status implements OneLinerable { diff --git a/services/minecraft/src/mineflayer/llm-agent.ts b/services/minecraft/src/mineflayer/llm-agent.ts index 93ea67862..f790ad4d6 100644 --- a/services/minecraft/src/mineflayer/llm-agent.ts +++ b/services/minecraft/src/mineflayer/llm-agent.ts @@ -11,8 +11,7 @@ export function LLMAgent(options: { agent: Neuri }): MineflayerPlugin { async created(bot) { const agent = options.agent - const logger = useLogg('aichat').useGlobalConfig() - logger.log('Loading aichat plugin') + const logger = useLogg('LLMAgent').useGlobalConfig() bot.memory.chatHistory.push(system(genActionAgentPrompt(bot))) @@ -23,13 +22,10 @@ export function LLMAgent(options: { agent: Neuri }): MineflayerPlugin { bot.memory.chatHistory.push(user(`${username}: ${message}`)) const content = await agent.handleStateless([...bot.memory.chatHistory], async (c) => { - logger.log('Generate response') + logger.log('thinking...') try { const completion = await c.reroute('action', c.messages, { model: 'openai/gpt-4o-mini' }) || { error: { message: 'Unknown error' } } - - logger.withFields({ completion }).log('Completion') - if (!completion || 'error' in completion) { logger.withFields(c).error('Completion') return @@ -37,17 +33,18 @@ export function LLMAgent(options: { agent: Neuri }): MineflayerPlugin { } const content = await completion?.firstContent() + logger.withFields({ usage: completion.usage, content }).log('output') bot.memory.chatHistory.push(assistant(content)) return content } catch (e) { - logger.errorWithError('Generate response error', e) + logger.errorWithError('failed to think of an action', e) } }) if (content) { - logger.withFields({ content }).log('Bot response') + logger.withFields({ content }).log('responded') bot.bot.chat(content) } })