spring有多个对象时如何注入
@BeanpublicReactAgentchatbotReactAgent(ChatModelchatModel,ShellTool2shellTool,ToolCallbackexecutePythonCode,ToolCallbackviewTextFile,MemorySavermemorySaver){returnxxx;这个里面有两个ToolCallback,如何注入
@BeanpublicToolCallbackexecutePythonCode(){returnFunctionToolCallback.builder("execute_python_code",newPythonTool()).description(PythonTool.DESCRIPTION).inputType(PythonTool.PythonRequest.class).build();}// 把框架提供的 ReadFileTool 包装成名为 view_text_file 的读文件工具。@BeanpublicToolCallbackviewTextFile(){ReadFileToolreadFileTool=newReadFileTool();returnFunctionToolCallback.builder("view_text_file",readFileTool).description("View the contents of a text file. The file_path parameter must be an absolute path. "+"You can specify offset and limit to read specific portions of the file. "+"By default, reads up to 500 lines starting from the beginning of the file.").inputType(ReadFileTool.ReadFileRequest.class).build();}spring对象注入
1.先按类型找;
2.如果同类型有多个,再按 Bean 名区分,默认函数名就是Bean的名字,也可以指定;
@Bean("pythonToolCallback")publicToolCallbackexecutePythonCode(){returnFunctionToolCallback.builder("execute_python_code",newPythonTool()).description(PythonTool.DESCRIPTION).inputType(PythonTool.PythonRequest.class).build();}3.如果还分不清,就用 @Qualifier 明确指定。
@Qualifier("pythonToolCallback")ToolCallbackexecutePythonCode