调用工具:AI写文件
This commit is contained in:
parent
18107370b0
commit
301cd1a6cc
@ -12,4 +12,6 @@ public interface ToolsService {
|
|||||||
String writeFileTest(String context, String name);
|
String writeFileTest(String context, String name);
|
||||||
|
|
||||||
String readFileTest(String name);
|
String readFileTest(String name);
|
||||||
|
|
||||||
|
String aiWriteFile(String question);
|
||||||
}
|
}
|
||||||
|
@ -41,4 +41,13 @@ public class ToolsServiceImpl implements ToolsService {
|
|||||||
FileTool fileTool = new FileTool();
|
FileTool fileTool = new FileTool();
|
||||||
return fileTool.readFile(name);
|
return fileTool.readFile(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String aiWriteFile(String question) {
|
||||||
|
return ChatClient.create(ollamaChatModel)
|
||||||
|
.prompt(question)
|
||||||
|
.advisors(new MyLoggerAdvisor())
|
||||||
|
.tools(new FileTool())
|
||||||
|
.call().content();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ public class ToolController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ToolsService toolsService;
|
private ToolsService toolsService;
|
||||||
|
|
||||||
@PostMapping("/getWeather")
|
@PostMapping("/getAiWeather")
|
||||||
@Operation(summary = "获取天气")
|
@Operation(summary = "AI获取天气")
|
||||||
public R<String> getWeather(@RequestBody String question) {
|
public R<String> getAiWeather(@RequestBody String question) {
|
||||||
String result = toolsService.getWeather(question);
|
String result = toolsService.getWeather(question);
|
||||||
return R.ok(result);
|
return R.ok(result);
|
||||||
}
|
}
|
||||||
@ -56,4 +56,12 @@ public class ToolController {
|
|||||||
String result = toolsService.readFileTest(name);
|
String result = toolsService.readFileTest(name);
|
||||||
return R.ok(result);
|
return R.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/aiWriteFile")
|
||||||
|
@Operation(summary = "AI写文件")
|
||||||
|
public R<String> aiWriteFile(@RequestBody String question) {
|
||||||
|
CheckUtils.checkEmpty(question, "问题");
|
||||||
|
String result = toolsService.aiWriteFile(question);
|
||||||
|
return R.ok(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user