Skip to content

Commit

Permalink
Improved expert brain functionality
Browse files Browse the repository at this point in the history
- Updated `useAgentBrain` to use `ex.stream` instead of `_currentExpert.stream`
- Added `setDefaultExpert` and `resetExperts` functions for managing experts
- Updated `checkExpert` function to throw error if expert is down
- Updated `AgentBrain` interface to include `setDefaultExpert` method
synw committed May 22, 2024
1 parent 39fd128 commit f6e271b
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/brain/src/brain.ts
Original file line number Diff line number Diff line change
@@ -138,9 +138,8 @@ const useAgentBrain = (experts: Array<LmExpert> = []): AgentBrain => {
if (!ex) {
throw new Error(`Expert ${expertName} not found`)
}
_currentExpert = ex;
stream = _currentExpert.stream;
return await _currentExpert.think(prompt, inferenceParams, options);
stream = ex.stream;
return await ex.think(prompt, inferenceParams, options);
}

const abortThinking = async () => {
@@ -156,17 +155,26 @@ const useAgentBrain = (experts: Array<LmExpert> = []): AgentBrain => {
return ex
}

const setDefaultExpert = (ex: LmExpert | string) => {
if (typeof ex == "string") {
_currentExpert = expert(ex);
} else {
_currentExpert = ex;
}
}

const resetExperts = () => {
_experts = [];
_currentExpert = _dummyExpert;
}

const _checkExpert = (_ex: LmExpert) => {
if (_ex.name == "dummydefault") {
//console.warn("ERR EX", _experts.map(e => e.name));
//console.log("ERR CEX", _ex.name);
throw new Error("No expert is configured")
}
if (!_ex.state.get().isUp) {
throw new Error(`Expert ${_ex.name} is down, can not abort`)
}
}

return {
@@ -186,6 +194,7 @@ const useAgentBrain = (experts: Array<LmExpert> = []): AgentBrain => {
discover,
discoverLocal,
expertsForModelsInfo,
setDefaultExpert,
getExpertForModel,
think,
thinkx,
1 change: 1 addition & 0 deletions packages/brain/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -216,6 +216,7 @@ interface AgentBrain {
discover: (isVerbose?: boolean) => Promise<boolean>;
discoverLocal: () => Promise<boolean>;
expertsForModelsInfo: () => Promise<void>;
setDefaultExpert: (ex: LmExpert | string) => void;
getExpertForModel: (model: string) => string | null;
think: ThinkFunctionType;
thinkx: ThinkxFunctionType;

0 comments on commit f6e271b

Please sign in to comment.