Skip to content

Commit

Permalink
feat(brainCommand): add refresh flag option
Browse files Browse the repository at this point in the history
  • Loading branch information
snowyu committed Jun 11, 2024
1 parent e3c1e51 commit 129dd3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/lib/brain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import EventEmitter from 'events'
EventEmitter.defaultMaxListeners = 1000

// note: need initTools() first
export function upgradeBrains() {
const brains = ToolFunc.get(BRAINS_FUNC_NAME) as LlmModelsFunc
brains.updateDBFromDir()
}

export function listBrains(userConfig: any, flags: any) {
const brainDir = userConfig.brainDir
const result: any[] = searchBrains(brainDir, flags)
Expand Down
9 changes: 8 additions & 1 deletion src/oclif/commands/brain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { initTools } from '../../../lib/init-tools.js'
import { AICommand } from '../../lib/ai-command.js'
import { showBanner } from '../../lib/help.js'
import { parseJsJson } from '@isdk/ai-tool'
import { listBrains, printBrains } from '../../../lib/brain.js'
import { listBrains, printBrains, upgradeBrains } from '../../../lib/brain.js'

export default class Brain extends AICommand {
static args = {
Expand All @@ -25,6 +25,10 @@ export default class Brain extends AICommand {
description: 'the max number of brains to list, 0 means all.',
default: 100,
}),
refresh: Flags.boolean({
char: 'r',
description: 'refresh the online brains list',
}),
}

static summary = '🧠 The AI Agent Brains(LLM) Manager.'
Expand All @@ -50,6 +54,9 @@ export default class Brain extends AICommand {
const {args, flags} = opts
const userConfig = this.loadConfig(flags.config, opts)
initTools(userConfig)
if (flags.refresh) {
upgradeBrains()
}

if (userConfig.banner && !isJson) {showBanner('Brain')}
flags.name = args.name
Expand Down
10 changes: 9 additions & 1 deletion src/oclif/commands/brain/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import util from 'util'
import { parseJsJson } from '@isdk/ai-tool'
import { listBrains, printBrains } from '../../../lib/brain.js'
import { listBrains, printBrains, upgradeBrains } from '../../../lib/brain.js'
import { initTools } from '../../../lib/init-tools.js'
import { AICommand } from '../../lib/ai-command.js'
import { showBanner } from '../../lib/help.js'
Expand Down Expand Up @@ -46,6 +46,10 @@ export default class AIBrainListCommand extends AICommand {
description: 'the max number of brains to list, 0 means all.',
default: 100,
}),
refresh: Flags.boolean({
char: 'r',
description: 'refresh the online brains list',
}),
}

async run(): Promise<any> {
Expand All @@ -55,6 +59,10 @@ export default class AIBrainListCommand extends AICommand {
const userConfig = this.loadConfig(flags.config, opts)
initTools(userConfig)

if (flags.refresh) {
upgradeBrains()
}

if (userConfig.banner && !isJson) {showBanner('Brain')}
flags.name = args.name
const result = listBrains(userConfig, flags)
Expand Down

0 comments on commit 129dd3f

Please sign in to comment.