Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

再使用SpringAI进行function-call时,发生非web上下文报错。我不太理解为何会报这种错。 #714

Open
LittleDrip opened this issue Dec 6, 2024 · 0 comments

Comments

@LittleDrip
Copy link

我分为三个代码块介绍吧
Controller类
public AIController(ChatClient.Builder builder, ChatMemory chatMemory) {
this.chatClient = builder
.defaultFunctions("psychologicalHealthAssessment") //调用函数(见Function处理类)
.build();
}

Function处理类
@bean
@description("做出心理健康评估")
public Function<PapersRequest, String> psychologicalHealthAssessment(){
return request -> {
Result evaluation = papersService.getEvaluation(1); 在此处报错
UserPapersDetailVo data = (UserPapersDetailVo )evaluation.getData();
return data.getEvaluation();
};
}
具体到Service类,即 StpUtil.getSession().这里报错。
public Result getEvaluation(int id) {
User user = (User) StpUtil.getSession().get("user"); 在此处报错
Long userId = user.getId();
UserPapers userPapers = userPapersService.lambdaQuery()
.eq(UserPapers::getUserId, userId)
.eq(UserPapers::getPaperId, id)
.one();
if (userPapers == null) {
return Result.build(null,404, "你尚未开始作答试卷");
}
UserPapersDetailVo userPapersDetailVo = BeanUtil.copyProperties(userPapers, UserPapersDetailVo.class);
return Result.ok(userPapersDetailVo);
}

主要是不明白哪里是非web上下文操作,这应该是标准的web操作啊,我也保证都注册到web容器了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant