@@ -281,8 +281,6 @@ export class Conversation extends EventEmitter {
281281 let _content = '' ;
282282 const reqMethods = this . _reqMethods ;
283283 const toolsConfig = this . _toolsConfig ;
284- //deduplicate tools
285- toolsConfig . tools = toolsConfig . tools . filter ( ( tool , index , self ) => self . findIndex ( ( t ) => t . function . name === tool . function . name ) === index ) ;
286284 const endpoints = this . _endpoints ;
287285 const baseUrl = this . _baseUrl ;
288286 const message_id = 'msg_' + randomUUID ( ) ;
@@ -832,15 +830,22 @@ export class Conversation extends EventEmitter {
832830 this . _customToolsDeclarations . push ( toolDefinition ) ;
833831 this . _customToolsHandlers [ tool . name ] = tool . handler ;
834832
833+ //deduplicate tools
834+
835835 const llmInference : LLMInference = await LLMInference . getInstance ( this . model , AccessCandidate . team ( this . _teamId ) ) ;
836+ this . _customToolsDeclarations = this . _customToolsDeclarations . filter (
837+ ( tool , index , self ) => self . findIndex ( ( t ) => t . name === tool . name ) === index
838+ ) ;
836839 const toolsConfig : any = llmInference . connector . formatToolsConfig ( {
837840 type : 'function' ,
838- toolDefinitions : [ toolDefinition ] ,
841+ toolDefinitions : this . _customToolsDeclarations ,
839842 toolChoice : this . toolChoice ,
840843 } ) ;
841844
842- if ( this . _toolsConfig ) this . _toolsConfig . tools . push ( ...toolsConfig ?. tools ) ;
843- else this . _toolsConfig = toolsConfig ;
845+ //if (this._toolsConfig) this._toolsConfig.tools.push(...toolsConfig?.tools);
846+ //else this._toolsConfig = toolsConfig;
847+
848+ this . _toolsConfig = toolsConfig ;
844849 }
845850 /**
846851 * updates LLM model, if spec is available, it will update the tools config
@@ -857,15 +862,19 @@ export class Conversation extends EventEmitter {
857862 this . _baseUrl = this . _spec ?. servers ?. [ 0 ] . url ;
858863
859864 const functionDeclarations = this . getFunctionDeclarations ( this . _spec ) ;
860- functionDeclarations . push ( ...this . _customToolsDeclarations ) ;
865+ //functionDeclarations.push(...this._customToolsDeclarations);
866+ this . _customToolsDeclarations . push ( ...functionDeclarations ) ;
861867 const llmInference : LLMInference = await LLMInference . getInstance ( this . _model , AccessCandidate . team ( this . _teamId ) ) ;
862868 if ( ! llmInference . connector ) {
863869 this . emit ( 'error' , 'No connector found for model: ' + this . _model ) ;
864870 return ;
865871 }
872+ this . _customToolsDeclarations = this . _customToolsDeclarations . filter (
873+ ( tool , index , self ) => self . findIndex ( ( t ) => t . name === tool . name ) === index
874+ ) ;
866875 this . _toolsConfig = llmInference . connector . formatToolsConfig ( {
867876 type : 'function' ,
868- toolDefinitions : functionDeclarations ,
877+ toolDefinitions : this . _customToolsDeclarations ,
869878 toolChoice : this . toolChoice ,
870879 } ) ;
871880
0 commit comments