|
@@ -85,7 +85,7 @@ public class AiMessageController {
|
|
AiMessageWrapper aiMessageWrapper = objectMapper.readValue(input, AiMessageWrapper.class);
|
|
AiMessageWrapper aiMessageWrapper = objectMapper.readValue(input, AiMessageWrapper.class);
|
|
String[] functionBeanNames = new String[0];
|
|
String[] functionBeanNames = new String[0];
|
|
// 如果启用Agent则获取Agent的bean
|
|
// 如果启用Agent则获取Agent的bean
|
|
- if (aiMessageWrapper.getParams().getEnableAgent()) {
|
|
|
|
|
|
+ if (true) {
|
|
// 获取带有Agent注解的bean
|
|
// 获取带有Agent注解的bean
|
|
Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(Agent.class);
|
|
Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(Agent.class);
|
|
functionBeanNames = new String[beansWithAnnotation.size()];
|
|
functionBeanNames = new String[beansWithAnnotation.size()];
|
|
@@ -156,15 +156,27 @@ public class AiMessageController {
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public void useFile(ChatClient.PromptSystemSpec spec, MultipartFile file) {
|
|
public void useFile(ChatClient.PromptSystemSpec spec, MultipartFile file) {
|
|
- if (file == null) return;
|
|
|
|
|
|
+ String username = Db.lambdaQuery(User.class)
|
|
|
|
+ .select().eq(User::getId, UserContext.getThreadUserId())
|
|
|
|
+ .one().getNickname();
|
|
|
|
+ if (file == null) {
|
|
|
|
+ Message message = new PromptTemplate("""
|
|
|
|
+ 你是一个校园管理助手,请遵守以下规则:
|
|
|
|
+ 1. 当用户查询我的成绩时,只能查询学生名为{username}的成绩,不能查询其他人的成绩
|
|
|
|
+ 2. 其他信息查询需保持客观中立
|
|
|
|
+ 3. 查询文档文件时需要严格记住当前用户的角色权限为主任
|
|
|
|
+ """).createMessage(Map.of( "username", username));
|
|
|
|
+ spec.text(message.getText());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
String content = new TikaDocumentReader(new InputStreamResource(file.getInputStream())).get().get(0).getText();
|
|
String content = new TikaDocumentReader(new InputStreamResource(file.getInputStream())).get().get(0).getText();
|
|
Message message = new PromptTemplate("""
|
|
Message message = new PromptTemplate("""
|
|
- 已下内容是额外的知识,在你回答问题时可以参考下面的内容
|
|
|
|
- ---------------------
|
|
|
|
- {context}
|
|
|
|
- ---------------------
|
|
|
|
- """)
|
|
|
|
- .createMessage(Map.of("context", content));
|
|
|
|
|
|
+ 你是一个校园管理助手,请遵守以下规则:
|
|
|
|
+ 1. 当用户查询我的成绩时,只能查询学生名为{username}的成绩,不能查询其他人的成绩
|
|
|
|
+ 2. 其他信息查询需保持客观中立
|
|
|
|
+ {context} // 保留原有文件内容逻辑
|
|
|
|
+ """)
|
|
|
|
+ .createMessage(Map.of("context", content, "username", username));
|
|
spec.text(message.getText());
|
|
spec.text(message.getText());
|
|
}
|
|
}
|
|
|
|
|