Files
moeka-project/services/minecraft/src/agents/openai.test.ts
T
2025-01-07 03:35:18 +08:00

53 lines
1.6 KiB
TypeScript

import { messages, system, user } from 'neuri/openai'
import { beforeAll, describe, expect, it } from 'vitest'
import { createBot, useBot } from '../composables/bot'
import { botConfig, initEnv } from '../composables/config'
import { genQueryAgentPrompt, genSystemBasicPrompt } from '../prompts/agent'
import { initLogger } from '../utils/logger'
import { initAgent } from './openai'
describe('openAI agent', { timeout: 10000 }, () => {
beforeAll(() => {
initLogger()
initEnv()
createBot(botConfig)
})
it('should initialize the agent', async () => {
const { ctx } = useBot()
const agent = await initAgent(ctx)
ctx.bot.once('spawn', async () => {
const text = await agent.handle(
messages(
system(genSystemBasicPrompt('airi')),
user('Hello, who are you?'),
),
async (c) => {
const completion = await c.reroute('query', c.messages, { model: 'openai/gpt-4o-mini' })
return await completion?.firstContent()
},
)
expect(text?.toLowerCase()).toContain('airi')
})
})
it('should choose right query command', async () => {
const { ctx } = useBot()
const agent = await initAgent(ctx)
ctx.bot.once('spawn', async () => {
const text = await agent.handle(messages(
system(genQueryAgentPrompt(ctx)),
user('What are you status?'),
), async (c) => {
const completion = await c.reroute('query', c.messages, { model: 'openai/gpt-4o-mini' })
return await completion?.firstContent()
})
expect(text?.toLowerCase()).toContain('position')
})
})
})