[feature][chat]Introduce dedicated LLM management.#1739

This commit is contained in:
jerryjzhang
2024-10-09 12:00:24 +08:00
parent 0654a54c8d
commit 7b9ff2e281
22 changed files with 367 additions and 43 deletions

View File

@@ -155,13 +155,8 @@ public class S2VisitsDemo extends S2BaseDemo {
agent.setDescription("帮助您用自然语言查询指标,支持时间限定、条件筛选、下钻维度以及聚合统计");
agent.setStatus(1);
agent.setEnableSearch(1);
agent.setExamples(Lists.newArrayList(
"近15天超音数访问次数汇总",
"按部门统计超音数的访问人数",
"对比alice和lucy的停留时长",
"过去30天访问次数最高的部门top3",
"近1个月总访问次数超过100次的部门有几个",
"过去半个月每个核心用户的总停留时长"));
agent.setExamples(Lists.newArrayList("近15天超音数访问次数汇总", "按部门统计超音数的访问人数", "对比alice和lucy的停留时长",
"过去30天访问次数最高的部门top3", "近1个月总访问次数超过100次的部门有几个", "过去半个月每个核心用户的总停留时长"));
AgentConfig agentConfig = new AgentConfig();
RuleParserTool ruleQueryTool = new RuleParserTool();
ruleQueryTool.setType(AgentToolType.NL2SQL_RULE);

View File

@@ -103,6 +103,21 @@ CREATE TABLE IF NOT EXISTS `s2_chat_memory` (
) ;
COMMENT ON TABLE s2_chat_memory IS 'chat memory table ';
CREATE TABLE IF NOT EXISTS `s2_chat_model`
(
id int AUTO_INCREMENT,
name varchar(100) null,
description varchar(500) null,
`config` varchar(500) NOT NULL ,
`created_at` TIMESTAMP NOT NULL ,
`created_by` varchar(100) NOT NULL ,
`updated_at` TIMESTAMP NOT NULL ,
`updated_by` varchar(100) NOT NULL,
`admin` varchar(500) NOT NULL,
`viewer` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`)
); COMMENT ON TABLE s2_chat_model IS 'chat model table';
create table IF NOT EXISTS s2_user
(
id INT AUTO_INCREMENT,
@@ -388,7 +403,6 @@ CREATE TABLE IF NOT EXISTS s2_agent
PRIMARY KEY (`id`)
); COMMENT ON TABLE s2_agent IS 'agent information table';
-------demo for semantic and chat
CREATE TABLE IF NOT EXISTS `s2_user_department` (
`user_name` varchar(200) NOT NULL,

View File

@@ -210,6 +210,20 @@ CREATE TABLE IF NOT EXISTS `s2_chat_statistics` (
KEY `commonIndex` (`question_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `s2_chat_model` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL COMMENT '名称',
`description` varchar(500) DEFAULT NULL COMMENT '描述',
`config` text NOT NULL COMMENT '配置信息',
`created_at` datetime NOT NULL COMMENT '创建时间',
`created_by` varchar(100) NOT NULL COMMENT '创建人',
`updated_at` datetime NOT NULL COMMENT '更新时间',
`updated_by` varchar(100) NOT NULL COMMENT '更新人',
`admin` varchar(500) DEFAULT NULL,
`viewer` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='对话大模型实例表';
CREATE TABLE IF NOT EXISTS `s2_database` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL COMMENT '名称',

View File

@@ -5,6 +5,7 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatExecuteReq;
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.service.ChatModelService;
import com.tencent.supersonic.chat.server.service.ChatQueryService;
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
@@ -33,6 +34,8 @@ public class BaseTest extends BaseApplication {
protected ChatQueryService chatQueryService;
@Autowired
protected AgentService agentService;
@Autowired
protected ChatModelService chatModelService;
protected QueryResult submitMultiTurnChat(String queryText, Integer agentId, Integer chatId)
throws Exception {

View File

@@ -2,6 +2,8 @@ package com.tencent.supersonic.evaluation;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.BaseTest;
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
import com.tencent.supersonic.chat.server.agent.Agent;
@@ -9,12 +11,14 @@ import com.tencent.supersonic.chat.server.agent.AgentConfig;
import com.tencent.supersonic.chat.server.agent.AgentToolType;
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
import com.tencent.supersonic.chat.server.agent.RuleParserTool;
import com.tencent.supersonic.chat.server.pojo.ChatModel;
import com.tencent.supersonic.common.pojo.enums.ChatModelType;
import com.tencent.supersonic.util.DataUtils;
import com.tencent.supersonic.util.LLMConfigUtils;
import org.junit.jupiter.api.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Disabled
@@ -133,7 +137,13 @@ public class Text2SQLEval extends BaseTest {
AgentConfig agentConfig = new AgentConfig();
agentConfig.getTools().add(getLLMQueryTool());
agent.setAgentConfig(JSONObject.toJSONString(agentConfig));
agent.setModelConfig(LLMConfigUtils.getLLMConfig(LLMConfigUtils.LLMType.OLLAMA_LLAMA3));
ChatModel chatModel = new ChatModel();
chatModel.setName("Text2SQL LLM");
chatModel.setConfig(LLMConfigUtils.getLLMConfig(LLMConfigUtils.LLMType.OLLAMA_LLAMA3));
chatModel = chatModelService.createChatModel(chatModel, User.getFakeUser());
Map<ChatModelType, Integer> chatModelConfig = Maps.newHashMap();
chatModelConfig.put(ChatModelType.TEXT_TO_SQL, chatModel.getId());
agent.setModelConfig(chatModelConfig);
MultiTurnConfig multiTurnConfig = new MultiTurnConfig();
multiTurnConfig.setEnableMultiTurn(enableMultiturn);
agent.setMultiTurnConfig(multiTurnConfig);

View File

@@ -103,6 +103,21 @@ CREATE TABLE IF NOT EXISTS `s2_chat_memory` (
) ;
COMMENT ON TABLE s2_chat_memory IS 'chat memory table ';
CREATE TABLE IF NOT EXISTS `s2_chat_model`
(
id int AUTO_INCREMENT,
name varchar(100) null,
description varchar(500) null,
`config` varchar(500) NOT NULL ,
`created_at` TIMESTAMP NOT NULL ,
`created_by` varchar(100) NOT NULL ,
`updated_at` TIMESTAMP NOT NULL ,
`updated_by` varchar(100) NOT NULL,
`admin` varchar(500) NOT NULL,
`viewer` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`)
); COMMENT ON TABLE s2_chat_model IS 'chat model table';
create table IF NOT EXISTS s2_user
(
id INT AUTO_INCREMENT,