feat:【AI 大模型】增加 AI ToolContext 上下文
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package cn.iocoder.yudao.framework.ai.core.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.chat.model.StreamingChatModel;
|
||||
|
||||
/**
|
||||
* 工具上下文参数 DTO,让AI工具可以处理当前用户的相关信息
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AiToolContext {
|
||||
public static final String CONTEXT_KEY = "AI_TOOL_CONTEXT";
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 聊天模型
|
||||
*/
|
||||
private StreamingChatModel chatModel;
|
||||
|
||||
/**
|
||||
* 关联的聊天角色Id
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 会话Id
|
||||
*/
|
||||
private Long conversationId;
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.framework.ai.core.util;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
|
||||
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiChatOptions;
|
||||
import org.springframework.ai.chat.messages.*;
|
||||
@@ -15,6 +17,7 @@ import org.springframework.ai.qianfan.QianFanChatOptions;
|
||||
import org.springframework.ai.zhipuai.ZhiPuAiChatOptions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -25,8 +28,11 @@ import java.util.Set;
|
||||
*/
|
||||
public class AiUtils {
|
||||
|
||||
public static final String TOOL_CONTEXT_LOGIN_USER = "LOGIN_USER";
|
||||
public static final String TOOL_CONTEXT_TENANT_ID = "TENANT_ID";
|
||||
|
||||
public static ChatOptions buildChatOptions(AiPlatformEnum platform, String model, Double temperature, Integer maxTokens) {
|
||||
return buildChatOptions(platform, model, temperature, maxTokens, null, Map.of());
|
||||
return buildChatOptions(platform, model, temperature, maxTokens, null, null);
|
||||
}
|
||||
|
||||
public static ChatOptions buildChatOptions(AiPlatformEnum platform, String model, Double temperature, Integer maxTokens,
|
||||
@@ -85,4 +91,11 @@ public class AiUtils {
|
||||
throw new IllegalArgumentException(StrUtil.format("未知消息类型({})", type));
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildCommonToolContext() {
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put(TOOL_CONTEXT_LOGIN_USER, SecurityFrameworkUtils.getLoginUser());
|
||||
context.put(TOOL_CONTEXT_TENANT_ID, TenantContextHolder.getTenantId());
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user