java
@Bean
public ReactAgent chatbotReactAgent(ChatModel chatModel,
ShellTool2 shellTool,
ToolCallback executePythonCode,
ToolCallback viewTextFile,
MemorySaver memorySaver) {
return xxx;
这个里面有两个ToolCallback,如何注入
java
@Bean
public ToolCallback executePythonCode() {
return FunctionToolCallback.builder("execute_python_code", new PythonTool())
.description(PythonTool.DESCRIPTION)
.inputType(PythonTool.PythonRequest.class)
.build();
}
// 把框架提供的 ReadFileTool 包装成名为 view_text_file 的读文件工具。
@Bean
public ToolCallback viewTextFile() {
ReadFileTool readFileTool = new ReadFileTool();
return FunctionToolCallback.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的名字,也可以指定;
java
@Bean("pythonToolCallback")
public ToolCallback executePythonCode() {
return FunctionToolCallback.builder("execute_python_code", new PythonTool())
.description(PythonTool.DESCRIPTION)
.inputType(PythonTool.PythonRequest.class)
.build();
}
3.如果还分不清,就用 @Qualifier 明确指定。
java
@Qualifier("pythonToolCallback") ToolCallback executePythonCode