diff --git a/.env b/.env index 0983d60..0380bee 100644 --- a/.env +++ b/.env @@ -1,5 +1,7 @@ OPENAI_API_BASEURL='' OPENAI_API_KEY='' +OPENAI_MODEL='deepseek-chat' +OPENAI_REASONING_MODEL='deepseek-reasoner' BOT_USERNAME='' BOT_HOSTNAME='' diff --git a/src/agents/action/llm-handler.test.ts b/src/agents/action/llm-handler.test.ts index 56e9f6d..8568e10 100644 --- a/src/agents/action/llm-handler.test.ts +++ b/src/agents/action/llm-handler.test.ts @@ -2,7 +2,7 @@ import { messages, system, user } from 'neuri/openai' import { beforeAll, describe, expect, it } from 'vitest' import { initBot, useBot } from '../../composables/bot' -import { botConfig, initEnv } from '../../composables/config' +import { botConfig, initEnv, openaiConfig } from '../../composables/config' import { createNeuriAgent } from '../../composables/neuri' import { initLogger } from '../../utils/logger' import { generateSystemBasicPrompt } from '../prompt/llm-agent.plugin' @@ -26,7 +26,7 @@ describe('openAI agent', { timeout: 0 }, () => { user('Hello, who are you?'), ), async (c) => { - const completion = await c.reroute('query', c.messages, { model: 'openai/gpt-4o-mini' }) + const completion = await c.reroute('query', c.messages, { model: openaiConfig.model }) return await completion?.firstContent() }, ) diff --git a/src/agents/action/tools.test.ts b/src/agents/action/tools.test.ts index a3aac85..fe166a6 100644 --- a/src/agents/action/tools.test.ts +++ b/src/agents/action/tools.test.ts @@ -2,7 +2,7 @@ import { messages, system, user } from 'neuri/openai' import { beforeAll, describe, expect, it } from 'vitest' import { initBot, useBot } from '../../composables/bot' -import { botConfig, initEnv } from '../../composables/config' +import { botConfig, initEnv, openaiConfig } from '../../composables/config' import { createNeuriAgent } from '../../composables/neuri' import { sleep } from '../../utils/helper' import { initLogger } from '../../utils/logger' @@ -25,7 +25,7 @@ describe('actions agent', { timeout: 0 }, () => { system(generateActionAgentPrompt(bot)), user('What\'s your status?'), ), async (c) => { - const completion = await c.reroute('query', c.messages, { model: 'openai/gpt-4o-mini' }) + const completion = await c.reroute('query', c.messages, { model: openaiConfig.model }) return await completion?.firstContent() }) @@ -46,7 +46,7 @@ describe('actions agent', { timeout: 0 }, () => { system(generateActionAgentPrompt(bot)), user('goToPlayer: luoling8192'), ), async (c) => { - const completion = await c.reroute('action', c.messages, { model: 'openai/gpt-4o-mini' }) + const completion = await c.reroute('action', c.messages, { model: openaiConfig.model }) return await completion?.firstContent() }) diff --git a/src/agents/chat/llm.ts b/src/agents/chat/llm.ts index 6659db1..0d77579 100644 --- a/src/agents/chat/llm.ts +++ b/src/agents/chat/llm.ts @@ -5,6 +5,7 @@ import { useLogg } from '@guiiai/logg' import { agent } from 'neuri' import { system, user } from 'neuri/openai' +import { openaiConfig } from '../../composables/config' import { toRetriable } from '../../utils/helper' import { genChatAgentPrompt } from '../prompt/chat' @@ -42,7 +43,7 @@ export async function generateChatResponse( const handleCompletion = async (c: any): Promise => { const completion = await c.reroute('chat', c.messages, { - model: config.model ?? 'openai/gpt-4o-mini', + model: config.model ?? openaiConfig.model, }) if (!completion || 'error' in completion) { diff --git a/src/composables/config.ts b/src/composables/config.ts index 6076dc5..81c7ec3 100644 --- a/src/composables/config.ts +++ b/src/composables/config.ts @@ -10,6 +10,7 @@ interface OpenAIConfig { apiKey: string baseUrl: string model: string + reasoningModel: string } interface EnvConfig { @@ -22,7 +23,8 @@ const defaultConfig: EnvConfig = { openai: { apiKey: '', baseUrl: '', - model: 'openai/gpt-4o-mini', + model: '', + reasoningModel: '', }, bot: { username: '', @@ -46,6 +48,7 @@ export function initEnv(): void { apiKey: env.OPENAI_API_KEY || defaultConfig.openai.apiKey, baseUrl: env.OPENAI_API_BASEURL || defaultConfig.openai.baseUrl, model: env.OPENAI_MODEL || defaultConfig.openai.model, + reasoningModel: env.OPENAI_REASONING_MODEL || defaultConfig.openai.reasoningModel, }, bot: { username: env.BOT_USERNAME || defaultConfig.bot.username, diff --git a/src/plugins/llm-agent.ts b/src/plugins/llm-agent.ts index e05bde2..de727d5 100644 --- a/src/plugins/llm-agent.ts +++ b/src/plugins/llm-agent.ts @@ -9,6 +9,7 @@ import { useLogg } from '@guiiai/logg' import { assistant, system, user } from 'neuri/openai' import { generateActionAgentPrompt, generateStatusPrompt } from '../agents/prompt/llm-agent.plugin' +import { openaiConfig } from '../composables/config' import { createAppContainer } from '../container' import { ChatMessageHandler } from '../libs/mineflayer/message' import { toRetriable } from '../utils/helper' @@ -28,7 +29,7 @@ async function handleLLMCompletion(context: NeuriContext, bot: MineflayerWithAge logger.log('rerouting...') const completion = await context.reroute('action', context.messages, { - model: 'openai/gpt-4o-mini', + model: openaiConfig.model, }) as ChatCompletion | { error: { message: string } } & ChatCompletion if (!completion || 'error' in completion) { @@ -145,7 +146,7 @@ export function LLMAgent(options: LLMAgentOptions): MineflayerPlugin { // Create container and get required services const container = createAppContainer({ neuri: options.agent, - model: 'openai/gpt-4o-mini', + model: openaiConfig.model, maxHistoryLength: 50, idleTimeout: 5 * 60 * 1000, })