chore: slight change

This commit is contained in:
Neko Ayaka
2025-01-09 18:38:14 +08:00
parent d35e98c458
commit d94dfd4e8c
2 changed files with 7 additions and 10 deletions
@@ -38,8 +38,8 @@ export class Health {
} }
} }
abstract class OneLinerable { interface OneLinerable {
public abstract toOneLiner(): string toOneLiner: () => string
} }
export class Status implements OneLinerable { export class Status implements OneLinerable {
@@ -11,8 +11,7 @@ export function LLMAgent(options: { agent: Neuri }): MineflayerPlugin {
async created(bot) { async created(bot) {
const agent = options.agent const agent = options.agent
const logger = useLogg('aichat').useGlobalConfig() const logger = useLogg('LLMAgent').useGlobalConfig()
logger.log('Loading aichat plugin')
bot.memory.chatHistory.push(system(genActionAgentPrompt(bot))) 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}`)) bot.memory.chatHistory.push(user(`${username}: ${message}`))
const content = await agent.handleStateless([...bot.memory.chatHistory], async (c) => { const content = await agent.handleStateless([...bot.memory.chatHistory], async (c) => {
logger.log('Generate response') logger.log('thinking...')
try { try {
const completion = await c.reroute('action', c.messages, { model: 'openai/gpt-4o-mini' }) || { error: { message: 'Unknown error' } } 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) { if (!completion || 'error' in completion) {
logger.withFields(c).error('Completion') logger.withFields(c).error('Completion')
return return
@@ -37,17 +33,18 @@ export function LLMAgent(options: { agent: Neuri }): MineflayerPlugin {
} }
const content = await completion?.firstContent() const content = await completion?.firstContent()
logger.withFields({ usage: completion.usage, content }).log('output')
bot.memory.chatHistory.push(assistant(content)) bot.memory.chatHistory.push(assistant(content))
return content return content
} }
catch (e) { catch (e) {
logger.errorWithError('Generate response error', e) logger.errorWithError('failed to think of an action', e)
} }
}) })
if (content) { if (content) {
logger.withFields({ content }).log('Bot response') logger.withFields({ content }).log('responded')
bot.bot.chat(content) bot.bot.chat(content)
} }
}) })