Commit e50250449a1d38128d6577917aa033e1414731a9
1 parent
c96f6bb3
fix:【AI 大模型】UserProfileQueryToolFunction 没有参数,会报错
Showing
1 changed file
with
24 additions
and
7 deletions
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/service/model/tool/UserProfileQueryToolFunction.java
| @@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | ||
| 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | 7 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 9 | import com.fasterxml.jackson.annotation.JsonClassDescription; | 9 | import com.fasterxml.jackson.annotation.JsonClassDescription; |
| 10 | +import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 11 | +import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
| 10 | import jakarta.annotation.Resource; | 12 | import jakarta.annotation.Resource; |
| 11 | import lombok.AllArgsConstructor; | 13 | import lombok.AllArgsConstructor; |
| 12 | import lombok.Data; | 14 | import lombok.Data; |
| @@ -17,7 +19,7 @@ import org.springframework.stereotype.Component; | @@ -17,7 +19,7 @@ import org.springframework.stereotype.Component; | ||
| 17 | import java.util.function.BiFunction; | 19 | import java.util.function.BiFunction; |
| 18 | 20 | ||
| 19 | /** | 21 | /** |
| 20 | - * 工具:当前用户信息查询 | 22 | + * 工具:用户信息查询 |
| 21 | * | 23 | * |
| 22 | * 同时,也是展示 ToolContext 上下文的使用 | 24 | * 同时,也是展示 ToolContext 上下文的使用 |
| 23 | * | 25 | * |
| @@ -31,8 +33,17 @@ public class UserProfileQueryToolFunction | @@ -31,8 +33,17 @@ public class UserProfileQueryToolFunction | ||
| 31 | private AdminUserApi adminUserApi; | 33 | private AdminUserApi adminUserApi; |
| 32 | 34 | ||
| 33 | @Data | 35 | @Data |
| 34 | - @JsonClassDescription("当前用户信息查询") | ||
| 35 | - public static class Request { } | 36 | + @JsonClassDescription("用户信息查询") |
| 37 | + public static class Request { | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 用户编号 | ||
| 41 | + */ | ||
| 42 | + @JsonProperty(value = "id") | ||
| 43 | + @JsonPropertyDescription("用户编号,例如说:1。如果查询自己,则 id 为空") | ||
| 44 | + private Long id; | ||
| 45 | + | ||
| 46 | + } | ||
| 36 | 47 | ||
| 37 | @Data | 48 | @Data |
| 38 | @AllArgsConstructor | 49 | @AllArgsConstructor |
| @@ -61,13 +72,19 @@ public class UserProfileQueryToolFunction | @@ -61,13 +72,19 @@ public class UserProfileQueryToolFunction | ||
| 61 | 72 | ||
| 62 | @Override | 73 | @Override |
| 63 | public Response apply(Request request, ToolContext toolContext) { | 74 | public Response apply(Request request, ToolContext toolContext) { |
| 64 | - LoginUser loginUser = (LoginUser) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_LOGIN_USER); | ||
| 65 | Long tenantId = (Long) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_TENANT_ID); | 75 | Long tenantId = (Long) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_TENANT_ID); |
| 66 | - if (loginUser == null | tenantId == null) { | ||
| 67 | - return null; | 76 | + if (tenantId == null) { |
| 77 | + return new Response(); | ||
| 78 | + } | ||
| 79 | + if (request.getId() == null) { | ||
| 80 | + LoginUser loginUser = (LoginUser) toolContext.getContext().get(AiUtils.TOOL_CONTEXT_LOGIN_USER); | ||
| 81 | + if (loginUser == null) { | ||
| 82 | + return new Response(); | ||
| 83 | + } | ||
| 84 | + request.setId(loginUser.getId()); | ||
| 68 | } | 85 | } |
| 69 | return TenantUtils.execute(tenantId, () -> { | 86 | return TenantUtils.execute(tenantId, () -> { |
| 70 | - AdminUserRespDTO user = adminUserApi.getUser(loginUser.getId()); | 87 | + AdminUserRespDTO user = adminUserApi.getUser(request.getId()); |
| 71 | return BeanUtils.toBean(user, Response.class); | 88 | return BeanUtils.toBean(user, Response.class); |
| 72 | }); | 89 | }); |
| 73 | } | 90 | } |