-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split init agent to composable/neuri
- Loading branch information
1 parent
8f1196e
commit 9d9ba91
Showing
4 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Agent, Neuri } from 'neuri' | ||
import type { Mineflayer } from '../libs/mineflayer' | ||
|
||
import { useLogg } from '@guiiai/logg' | ||
import { neuri } from 'neuri' | ||
|
||
import { initActionAgent } from '../agents/action/llm' | ||
import { openaiConfig } from './config' | ||
|
||
let neuriAgent: Neuri | undefined | ||
const agents = new Set<Agent | Promise<Agent>>() | ||
|
||
const logger = useLogg('action-llm').useGlobalConfig() | ||
|
||
export async function initNeuriAgent(mineflayer: Mineflayer): Promise<Neuri> { | ||
logger.log('Initializing agent') | ||
let n = neuri() | ||
|
||
agents.add(initActionAgent(mineflayer)) | ||
|
||
agents.forEach(agent => n = n.agent(agent)) | ||
|
||
neuriAgent = await n.build({ | ||
provider: { | ||
apiKey: openaiConfig.apiKey, | ||
baseURL: openaiConfig.baseUrl, | ||
}, | ||
}) | ||
|
||
return neuriAgent | ||
} | ||
|
||
export function getAgent(): Neuri { | ||
if (!neuriAgent) { | ||
throw new Error('Agent not initialized') | ||
} | ||
return neuriAgent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters