feat: global configurable model and reasoning model

This commit is contained in:
RainbowBird
2025-01-28 16:18:20 +08:00
parent b804f687cd
commit 8a5795cac6
5 changed files with 14 additions and 9 deletions
@@ -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()
},
)
@@ -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()
})
+2 -1
View File
@@ -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<string> => {
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) {
+4 -1
View File
@@ -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,
+3 -2
View File
@@ -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,
})