35 Commits
v0.6 ... v0.7.3

Author SHA1 Message Date
williamhliu
40e0a58502 [feature](project) delete package-lock.json (#44)
Co-authored-by: williamhliu <williamhliu@tencent.com>
2023-08-30 14:19:39 +08:00
lexluo09
9723c2496e [release][project]update mvn pom to 0.7.3 and recover llm code,start shell, and docs (#43)
Co-authored-by: lexluo <lexluo@tencent.com>
2023-08-30 14:18:52 +08:00
williamhliu
4b99736a38 Merge pull request #42 from williamhliu/master
[feature](webapp) merge query steps to one card
2023-08-29 22:16:35 +08:00
williamhliu
36fd737440 [feature](webapp) merge query steps to one card 2023-08-29 22:14:14 +08:00
mainmain
93ca060c45 [improvement] fix LLMDslParser name problem (#41)
Co-authored-by: zuopengge <hwzuopengge@tencent.com>
2023-08-29 22:00:40 +08:00
mainmain
e1911bc81b [release][project] supersonic 0.7.3 version backend update (#40)
* [improvement] add some features

* [improvement] revise CHANGELOG

---------

Co-authored-by: zuopengge <hwzuopengge@tencent.com>
2023-08-29 20:06:34 +08:00
jerryjzhang
6fe9ab79ed [improvement][docs]Add local development build to README 2023-08-29 18:23:12 +08:00
jerryjzhang
5ee5ab116f [improvement][docs]Add wechat contact to README 2023-08-29 09:53:33 +08:00
Scott
a6c4d10d70 [improvement][project]update scripts to build&run on macos (#37)
* [improvement][project]update scripts to build&run on macos
2023-08-28 19:05:17 +08:00
codescracker
0d65d03bee upgrade text2dsl module for date related parse. (#38)
* [improvement](llm) data de-identification for few-shots examples.

* [improvement](llm) add plugin-call and preset retrieval features.

* [fix](llm) remove config variables.

* [improvement][feature]upgrade text2dsl module for date related parse.

---------
2023-08-28 18:56:24 +08:00
jerryjzhang
acca5e4538 [improvement][docs]update README and architecture diagram 2023-08-28 11:46:07 +08:00
williamhliu
233899ca3e Merge pull request #35 from williamhliu/master
[feature](weaapp) add agent
2023-08-20 18:47:39 +08:00
williamhliu
aa218898ff [feature](weaapp) add agent 2023-08-20 18:17:00 +08:00
mainmain
cf1b5336c3 [improvement](supersonic) based on version 0.7.2 (#34)
Co-authored-by: zuopengge <hwzuopengge@tencent.com>
2023-08-20 17:30:35 +08:00
lexluo09
c93e60ced7 [improvement][project] update version to 0.7.2 (#32)
Co-authored-by: lexluo <lexluo@tencent.com>
2023-08-15 20:38:11 +08:00
williamhliu
3cb8f53aec Merge pull request #31 from williamhliu/master
[feature](webapp) add copilot and modify domain to model
2023-08-15 20:11:12 +08:00
williamhliu
86b93876c7 [feature](webapp) add copilot and modify domain to model 2023-08-15 20:04:04 +08:00
lexluo09
2732d8fee1 [fix](chat) add env bash to env.sh (#30)
Co-authored-by: lexluo <lexluo@tencent.com>
2023-08-15 18:08:45 +08:00
tristanliu
6c7c1ffbeb Merge pull request #29 from sevenliu1896/master
[improvement][semantic-fe] Restructured the code to extract the quest…
2023-08-15 10:43:14 +08:00
tristanliu
c3d3b1146b [improvement][semantic-fe] Restructured the code to extract the question-answer settings and model management model controls into the OverviewContainer component. 2023-08-15 10:40:58 +08:00
jipeli
b1952d64ab [improvement][project] supersonic 0.7.2 version backend update (#28)
Co-authored-by: jipengli <jipengli@tencent.com>
2023-08-15 08:56:18 +08:00
tristanliu
27283001a8 Merge pull request #26 from sevenliu1896/master
[improvement][semantic-fe] Optimized the frontend display and code lo…
2023-08-07 11:44:18 +08:00
tristanliu
ef7c37a8da [improvement][semantic-fe] Optimized the frontend display and code logic of visual modeling, and updated the relevant interface of the permission management module. 2023-08-07 10:10:54 +08:00
SunDean
aa0a100a85 [improvement][project] supersonic 0.7.0 version backend update (#24)
* [improvement][project] supersonic 0.7.0 version backend update

* [improvement][project] supersonic 0.7.0 version backend update

* [improvement][project] supersonic 0.7.0 version readme update

---------

Co-authored-by: jolunoluo <jolunoluo@tencent.com>
2023-08-05 22:17:56 +08:00
williamhliu
6951eada9d add chat plugin and split query to parse and execute (#25)
* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) gitignore add supersonic-webapp

* [feature](webapp) gitignore add supersonic-webapp

* [feature](webapp) add chat plugin and split query to parse and execute

* [feature](webapp) add chat plugin and split query to parse and execute

* [feature](webapp) add chat plugin and split query to parse and execute

---------

Co-authored-by: williamhliu <williamhliu@tencent.com>
2023-08-05 22:17:42 +08:00
jerryjzhang
c9baed6c4e [improvement][docs]update README and architecture diagram 2023-08-04 14:38:16 +08:00
jerryjzhang
4693785738 Merge remote-tracking branch 'origin/master' 2023-07-31 20:16:08 +08:00
jerryjzhang
a0a466fe07 [improvement][docs]update demo gif 2023-07-31 20:15:51 +08:00
jerryjzhang
23f3d50796 [improvement][docs]update README and architecture diagram 2023-07-31 17:32:39 +08:00
williamhliu
bdae7ebefa gitignore file add supersonic-webapp (#23)
* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) gitignore add supersonic-webapp

* [feature](webapp) gitignore add supersonic-webapp

---------

Co-authored-by: williamhliu <williamhliu@tencent.com>
2023-07-31 17:31:52 +08:00
williamhliu
7c99829052 add drill down dimensions and metric period compare and modify layout (#22)
* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) add drill down dimensions and metric period compare and modify layout

---------

Co-authored-by: williamhliu <williamhliu@tencent.com>
2023-07-31 12:00:39 +08:00
tristanliu
0ac652c5d9 semantic-fe visual modeling pr (#21)
* [improvement][semantic-fe] Added an editing component to set filtering rules for Q&A. Now, the SQL editor will be accompanied by a list for display and control, to resolve ambiguity when using comma-separated values.
[improvement][semantic-fe] Improved validation logic and prompt copywriting for data source/dimension/metric editing and creation.
[improvement][semantic-fe] Improved user experience for visual modeling. Now, when using the legend to control the display/hide of data sources and their associated metric dimensions, the canvas will be re-layout based on the activated data source in the legend.

* [improvement][semantic-fe] Submitted a new version of the visual modeling tool.
[improvement][semantic-fe] Fixed an issue with the initialization of YoY and MoM metrics in Q&A settings.
[improvement][semantic-fe] Added a version field to the database settings.
[improvement][semantic-fe] 1. Added the ability to set YoY and MoM metrics in Q&A settings.2. Moved dimension value editing from the dimension editing window to the dimension list.

---------

Co-authored-by: tristanliu <tristanliu@tencent.com>
2023-07-31 11:23:37 +08:00
daikon
e2b2d31429 [improvement][project] supersonic 0.7.0 version backend update (#20)
Co-authored-by: kanedai <kanedai@tencent.com>
2023-07-31 11:09:58 +08:00
tristanliu
078a81038f [improvement][semantic-fe] Added an editing component to set filtering rules for Q&A. Now, the SQL editor will be accompanied by a list for display and control, to resolve ambiguity when using comma-separated values.
[improvement][semantic-fe] Improved validation logic and prompt copywriting for data source/dimension/metric editing and creation.
[improvement][semantic-fe] Improved user experience for visual modeling. Now, when using the legend to control the display/hide of data sources and their associated metric dimensions, the canvas will be re-layout based on the activated data source in the legend.

Co-authored-by: tristanliu <tristanliu@tencent.com>
2023-07-21 15:30:38 +08:00
codescracker
6492316e23 [improvement](llm) data de-identification for few-shots examples. (#17)
Co-authored-by: shaoweigong <shaoweigong@tencent.com>
2023-07-17 20:36:31 +08:00
1139 changed files with 45452 additions and 28409 deletions

3
.gitignore vendored
View File

@@ -14,4 +14,5 @@ assembly/runtime/*
*.umi/
/assembly/deploy
/runtime
**/.flattened-pom.xml
**/.flattened-pom.xml
__pycache__/

View File

@@ -1,21 +0,0 @@
davinci 0.3.0 change log
1) add data portal
2) add metric trend chart
3) add feedback component
4) add tab component
5) add page setting
6) modify permission process
7) optimize css style
8) optimize filter
9) delete view module
supersonic 0.6.0 change log
1) add llm parser and llm api server
2) support fuzzy mapping
3) support query filter and domain filter in query and search
4) support standalone mode
5) add dsl query in semantic
6) code architecture adjustment in semantic and chat
7) add unit testing and integration testing
8) support dimension and metric alias

126
CHANGELOG.md Normal file
View File

@@ -0,0 +1,126 @@
# SuperSonic Changelog
- All notable changes to this project will be documented in this file.
- "Breaking Changes" describes any changes that may break existing functionality or cause
compatibility issues with previous versions.
## SuperSonic [0.7.3] - 2023-08-29
### Added
- meet checkstyle code requirements
- save parseInfo after parsing
- add time statistics
- add agent
### Updated
- dsl where condition is used for front-end display
- dsl remove context inheritance
## SuperSonic [0.7.2] - 2023-08-12
### Added
- Support asynchronous query - return parse information to user before executing result
- Add Model as the basic data structure of the semantic definitions - this will repalce the old conception of subdomain
### Updated
- improve knowledge word similarity algorithm
- improve embedding plugin chooser
- improve DSLQuery field correction and parser
### Fixed
- Fix mapper error that detectWord text is shorter than word
- Fix MetricDomainQuery inherit context
## SuperSonic [0.7.0] - 2023-07-30
### Added
- Add function call parser and embedding recall parser
- Add plugin management
- Add web page query and web service query
- Metric filter query support querying metrics and comparing them in different dimensions
- Support dimension value mapping
- Support dimension/metric invisible, chat filter related data
- Add user guide docs
### Fixed
- Fix the data problem of getDomainList interface in standalone mode
## SuperSonic [0.6.0] - 2023-07-16
### Added
- Support llm parser and llm api server - users can query data through complex natural language.
- Support fuzzy query dimension and metric name - users can set the 'metric.dimension.threshold'
parameter to control the fuzzy threshold.
- Support query filter and domain filter in query and search - users can specify domainId and query
filter to filter the results in search and query.
- Support standalone mode - users can integrate semantic and chat services in one process for easy
management and debugging.
- Support dsl query in semantic - users can specify DSL language to query data in Semantic. In the
past, data querying was limited to struct language.
- Add unit and integration testing - add integration tests for single-turn and multi-turn
conversations, to efficiently validate the code.
- Support dimension and metric alias - users can specify one or multiple aliases to expand search
and query.
- Add scheduled semantic metadata update functionality in chat.
- Support create datasource by table name in the web page.
- Add the ability to set permissions for domain.
- Add a local/Remote implementation to the SemanticLayer interface.
### Updated
- Code architecture adjustment in chat.
1) Abstracting into three modules, namely api, core, and knowledge. Providing four core interfaces:
SchemaMapper, SemanticLayer, SemanticParser, and SemanticQuery.
2) Add RuleSemanticQuery and LLMSemanticQuery implement to SemanticQuery.
3) Add all possible queries to the candidate queries, and then select the most suitable query from
the candidate queries.
- Code architecture adjustment in semantic.
1) Refactor semantic layer SQL parsing code through Calcite.
2) Add QueryOptimizer interface.
- Chat config subdivided into detailed and metric scenarios - users can set different parameters in these two scenarios.
### Fixed
- Resolved last word not be recognized in SchemaMapper.
- Fix context inheritance problem.
- Fix the error of querying H2 database by month unit.
- Set faker user to context when authentication disable.
## SuperSonic [0.5.0] - 2023-06-15
### Added
- Add the search and query feature in chat according to rules in an extensible way.
- Add semantic/chat independent service for users.
- Add Modeling Interface - users can visually define and maintain semantic models in the web page.
- Add a unified semantic parsing layer - user can query data by struct language.
# Davinci Changelog
## Davinci [0.3.0] - 2023-06-15
### Added
- add data portal
- add metric trend chart
- add feedback component
- add tab component
- add page setting
### Updated
- modify permission process
- optimize css style
- optimize filter
### Removed
- delete view module

View File

@@ -2,60 +2,47 @@ English | [中文](README_CN.md)
# SuperSonic (超音数)
**SuperSonic is an out-of-the-box yet highly extensible framework for building a data chatbot**. SuperSonic provides a chat interface that empowers users to query data using natural language and visualize the results with suitable charts. To enable such experience, the only thing necessary is to define logical semantic models (metrics, dimensions, relationships, etc) on top of physical data models, and no data modification or copying is required. Meanwhile SuperSonic is designed to be plugable, allowing new functionalities to be added through plugins and core components to be integrated into other systems.
**SuperSonic is an out-of-the-box yet highly extensible framework for building a data chatbot**. SuperSonic provides a chat interface that empowers users to query data using natural language and visualize the results with suitable charts. To enable such experience, the only thing necessary is to build logical semantic models (definition of metrics/dimensions/entities, along with their meaning, context and relationships) on top of physical data models, and no data modification or copying is required. Meanwhile, SuperSonic is designed to be pluggable, allowing new functionalities to be added through plugins and core components to be integrated with other systems.
<img src="./docs/images/supersonic_demo.gif" align="center"/>
<img src="./docs/images/supersonic_demo.gif" height="100%" width="100%" align="center"/>
## Motivation
The emergence of Large Language Models (LLMs) like ChatGPT is reshaping the way information is retrieved. In the field of data analytics, both academia and industry are primarily focused on leveraging deep learning models to convert natural language queries into SQL queries. While some works show promising results, they are not applicable to real-world scenarios.
The emergence of Large Language Model (LLM) like ChatGPT is reshaping the way information is retrieved. In the field of data analytics, both academia and industry are primarily focused on leveraging LLM to convert natural language queries into SQL queries. While some works show promising results, they are still not applicable to real-world scenarios.
From our perspective, the key to filling the real-world gap lies in two aspects:
1. Utilize a combination of rule-based and model-based semantic parsers to deal with different scenarios
2. Introduce a semantic model layer to encapsulate underlying complexity thus simplify the semantic parsers
From our perspective, the key to filling the real-world gap lies in three aspects:
1. Complement the LLM-based semantic parser with rule-based semantic parsers to improve **efficiency**(in terms of latency and cost).
2. Augment semantic parsing with schema mappers(as a kind of preprocessor) and semantic correctors(as a kind of postprocessor) to improve **accuracy** and **stability**.
3. Introduce a semantic layer encapsulating underlying data context(joins, formulas, etc) to reduce **complexity**.
With these ideas in mind, we developed SuperSonic as a reference implementation and used it to power our real-world products. Additionally, to encourage further development of data chatbots, we decided to open source SuperSonic as an extensible framework.
With these ideas in mind, we develop SuperSonic as a practical reference implementation and use it to power our real-world products. Additionally, to facilitate further development of data chatbot, we decide to open source SuperSonic as an extensible framework.
## Out-of-the-box Features
- Built-in graphical interface for business users to enter data queries
- Built-in graphical interface for analytics engineers to manage semantic models
- Built-in CUI(Chat User Interface) for *business users* to enter data queries
- Built-in GUI(Graphical User Interface) for *analytics engineers* to build semantic models
- Built-in GUI for *system administrators* to manage chat plugins and agents
- Support input auto-completion as well as query recommendation
- Support multi-turn conversation and history context management
- Support three-level permission control: domain-level, column-level and row-level
- Support four-level permission control: domain-level, model-level, column-level and row-level
## Extensible Components
SuperSonic is composed of two layers: supersonic-chat and supersonic-semantic. The chat layer is responsible for converting **natural language query** into semantic query (also known as DSL query), whereas the semantic layer is responsible for converting DSL query into **SQL query**. The high-level architecture and main process flow is shown in below diagram:
The high-level architecture and main process flow is as follows:
<img src="./docs/images/supersonic_components.png" height="65%" width="65%" align="center"/>
<img src="./docs/images/supersonic_components.png" height="80%" width="80%" align="center"/>
- **Knowledge Base:** extracts schema information periodically from the semantic models and build dictionary and index to facilitate schema mapping.
- **Schema Mapper:** identifies references to schema elements(metrics/dimensions/entities/values) in user queries. It matches the query text against the knowledge base.
### Chat Layer
- **Semantic Parser:** understands user queries and extracts semantic information. It consists of a combination of rule-based and model-based parsers, each of which deals with specific scenarios.
The chat layer contains four core components:
- **Semantic Corrector:** checks validity of extracted semantic information and performs correction and optimization if needed.
- **Chat Interface:** accepts user queries and answer results with appropriate visualization charts. It supports input auto-completion as well as multi-turn conversation.
- **Semantic Layer:** performs execution according to extracted semantic information. It generates SQL queries and executes them against physical data models.
- **Schema Mapper Chain:** identifies references to semantic schema elements in user queries. It matches queries against the knowledage base which is constructed using the schema of semantic models.
- **Semantic Parser Chain:** resolves query mode based on mapped semantic models. It is composed of a group of rule-based and model-based parsers, each of which deals with specific scenarios.
- **Semantic Query:** performs execution according to the results of semantic parsing. The default semantic query would submit DSL to the semantic component, but new types of semantic query can be extended.
### Semantic Layer
The semantic layer contains four core components:
- **Modeling Interface:** empowers analytics engineers to visually define and maintain semantic models. The configurations related to access permission and chat conversation can also be set on the UI.
- **DSL Parser:** converts DSL expression to intermediate structures. To make it easily integratable with analytics applications, SQL (without joins and calculation formulas) is used as the DSL.
- **Query Planner:** builds and optimizes query plans according to various rules.
- **SQL Generator:** generates final SQL expression (with joins and calculation formulas) based on the query plan.
- **Chat Plugin:** extends functionality with third-party tools. The LLM is going to select the most suitable one, given all configured plugins with function description and sample questions.
## Quick Demo
@@ -63,8 +50,26 @@ SuperSonic comes with sample semantic models as well as chat conversations that
- Download the latest prebuilt binary from the [release page](https://github.com/tencentmusic/supersonic/releases)
- Run script "bin/start-standalone.sh" to start a standalone server
- Visit http://localhost:9080 in browser to start exploration
- Visit http://localhost:9080 in the browser to start exploration
## How to Build
Pull the source code and run script "assembly/bin/build-standalone.sh" to build packages in the standalone mode.
SuperSonic can be deployed in two modes: standalone (for a quick demo) and distributed (for production use).
### Build for Standalone Mode
Pull the source code and run script "assembly/bin/build-standalone.sh" to build a single packages.
### Build for Distributed Mode
Pull the source code and run scripts "assembly/bin/build-chat.sh" and "assembly/bin/build-semantic.sh" separately to build packages.
### Build for Local Development
Pull the source code and run script "assembly/bin/build-ide.sh" and run bootstrap class "StandaloneLauncher" in the IDE.
## WeChat Contact
Please join the chat group to suggest feedbacks or ideas:
<img src="./docs/images/wechat_contact.jpeg" height="30%" width="30%" align="center"/>

View File

@@ -1,56 +1,46 @@
# 超音数SuperSonic
**超音数是一个开箱即用且易于扩展的数据问答对话框架**。通过超音数的问答对话界面,用户能够使用自然语言查询数据,系统会选择合适的可视化图表呈现结果。超音数不需要修改或复制数据,只需要在物理数据之上构建逻辑语义模型(定义指标维度、相互间关系等),即可开启数据问答体验。与此同时,超音数被设计为可插拔式框架,允许以插件形式来扩展新功能,或者将核心组件与其他系统集成。
**超音数是一个开箱即用且易于扩展的数据问答对话框架**。通过超音数的问答对话界面,用户能够使用自然语言查询数据,系统会选择合适的可视化图表呈现结果。超音数不需要修改或复制数据,只需要在物理数据模型之上构建逻辑语义模型(指标/维度/实体的定义,以及他们的业务含义、相互间关系等),即可开启数据问答体验。与此同时,超音数被设计为可插拔式框架,允许以插件形式来扩展新功能,或者将核心组件与其他系统集成。
<img src="./docs/images/supersonic_demo.gif" align="center"/>
<img src="./docs/images/supersonic_demo.gif" height="100%" width="100%" align="center"/>
## 项目动机
大型语言模型LLMs如ChatGPT的出现正在重塑信息检索的方式。在数据分析领域学术界和工业界主要关注利用深度学习模型将自然语言查询转换为SQL查询。虽然一些工作显示出有前景的结果但它们还并不适用于实际场景。
在我们看来,为了在实际场景发挥价值,有个关键点:
1. 基于规则和基于模型语义解析器相结合,发挥各自优势,以便处理不同的场景
2. 引入语义模型层来封装数据底层的复杂性,从而简化语义解析器的问题求解空间
在我们看来,为了在实际场景发挥价值,有个关键点:
1. 基于模型语义解析器基础上,增加基于规则的解析器,提升语义解析的**效率**。
2. 加入模式映射器和语义修正器,来增强语义解析能力,提升语义解析的**准确性**和**稳定性**。
3. 引入语义模型层,封装底层数据的上下文(关联、公式等),降低语义解析的**复杂性**。
为了验证上述想法,我们开发了超音数项目,并将其应用在实际的内部产品中。与此同时,我们决定将超音数作为一个可扩展的框架开源,希望能够促进数据问答对话领域的进一步发展。
为了验证上述想法,我们开发了超音数项目,并将其应用在实际的内部产品中。与此同时,我们将超音数作为一个可扩展的框架开源,希望能够促进数据问答对话领域的进一步发展。
## 开箱即用的特性
- 内置图形界面以便业务用户输入数据查询
- 内置图形界面以便分析工程师管理语义模型
- 支持文本输入的联想和查询问题的推荐
- 支持多轮对话,根据语境自动切换上下文
- 支持三级权限控制:主题域级、列级、行级
- 内置对话界面以便*业务用户*输入数据查询
- 内置图形界面以便*分析工程师*构建语义模型
- 内置图形界面以便*系统管理员*管理问答插件和助理。
- 支持文本输入的联想和查询问题的推荐。
- 支持多轮对话,根据语境自动切换上下文。
- 支持四级权限控制:主题域级、模型级、列级、行级。
## 易于扩展的组件
超音数主要分为两层supersonic-chat and supersonic-semantic。问答层负责将自然语言查询转换为语义查询也称为DSL查询而语义层负责将DSL查询转换为SQL查询。超音数的整体架构和主流程如下图所示:
超音数的整体架构和主流程如下图所示:
<img src="./docs/images/supersonic_components.png" height="80%" width="80%" align="center"/>
<img src="./docs/images/supersonic_components.png" height="65%" width="65%" align="center"/>
### 问答层
- **知识库(Knowledge Base)** 定期从语义模型中提取相关的模式信息,构建词典和索引,以便后续的模式映射。
问答层包含以下4个核心组件
- **模式映射器(Schema Mapper)** 将自然语言文本在知识库中进行匹配,为后续的语义解析提供相关信息。
- **问答对话界面(chat interface)**:接受用户查询并选择合适的可视化图表呈现结果,支持输入联想和多轮对话
- **语义解析器(Semantic Parser)** 理解用户查询并抽取语义信息,其由一组基于规则和基于模型的解析器组成,每个解析器可应对不同的特定场景
- **模式映射器(schema mapper)**基于语义模型的schema构建知识库然后将自然语言查询在知识库中进行匹配为后续的语义解析提供相关信息
- **语义修正器(Semantic Corrector)** 检查语义信息的合法性,对不合法的信息做修正和优化处理
- **语义解析器链(semantic parser chain)**:识别查询模式并选择最匹配的语义模型,其由一组基于规则或模型的解析器组成,每个解析器可用于应对不同的特定场景
- **语义模型层(Semantic Layer)** 根据语义信息生成物理SQL执行查询
- **语义查询(semantic query)**: 根据语义解析的结果执行查询默认的语义查询会将DSL提交给语义组件但可以扩展新类型的查询。
### 语义层
语义层包含以下4个核心组件
- **语义建模界面(modeling interface)**:使分析工程师能够通过可视化方式定义和维护语义模型,与访问权限和聊天对话相关的配置也可以在用户界面上设置。
- **DSL解析器(DSL parser)**将DSL表达式转换为中间结构。为了使其易于与分析应用程序集成使用SQL不含join和计算公式来作为DSL。
- **查询计划器(query planner)**:根据各种规则来构建和优化查询计划。
- **SQL生成器(SQL genenrator)**基于查询计划来生成最终的SQL语句含join和计算公式
- **问答插件(Chat Plugin)** 通过第三方工具扩展功能。给定所有配置的插件及其功能描述和示例问题,大语言模型将选择最合适的插件。
## 快速体验
@@ -62,4 +52,22 @@
## 如何构建
下载源码包,运行脚本"assembly/bin/build-standalone.sh",将所有服务一起编译打包
超音数可以运行在两个模式standalone一般用于快速演示和distributed一般用于生产环境
### Standalone模式构建
下载源码包,运行脚本"assembly/bin/build-standalone.sh",将所有服务一起编译打包。
### Distributed模式构建
下载源码包,分别运行脚本"assembly/bin/build-chat.sh"、"assembly/bin/build-semantic.sh",为问答层服务和语义层服务编译打包。
### 本地开发构建
下载源码包,运行脚本"assembly/bin/build-ide.sh"然后在本地IDE运行启动类"StandaloneLauncher"。
## 微信联系方式
欢迎加入微信群反馈建议:
<img src="./docs/images/wechat_contact.jpeg" height="30%" width="30%" align="center"/>

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/runtime
buildDir=$baseDir/build

13
assembly/bin/build-ide.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(cd "$sbinDir/.." && pwd -P)
buildDir=$baseDir/build
cd $baseDir/bin
sh build-standalone.sh
cd $buildDir
tar xvf supersonic-webapp.tar.gz
mv supersonic-webapp webapp
mv webapp ../../launchers/standalone/target/classes

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/runtime
buildDir=$baseDir/build

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/runtime
buildDir=$baseDir/build

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/../runtime
buildDir=$baseDir/build

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/../runtime
buildDir=$baseDir/build

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(readlink -f $sbinDir/../)
baseDir=$(cd "$sbinDir/.." && pwd -P)
runtimeDir=$baseDir/../runtime
buildDir=$baseDir/build
@@ -29,4 +29,4 @@ rm -fr ${buildDir}/supersonic-webapp
#start standalone service
sh ${runtimeDir}/supersonic-standalone/bin/service.sh restart
#start llm service
sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh restart
sh ${runtimeDir}/supersonic-standalone/llm/bin/service.sh restart

View File

@@ -0,0 +1,24 @@
package com.tencent.supersonic.auth.api.authentication.adaptor;
import com.tencent.supersonic.auth.api.authentication.pojo.Organization;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import java.util.List;
import java.util.Set;
public interface UserAdaptor {
List<String> getUserNames();
List<User> getUserList();
List<Organization> getOrganizationTree();
void register(UserReq userReq);
String login(UserReq userReq);
List<User> getUserByOrg(String key);
Set<String> getUserAllOrgId(String userName);
}

View File

@@ -19,7 +19,7 @@ public class AuthenticationConfig {
@Value("${authentication.token.secret:secret}")
private String tokenSecret;
@Value("${authentication.token.http.header.key:Auth}")
@Value("${authentication.token.http.header.key:Authorization}")
private String tokenHttpHeaderKey;

View File

@@ -0,0 +1,22 @@
package com.tencent.supersonic.auth.api.authentication.pojo;
import com.google.common.collect.Lists;
import java.util.List;
import lombok.Data;
@Data
public class Organization {
private String id;
private String parentId;
private String name;
private String fullName;
private List<Organization> subOrganizations = Lists.newArrayList();
private boolean isRoot;
}

View File

@@ -1,9 +1,10 @@
package com.tencent.supersonic.auth.api.authentication.service;
import com.tencent.supersonic.auth.api.authentication.pojo.Organization;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import java.util.List;
import java.util.Set;
public interface UserService {
@@ -14,4 +15,10 @@ public interface UserService {
void register(UserReq userCmd);
String login(UserReq userCmd);
Set<String> getUserAllOrgId(String userName);
List<User> getUserByOrg(String key);
List<Organization> getOrganizationTree();
}

View File

@@ -1,7 +1,6 @@
package com.tencent.supersonic.auth.api.authentication.service;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

View File

@@ -6,7 +6,7 @@ import lombok.Data;
@Data
public class AuthGroup {
private String domainId;
private String modelId;
private String name;
private Integer groupId;
private List<AuthRule> authRules;

View File

@@ -7,14 +7,14 @@ import lombok.ToString;
@ToString
public class AuthRes {
private String domainId;
private String modelId;
private String name;
public AuthRes() {
}
public AuthRes(String domainId, String name) {
this.domainId = domainId;
public AuthRes(String modelId, String name) {
this.modelId = modelId;
this.name = name;
}
}

View File

@@ -3,7 +3,6 @@ package com.tencent.supersonic.auth.api.authorization.request;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRes;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.ToString;
@@ -11,11 +10,9 @@ import lombok.ToString;
@ToString
public class QueryAuthResReq {
private String user;
private List<String> departmentIds = new ArrayList<>();
private List<AuthRes> resources;
private String domainId;
private String modelId;
}

View File

@@ -1,7 +1,7 @@
package com.tencent.supersonic.auth.api.authorization.request;
import com.tencent.supersonic.common.request.PageBaseReq;
import com.tencent.supersonic.common.pojo.PageBaseReq;
import java.util.List;
import lombok.Data;

View File

@@ -4,7 +4,6 @@ import com.tencent.supersonic.auth.api.authorization.pojo.AuthResGrp;
import com.tencent.supersonic.auth.api.authorization.pojo.DimensionFilter;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data

View File

@@ -1,11 +1,12 @@
package com.tencent.supersonic.auth.api.authorization.service;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
import com.tencent.supersonic.auth.api.authorization.request.QueryAuthResReq;
import com.tencent.supersonic.auth.api.authorization.response.AuthorizedResourceResp;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
public interface AuthService {
List<AuthGroup> queryAuthGroups(String domainId, Integer groupId);
@@ -14,5 +15,5 @@ public interface AuthService {
void removeAuthGroup(AuthGroup group);
AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, HttpServletRequest request);
AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, User user);
}

View File

@@ -1,67 +1,58 @@
package com.tencent.supersonic.auth.authentication.application;
package com.tencent.supersonic.auth.authentication.adaptor;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tencent.supersonic.auth.api.authentication.adaptor.UserAdaptor;
import com.tencent.supersonic.auth.api.authentication.pojo.Organization;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import com.tencent.supersonic.auth.api.authentication.service.UserService;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.domain.repository.UserRepository;
import com.tencent.supersonic.auth.authentication.domain.utils.UserTokenUtils;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.persistence.repository.UserRepository;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import com.tencent.supersonic.common.util.ContextUtils;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private UserRepository userRepository;
private UserTokenUtils userTokenUtils;
public UserServiceImpl(UserRepository userRepository, UserTokenUtils userTokenUtils) {
this.userRepository = userRepository;
this.userTokenUtils = userTokenUtils;
}
public class DefaultUserAdaptor implements UserAdaptor {
private List<UserDO> getUserDOList() {
UserRepository userRepository = ContextUtils.getBean(UserRepository.class);
return userRepository.getUserList();
}
private UserDO getUser(String name) {
UserRepository userRepository = ContextUtils.getBean(UserRepository.class);
return userRepository.getUser(name);
}
public boolean checkExist(UserWithPassword user) {
UserDO userDO = getUser(user.getName());
if (userDO == null) {
return false;
}
return userDO.getPassword().equals(user.getPassword());
}
@Override
public List<String> getUserNames() {
return getUserDOList().stream().map(UserDO::getName).collect(Collectors.toList());
}
@Override
public List<User> getUserList() {
List<UserDO> userDOS = getUserDOList();
return userDOS.stream().map(this::convert).collect(Collectors.toList());
}
@Override
public List<Organization> getOrganizationTree() {
return Lists.newArrayList();
}
private User convert(UserDO userDO) {
User user = new User();
BeanUtils.copyProperties(userDO, user);
return user;
}
@Override
public void register(UserReq userReq) {
UserRepository userRepository = ContextUtils.getBean(UserRepository.class);
List<String> userDOS = getUserNames();
if (userDOS.contains(userReq.getName())) {
throw new RuntimeException(String.format("user %s exist", userReq.getName()));
@@ -73,6 +64,7 @@ public class UserServiceImpl implements UserService {
@Override
public String login(UserReq userReq) {
UserTokenUtils userTokenUtils = ContextUtils.getBean(UserTokenUtils.class);
UserDO userDO = getUser(userReq.getName());
if (userDO == null) {
throw new RuntimeException("user not exist,please register");
@@ -85,5 +77,14 @@ public class UserServiceImpl implements UserService {
throw new RuntimeException("password not correct, please try again");
}
@Override
public List<User> getUserByOrg(String key) {
return Lists.newArrayList();
}
}
@Override
public Set<String> getUserAllOrgId(String userName) {
return Sets.newHashSet();
}
}

View File

@@ -1,51 +0,0 @@
package com.tencent.supersonic.auth.authentication.infrastructure.mapper;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDOExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserDOMapper {
/**
* @mbg.generated
*/
long countByExample(UserDOExample example);
/**
* @mbg.generated
*/
int deleteByPrimaryKey(Long id);
/**
* @mbg.generated
*/
int insert(UserDO record);
/**
* @mbg.generated
*/
int insertSelective(UserDO record);
/**
* @mbg.generated
*/
List<UserDO> selectByExample(UserDOExample example);
/**
* @mbg.generated
*/
UserDO selectByPrimaryKey(Long id);
/**
* @mbg.generated
*/
int updateByPrimaryKeySelective(UserDO record);
/**
* @mbg.generated
*/
int updateByPrimaryKey(UserDO record);
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.interceptor;
package com.tencent.supersonic.auth.authentication.interceptor;
import java.lang.annotation.ElementType;

View File

@@ -1,10 +1,10 @@
package com.tencent.supersonic.auth.authentication.domain.interceptor;
package com.tencent.supersonic.auth.authentication.interceptor;
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
import com.tencent.supersonic.auth.api.authentication.constant.UserConstants;
import com.tencent.supersonic.auth.authentication.application.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.domain.utils.UserTokenUtils;
import com.tencent.supersonic.common.util.context.S2ThreadContext;
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import com.tencent.supersonic.common.util.S2ThreadContext;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

View File

@@ -1,15 +1,15 @@
package com.tencent.supersonic.auth.authentication.domain.interceptor;
package com.tencent.supersonic.auth.authentication.interceptor;
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
import com.tencent.supersonic.auth.authentication.application.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.domain.utils.UserTokenUtils;
import com.tencent.supersonic.common.exception.AccessException;
import com.tencent.supersonic.common.util.context.ContextUtils;
import com.tencent.supersonic.common.util.context.S2ThreadContext;
import com.tencent.supersonic.common.util.context.ThreadContext;
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import com.tencent.supersonic.common.pojo.exception.AccessException;
import com.tencent.supersonic.common.util.ContextUtils;
import com.tencent.supersonic.common.util.S2ThreadContext;
import com.tencent.supersonic.common.util.ThreadContext;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -35,11 +35,14 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
setFakerUser(request);
return true;
}
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
AuthenticationIgnore ignore = method.getAnnotation(AuthenticationIgnore.class);
if (ignore != null) {
return true;
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
AuthenticationIgnore ignore = method.getAnnotation(AuthenticationIgnore.class);
if (ignore != null) {
return true;
}
}
String uri = request.getServletPath();

View File

@@ -1,12 +1,11 @@
package com.tencent.supersonic.auth.authentication.domain.interceptor;
package com.tencent.supersonic.auth.authentication.interceptor;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
@Configuration
public class InterceptorFactory implements WebMvcConfigurer {

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.dataobject;
package com.tencent.supersonic.auth.authentication.persistence.dataobject;
public class UserDO {

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.dataobject;
package com.tencent.supersonic.auth.authentication.persistence.dataobject;
import java.util.ArrayList;
import java.util.List;

View File

@@ -0,0 +1,22 @@
package com.tencent.supersonic.auth.authentication.persistence.mapper;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserDOMapper {
/**
* @mbg.generated
*/
int insert(UserDO record);
/**
* @mbg.generated
*/
List<UserDO> selectByExample(UserDOExample example);
}

View File

@@ -1,10 +1,10 @@
package com.tencent.supersonic.auth.authentication.infrastructure.repository;
package com.tencent.supersonic.auth.authentication.persistence.repository.impl;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDOExample;
import com.tencent.supersonic.auth.authentication.domain.repository.UserRepository;
import com.tencent.supersonic.auth.authentication.infrastructure.mapper.UserDOMapper;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample;
import com.tencent.supersonic.auth.authentication.persistence.mapper.UserDOMapper;
import com.tencent.supersonic.auth.authentication.persistence.repository.UserRepository;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Component;

View File

@@ -1,6 +1,6 @@
package com.tencent.supersonic.auth.authentication.domain.repository;
package com.tencent.supersonic.auth.authentication.persistence.repository;
import com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO;
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO;
import java.util.List;
public interface UserRepository {

View File

@@ -1,19 +1,22 @@
package com.tencent.supersonic.auth.authentication.rest;
import com.tencent.supersonic.auth.api.authentication.pojo.Organization;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import com.tencent.supersonic.auth.api.authentication.service.UserService;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
@RestController
@RequestMapping("/api/auth/user")
@@ -32,7 +35,6 @@ public class UserController {
return UserHolder.findUser(httpServletRequest, httpServletResponse);
}
@GetMapping("/getUserNames")
public List<String> getUserNames() {
return userService.getUserNames();
@@ -43,6 +45,21 @@ public class UserController {
return userService.getUserList();
}
@GetMapping("/getOrganizationTree")
public List<Organization> getOrganizationTree() {
return userService.getOrganizationTree();
}
@GetMapping("/getUserAllOrgId/{userName}")
public Set<String> getUserAllOrgId(@PathVariable("userName") String userName) {
return userService.getUserAllOrgId(userName);
}
@GetMapping("/getUserByOrg/{org}")
public List<User> getUserByOrg(@PathVariable("org") String org) {
return userService.getUserByOrg(org);
}
@PostMapping("/register")
public void register(@RequestBody UserReq userCmd) {
userService.register(userCmd);

View File

@@ -0,0 +1,51 @@
package com.tencent.supersonic.auth.authentication.service;
import com.tencent.supersonic.auth.api.authentication.pojo.Organization;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
import com.tencent.supersonic.auth.api.authentication.service.UserService;
import com.tencent.supersonic.auth.authentication.utils.ComponentFactory;
import java.util.List;
import java.util.Set;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Override
public List<String> getUserNames() {
return ComponentFactory.getUserAdaptor().getUserNames();
}
@Override
public List<User> getUserList() {
return ComponentFactory.getUserAdaptor().getUserList();
}
@Override
public Set<String> getUserAllOrgId(String userName) {
return ComponentFactory.getUserAdaptor().getUserAllOrgId(userName);
}
@Override
public List<User> getUserByOrg(String key) {
return ComponentFactory.getUserAdaptor().getUserByOrg(key);
}
@Override
public List<Organization> getOrganizationTree() {
return ComponentFactory.getUserAdaptor().getOrganizationTree();
}
@Override
public void register(UserReq userReq) {
ComponentFactory.getUserAdaptor().register(userReq);
}
@Override
public String login(UserReq userReq) {
return ComponentFactory.getUserAdaptor().login(userReq);
}
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.strategy;
package com.tencent.supersonic.auth.authentication.strategy;
import com.tencent.supersonic.auth.api.authentication.pojo.User;

View File

@@ -1,8 +1,8 @@
package com.tencent.supersonic.auth.authentication.domain.strategy;
package com.tencent.supersonic.auth.authentication.strategy;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.service.UserStrategy;
import com.tencent.supersonic.auth.authentication.domain.utils.UserTokenUtils;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.strategy;
package com.tencent.supersonic.auth.authentication.strategy;
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;

View File

@@ -0,0 +1,23 @@
package com.tencent.supersonic.auth.authentication.utils;
import com.tencent.supersonic.auth.api.authentication.adaptor.UserAdaptor;
import java.util.Objects;
import org.springframework.core.io.support.SpringFactoriesLoader;
public class ComponentFactory {
private static UserAdaptor userAdaptor;
public static UserAdaptor getUserAdaptor() {
if (Objects.isNull(userAdaptor)) {
userAdaptor = init(UserAdaptor.class);
}
return userAdaptor;
}
private static <T> T init(Class<T> factoryType) {
return SpringFactoriesLoader.loadFactories(factoryType,
Thread.currentThread().getContextClassLoader()).get(0);
}
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.auth.authentication.domain.utils;
package com.tencent.supersonic.auth.authentication.utils;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_ALGORITHM;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_CREATE_TIME;
@@ -9,11 +9,10 @@ import static com.tencent.supersonic.auth.api.authentication.constant.UserConsta
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_ID;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_NAME;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_PASSWORD;
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
import com.tencent.supersonic.common.exception.AccessException;
import com.tencent.supersonic.common.pojo.exception.AccessException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
@@ -22,9 +21,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class UserTokenUtils {
@@ -68,7 +69,9 @@ public class UserTokenUtils {
public UserWithPassword getUserWithPassword(HttpServletRequest request) {
String token = request.getHeader(authenticationConfig.getTokenHttpHeaderKey());
if (StringUtils.isBlank(token)) {
throw new AccessException("token is blank, get user failed");
String message = "token is blank, get user failed";
log.warn("{}, uri: {}", message, request.getServletPath());
throw new AccessException(message);
}
final Claims claims = getClaims(token);
Long userId = Long.parseLong(claims.getOrDefault(TOKEN_USER_ID, 0).toString());

View File

@@ -1,145 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.auth.authentication.infrastructure.mapper.UserDOMapper">
<resultMap id="BaseResultMap" type="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="password" jdbcType="VARCHAR" property="password" />
<result column="display_name" jdbcType="VARCHAR" property="displayName" />
<result column="email" jdbcType="VARCHAR" property="email" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.auth.authentication.persistence.mapper.UserDOMapper">
<resultMap id="BaseResultMap"
type="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="password" jdbcType="VARCHAR" property="password"/>
<result column="display_name" jdbcType="VARCHAR" property="displayName"/>
<result column="email" jdbcType="VARCHAR" property="email"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and
#{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem"
open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</trim>
</where>
</sql>
<sql id="Base_Column_List">
id
, name, password, display_name, email
</sql>
<select id="selectByExample"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample"
resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, name, password, display_name, email
</sql>
<select id="selectByExample" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDOExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from s2_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from s2_user
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from s2_user
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO">
insert into s2_user (id, name, password,
display_name, email)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{displayName,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO">
insert into s2_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="password != null">
password,
</if>
<if test="displayName != null">
display_name,
</if>
<if test="email != null">
email,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
#{displayName,jdbcType=VARCHAR},
</if>
<if test="email != null">
#{email,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDOExample" resultType="java.lang.Long">
select count(*) from s2_user
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO">
update s2_user
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
display_name = #{displayName,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.auth.authentication.domain.dataobject.UserDO">
update s2_user
set name = #{name,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
display_name = #{displayName,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<include refid="Base_Column_List"/>
from s2_user
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from s2_user
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from s2_user
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
insert into s2_user (id, name, password,
display_name, email)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{displayName,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
insert into s2_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="password != null">
password,
</if>
<if test="displayName != null">
display_name,
</if>
<if test="email != null">
email,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
#{displayName,jdbcType=VARCHAR},
</if>
<if test="email != null">
#{email,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample"
resultType="java.lang.Long">
select count(*) from s2_user
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByPrimaryKeySelective"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
update s2_user
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
display_name = #{displayName,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey"
parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
update s2_user
set name = #{name,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
display_name = #{displayName,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

View File

@@ -2,14 +2,14 @@ package com.tencent.supersonic.auth.authorization.application;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.service.UserService;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRes;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthResGrp;
import com.tencent.supersonic.auth.api.authorization.pojo.DimensionFilter;
import com.tencent.supersonic.auth.api.authorization.request.QueryAuthResReq;
import com.tencent.supersonic.auth.api.authorization.response.AuthorizedResourceResp;
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
import javax.servlet.http.HttpServletRequest;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRule;
import lombok.extern.slf4j.Slf4j;
@@ -17,11 +17,11 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Map;
import java.util.ArrayList;
import java.util.stream.Collectors;
@Service
@@ -30,8 +30,12 @@ public class AuthServiceImpl implements AuthService {
private JdbcTemplate jdbcTemplate;
public AuthServiceImpl(JdbcTemplate jdbcTemplate) {
private UserService userService;
public AuthServiceImpl(JdbcTemplate jdbcTemplate,
UserService userService) {
this.jdbcTemplate = jdbcTemplate;
this.userService = userService;
}
private List<AuthGroup> load() {
@@ -41,10 +45,10 @@ public class AuthServiceImpl implements AuthService {
}
@Override
public List<AuthGroup> queryAuthGroups(String domainId, Integer groupId) {
public List<AuthGroup> queryAuthGroups(String modelId, Integer groupId) {
return load().stream()
.filter(group -> (Objects.isNull(groupId) || groupId.equals(group.getGroupId()))
&& domainId.equals(group.getDomainId()))
&& modelId.equals(group.getModelId()))
.collect(Collectors.toList());
}
@@ -74,19 +78,23 @@ public class AuthServiceImpl implements AuthService {
@Override
public AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, HttpServletRequest request) {
List<AuthGroup> groups = getAuthGroups(req);
public AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, User user) {
Set<String> userOrgIds = userService.getUserAllOrgId(user.getName());
if (!CollectionUtils.isEmpty(userOrgIds)) {
req.setDepartmentIds(new ArrayList<>(userOrgIds));
}
List<AuthGroup> groups = getAuthGroups(req, user.getName());
AuthorizedResourceResp resource = new AuthorizedResourceResp();
Map<String, List<AuthGroup>> authGroupsByDomainId = groups.stream()
.collect(Collectors.groupingBy(AuthGroup::getDomainId));
Map<String, List<AuthGroup>> authGroupsByModelId = groups.stream()
.collect(Collectors.groupingBy(AuthGroup::getModelId));
Map<String, List<AuthRes>> reqAuthRes = req.getResources().stream()
.collect(Collectors.groupingBy(AuthRes::getDomainId));
.collect(Collectors.groupingBy(AuthRes::getModelId));
for (String domainId : reqAuthRes.keySet()) {
List<AuthRes> reqResourcesList = reqAuthRes.get(domainId);
for (String modelId : reqAuthRes.keySet()) {
List<AuthRes> reqResourcesList = reqAuthRes.get(modelId);
AuthResGrp rg = new AuthResGrp();
if (authGroupsByDomainId.containsKey(domainId)) {
List<AuthGroup> authGroups = authGroupsByDomainId.get(domainId);
if (authGroupsByModelId.containsKey(modelId)) {
List<AuthGroup> authGroups = authGroupsByModelId.get(modelId);
for (AuthRes reqRes : reqResourcesList) {
for (AuthGroup authRuleGroup : authGroups) {
List<AuthRule> authRules = authRuleGroup.getAuthRules();
@@ -105,8 +113,8 @@ public class AuthServiceImpl implements AuthService {
}
}
if (StringUtils.isNotEmpty(req.getDomainId())) {
List<AuthGroup> authGroups = authGroupsByDomainId.get(req.getDomainId());
if (StringUtils.isNotEmpty(req.getModelId())) {
List<AuthGroup> authGroups = authGroupsByModelId.get(req.getModelId());
if (!CollectionUtils.isEmpty(authGroups)) {
for (AuthGroup group : authGroups) {
if (group.getDimensionFilters() != null
@@ -119,29 +127,28 @@ public class AuthServiceImpl implements AuthService {
}
}
}
return resource;
}
private List<AuthGroup> getAuthGroups(QueryAuthResReq req) {
List<AuthGroup> groups = load().stream().
filter(group -> {
if (!Objects.equals(group.getDomainId(), req.getDomainId())) {
private List<AuthGroup> getAuthGroups(QueryAuthResReq req, String userName) {
List<AuthGroup> groups = load().stream()
.filter(group -> {
if (!Objects.equals(group.getModelId(), req.getModelId())) {
return false;
}
if (!CollectionUtils.isEmpty(group.getAuthorizedUsers()) && group.getAuthorizedUsers()
.contains(req.getUser())) {
.contains(userName)) {
return true;
}
for (String deparmentId : req.getDepartmentIds()) {
for (String departmentId : req.getDepartmentIds()) {
if (!CollectionUtils.isEmpty(group.getAuthorizedDepartmentIds())
&& group.getAuthorizedDepartmentIds().contains(deparmentId)) {
&& group.getAuthorizedDepartmentIds().contains(departmentId)) {
return true;
}
}
return false;
}).collect(Collectors.toList());
log.info("user:{} department:{} authGroups:{}", req.getUser(), req.getDepartmentIds(), groups);
log.info("user:{} department:{} authGroups:{}", userName, req.getDepartmentIds(), groups);
return groups;
}

View File

@@ -1,11 +1,14 @@
package com.tencent.supersonic.auth.authorization.rest;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.auth.api.authorization.request.QueryAuthResReq;
import com.tencent.supersonic.auth.api.authorization.response.AuthorizedResourceResp;
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -26,9 +29,9 @@ public class AuthController {
}
@GetMapping("/queryGroup")
public List<AuthGroup> queryAuthGroup(@RequestParam("domainId") String domainId,
public List<AuthGroup> queryAuthGroup(@RequestParam("modelId") String modelId,
@RequestParam(value = "groupId", required = false) Integer groupId) {
return authService.queryAuthGroups(domainId, groupId);
return authService.queryAuthGroups(modelId, groupId);
}
/**
@@ -62,12 +65,13 @@ public class AuthController {
* 查询有权限访问的受限资源id
*
* @param req
* @param request
* @return
*/
@PostMapping("/queryAuthorizedRes")
public AuthorizedResourceResp queryAuthorizedResources(@RequestBody QueryAuthResReq req,
HttpServletRequest request) {
return authService.queryAuthorizedResources(req, request);
HttpServletRequest request,
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return authService.queryAuthorizedResources(req, user);
}
}

View File

@@ -1,6 +1,6 @@
package com.tencent.supersonic.chat.api.component;
import com.tencent.supersonic.chat.api.request.QueryContextReq;
import com.tencent.supersonic.chat.api.pojo.QueryContext;
/**
* This interface defines the contract for a schema mapper that identifies references to schema
@@ -11,5 +11,5 @@ import com.tencent.supersonic.chat.api.request.QueryContextReq;
*/
public interface SchemaMapper {
void map(QueryContextReq queryContext);
void map(QueryContext queryContext);
}

View File

@@ -0,0 +1,9 @@
package com.tencent.supersonic.chat.api.component;
import com.tencent.supersonic.chat.api.pojo.CorrectionInfo;
import net.sf.jsqlparser.JSQLParserException;
public interface SemanticCorrector {
CorrectionInfo corrector(CorrectionInfo correctionInfo) throws JSQLParserException;
}

View File

@@ -2,10 +2,17 @@ package com.tencent.supersonic.chat.api.component;
import com.github.pagehelper.PageInfo;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.semantic.api.core.request.PageDimensionReq;
import com.tencent.supersonic.semantic.api.core.request.PageMetricReq;
import com.tencent.supersonic.semantic.api.core.response.*;
import com.tencent.supersonic.semantic.api.query.request.QuerySqlReq;
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
import com.tencent.supersonic.common.pojo.enums.AuthType;
import com.tencent.supersonic.semantic.api.model.request.PageDimensionReq;
import com.tencent.supersonic.semantic.api.model.request.PageMetricReq;
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
import com.tencent.supersonic.semantic.api.query.request.QueryDslReq;
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
import java.util.List;
@@ -25,27 +32,13 @@ import java.util.List;
public interface SemanticLayer {
QueryResultWithSchemaResp queryByStruct(QueryStructReq queryStructReq, User user);
QueryResultWithSchemaResp queryBySql(QuerySqlReq querySqlReq, User user);
DomainSchemaResp getDomainSchemaInfo(Long domain, Boolean cacheEnable);
List<DomainSchemaResp> getDomainSchemaInfo(List<Long> ids);
List<DomainResp> getDomainListForViewer();
List<DomainResp> getDomainListForAdmin();
PageInfo<DimensionResp> queryDimensionPage(PageDimensionReq pageDimensionCmd);
PageInfo<MetricResp> queryMetricPage(PageMetricReq pageMetricCmd);
// PageInfo<MetricResp> queryMetricPage(PageMetricReq pageMetricCmd);
//
// PageInfo<DimensionResp> queryDimensionPage(PageDimensionReq pageDimensionCmd);
//
// List<DomainResp> getDomainListForAdmin();
//
// List<DomainResp> getDomainListForViewer();
QueryResultWithSchemaResp queryByMultiStruct(QueryMultiStructReq queryMultiStructReq, User user);
QueryResultWithSchemaResp queryByDsl(QueryDslReq queryDslReq, User user);
List<ModelSchema> getModelSchema();
List<ModelSchema> getModelSchema(List<Long> ids);
ModelSchema getModelSchema(Long model, Boolean cacheEnable);
PageInfo<DimensionResp> getDimensionPage(PageDimensionReq pageDimensionCmd);
PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricCmd);
List<DomainResp> getDomainList(User user);
List<ModelResp> getModelList(AuthType authType, Long domainId, User user);
}

View File

@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.api.component;
import com.tencent.supersonic.chat.api.pojo.ChatContext;
import com.tencent.supersonic.chat.api.request.QueryContextReq;
import com.tencent.supersonic.chat.api.pojo.QueryContext;
/**
* This interface defines the contract for a semantic parser that can analyze natural language query
@@ -13,5 +13,5 @@ import com.tencent.supersonic.chat.api.request.QueryContextReq;
*/
public interface SemanticParser {
void parse(QueryContextReq queryContext, ChatContext chatContext);
void parse(QueryContext queryContext, ChatContext chatContext);
}

View File

@@ -2,7 +2,8 @@ package com.tencent.supersonic.chat.api.component;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
import com.tencent.supersonic.chat.api.response.QueryResultResp;
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
import org.apache.calcite.sql.parser.SqlParseException;
/**
* This class defines the contract for a semantic query that executes specific type of
@@ -12,7 +13,9 @@ public interface SemanticQuery {
String getQueryMode();
QueryResultResp execute(User user);
QueryResult execute(User user) throws SqlParseException;
SemanticParseInfo getParseInfo();
void setParseInfo(SemanticParseInfo parseInfo);
}

View File

@@ -6,6 +6,7 @@ import lombok.Data;
public class ChatContext {
private Integer chatId;
private Integer agentId;
private String queryText;
private SemanticParseInfo parseInfo = new SemanticParseInfo();
private String user;

View File

@@ -0,0 +1,21 @@
package com.tencent.supersonic.chat.api.pojo;
import com.tencent.supersonic.chat.api.pojo.request.QueryFilters;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CorrectionInfo {
private QueryFilters queryFilters;
private SemanticParseInfo parseInfo;
private String sql;
}

View File

@@ -0,0 +1,46 @@
package com.tencent.supersonic.chat.api.pojo;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import lombok.Data;
@Data
public class ModelSchema {
private SchemaElement model;
private Set<SchemaElement> metrics = new HashSet<>();
private Set<SchemaElement> dimensions = new HashSet<>();
private Set<SchemaElement> dimensionValues = new HashSet<>();
private SchemaElement entity = new SchemaElement();
public SchemaElement getElement(SchemaElementType elementType, long elementID) {
Optional<SchemaElement> element = Optional.empty();
switch (elementType) {
case ENTITY:
element = Optional.ofNullable(entity);
break;
case MODEL:
element = Optional.of(model);
break;
case METRIC:
element = metrics.stream().filter(e -> e.getId() == elementID).findFirst();
break;
case DIMENSION:
element = dimensions.stream().filter(e -> e.getId() == elementID).findFirst();
break;
case VALUE:
element = dimensionValues.stream().filter(e -> e.getId() == elementID).findFirst();
break;
default:
}
if (element.isPresent()) {
return element.get();
} else {
return null;
}
}
}

View File

@@ -0,0 +1,21 @@
package com.tencent.supersonic.chat.api.pojo;
import com.tencent.supersonic.chat.api.component.SemanticQuery;
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class QueryContext {
private QueryReq request;
private List<SemanticQuery> candidateQueries = new ArrayList<>();
private SchemaMapInfo mapInfo = new SchemaMapInfo();
public QueryContext(QueryReq request) {
this.request = request;
}
}

View File

@@ -1,12 +0,0 @@
package com.tencent.supersonic.chat.api.pojo;
import lombok.Data;
@Data
public class QueryMatchInfo {
SchemaElementType elementType;
String detectWord;
private Integer count = 0;
private double maxSimilarity;
}

View File

@@ -0,0 +1,57 @@
package com.tencent.supersonic.chat.api.pojo;
import com.google.common.base.Objects;
import java.io.Serializable;
import java.util.List;
import lombok.Data;
import lombok.Getter;
import lombok.Builder;
import lombok.NoArgsConstructor;
@Data
@Getter
@Builder
@NoArgsConstructor
public class SchemaElement implements Serializable {
private Long model;
private Long id;
private String name;
private String bizName;
private Long useCnt;
private SchemaElementType type;
private List<String> alias;
public SchemaElement(Long model, Long id, String name, String bizName,
Long useCnt, SchemaElementType type, List<String> alias) {
this.model = model;
this.id = id;
this.name = name;
this.bizName = bizName;
this.useCnt = useCnt;
this.type = type;
this.alias = alias;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SchemaElement schemaElement = (SchemaElement) o;
return Objects.equal(model, schemaElement.model) && Objects.equal(id,
schemaElement.id) && Objects.equal(name, schemaElement.name)
&& Objects.equal(bizName, schemaElement.bizName) && Objects.equal(
useCnt, schemaElement.useCnt) && Objects.equal(type, schemaElement.type);
}
@Override
public int hashCode() {
return Objects.hashCode(model, id, name, bizName, useCnt, type);
}
}

View File

@@ -13,15 +13,11 @@ import lombok.ToString;
@NoArgsConstructor
public class SchemaElementMatch {
SchemaElementType elementType;
int elementID;
SchemaElement element;
double similarity;
String detectWord;
String word;
Long frequency;
boolean isInherited;
}

View File

@@ -1,7 +1,7 @@
package com.tencent.supersonic.chat.api.pojo;
public enum SchemaElementType {
DOMAIN,
MODEL,
METRIC,
DIMENSION,
VALUE,

View File

@@ -7,26 +7,21 @@ import java.util.Set;
public class SchemaMapInfo {
private Map<Integer, List<SchemaElementMatch>> domainElementMatches = new HashMap<>();
private Map<Long, List<SchemaElementMatch>> modelElementMatches = new HashMap<>();
public Set<Integer> getMatchedDomains() {
return domainElementMatches.keySet();
public Set<Long> getMatchedModels() {
return modelElementMatches.keySet();
}
public List<SchemaElementMatch> getMatchedElements(Integer domain) {
return domainElementMatches.get(domain);
public List<SchemaElementMatch> getMatchedElements(Long model) {
return modelElementMatches.get(model);
}
public Map<Integer, List<SchemaElementMatch>> getDomainElementMatches() {
return domainElementMatches;
public Map<Long, List<SchemaElementMatch>> getModelElementMatches() {
return modelElementMatches;
}
public void setDomainElementMatches(
Map<Integer, List<SchemaElementMatch>> domainElementMatches) {
this.domainElementMatches = domainElementMatches;
}
public void setMatchedElements(Integer domain, List<SchemaElementMatch> elementMatches) {
domainElementMatches.put(domain, elementMatches);
public void setMatchedElements(Long model, List<SchemaElementMatch> elementMatches) {
modelElementMatches.put(model, elementMatches);
}
}

View File

@@ -1,34 +1,68 @@
package com.tencent.supersonic.chat.api.pojo;
import com.tencent.supersonic.common.enums.AggregateTypeEnum;
import com.tencent.supersonic.common.pojo.DateConf;
import com.tencent.supersonic.common.pojo.Order;
import com.tencent.supersonic.common.pojo.SchemaItem;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Comparator;
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
import com.tencent.supersonic.chat.api.pojo.response.EntityInfo;
import com.tencent.supersonic.common.pojo.DateConf;
import com.tencent.supersonic.common.pojo.Order;
import com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum;
import lombok.Data;
@Data
public class SemanticParseInfo {
String queryMode;
AggregateTypeEnum aggType = AggregateTypeEnum.NONE;
Long domainId = 0L;
String domainName;
Long entity = 0L;
Set<SchemaItem> metrics = new LinkedHashSet();
Set<SchemaItem> dimensions = new LinkedHashSet();
Set<Filter> dimensionFilters = new LinkedHashSet();
Set<Filter> metricFilters = new LinkedHashSet();
private Integer id;
private String queryMode;
private SchemaElement model;
private Set<SchemaElement> metrics = new TreeSet<>(new SchemaNameLengthComparator());
private Set<SchemaElement> dimensions = new LinkedHashSet();
private SchemaElement entity;
private AggregateTypeEnum aggType = AggregateTypeEnum.NONE;
private Set<QueryFilter> dimensionFilters = new LinkedHashSet();
private Set<QueryFilter> metricFilters = new LinkedHashSet();
private Set<Order> orders = new LinkedHashSet();
private DateConf dateInfo;
private Long limit;
private Boolean nativeQuery = false;
private Double bonus = 0d;
private double score;
private List<SchemaElementMatch> elementMatches = new ArrayList<>();
private Object info;
private Map<String, Object> properties = new HashMap<>();
private EntityInfo entityInfo;
public Long getModelId() {
return model != null ? model.getId() : 0L;
}
public String getModelName() {
return model != null ? model.getName() : "null";
}
private static class SchemaNameLengthComparator implements Comparator<SchemaElement> {
@Override
public int compare(SchemaElement o1, SchemaElement o2) {
int len1 = o1.getName().length();
int len2 = o2.getName().length();
if (len1 != len2) {
return len1 - len2;
} else {
return o1.getName().compareTo(o2.getName());
}
}
}
public Set<SchemaElement> getMetrics() {
Set<SchemaElement> metricSet = new TreeSet<>(new SchemaNameLengthComparator());
metricSet.addAll(metrics);
metrics = metricSet;
return metrics;
}
}

View File

@@ -0,0 +1,55 @@
package com.tencent.supersonic.chat.api.pojo;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class SemanticSchema implements Serializable {
private List<ModelSchema> modelSchemaList;
public SemanticSchema(List<ModelSchema> modelSchemaList) {
this.modelSchemaList = modelSchemaList;
}
public void add(ModelSchema schema) {
modelSchemaList.add(schema);
}
public Map<Long, String> getModelIdToName() {
return modelSchemaList.stream()
.collect(Collectors.toMap(a -> a.getModel().getId(), a -> a.getModel().getName(), (k1, k2) -> k1));
}
public List<SchemaElement> getDimensionValues() {
List<SchemaElement> dimensionValues = new ArrayList<>();
modelSchemaList.stream().forEach(d -> dimensionValues.addAll(d.getDimensionValues()));
return dimensionValues;
}
public List<SchemaElement> getDimensions() {
List<SchemaElement> dimensions = new ArrayList<>();
modelSchemaList.stream().forEach(d -> dimensions.addAll(d.getDimensions()));
return dimensions;
}
public List<SchemaElement> getMetrics() {
List<SchemaElement> metrics = new ArrayList<>();
modelSchemaList.stream().forEach(d -> metrics.addAll(d.getMetrics()));
return metrics;
}
public List<SchemaElement> getModels() {
List<SchemaElement> models = new ArrayList<>();
modelSchemaList.stream().forEach(d -> models.add(d.getModel()));
return models;
}
public List<SchemaElement> getEntities() {
List<SchemaElement> entities = new ArrayList<>();
modelSchemaList.stream().forEach(d -> entities.add(d.getEntity()));
return entities;
}
}

View File

@@ -0,0 +1,23 @@
package com.tencent.supersonic.chat.api.pojo.request;
import java.util.List;
import lombok.Data;
@Data
public class ChatAggConfigReq {
/**
* invisible dimensions/metrics
*/
private ItemVisibility visibility;
/**
* information about dictionary about the model
*/
private List<KnowledgeInfoReq> knowledgeInfos;
private KnowledgeAdvancedConfig globalKnowledgeConfig;
private ChatDefaultConfigReq chatDefaultConfig;
}

View File

@@ -0,0 +1,38 @@
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import java.util.List;
import lombok.Data;
import lombok.ToString;
/**
* extended information command about model
*/
@Data
@ToString
public class ChatConfigBaseReq {
private Long modelId;
/**
* the chatDetailConfig about the model
*/
private ChatDetailConfigReq chatDetailConfig;
/**
* the chatAggConfig about the model
*/
private ChatAggConfigReq chatAggConfig;
/**
* the recommended questions about the model
*/
private List<RecommendedQuestionReq> recommendedQuestions;
/**
* available status
*/
private StatusEnum status;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import lombok.Data;

View File

@@ -1,6 +1,6 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.common.enums.StatusEnum;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -10,6 +10,6 @@ import lombok.NoArgsConstructor;
public class ChatConfigFilter {
private Long id;
private Long domainId;
private Long modelId;
private StatusEnum status = StatusEnum.ONLINE;
}

View File

@@ -1,14 +1,13 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.common.constant.Constants;
import lombok.Data;
import com.tencent.supersonic.common.pojo.Constants;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data
public class ChatDefaultConfig {
public class ChatDefaultConfigReq {
private List<Long> dimensionIds = new ArrayList<>();
private List<Long> metricIds = new ArrayList<>();
@@ -24,4 +23,15 @@ public class ChatDefaultConfig {
*/
private String period = Constants.DAY;
private TimeMode timeMode = TimeMode.LAST;
public enum TimeMode {
/**
* date mode
* LAST - a certain time
* RECENT - a period time
*/
LAST, RECENT
}
}

View File

@@ -0,0 +1,23 @@
package com.tencent.supersonic.chat.api.pojo.request;
import java.util.List;
import lombok.Data;
@Data
public class ChatDetailConfigReq {
/**
* invisible dimensions/metrics
*/
private ItemVisibility visibility;
/**
* information about dictionary about the model
*/
private List<KnowledgeInfoReq> knowledgeInfos;
private KnowledgeAdvancedConfig globalKnowledgeConfig;
private ChatDefaultConfigReq chatDefaultConfig;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import java.util.List;
import lombok.AllArgsConstructor;
@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* the entity info about the domain
* the entity info about the model
*/
@Data
@AllArgsConstructor

View File

@@ -0,0 +1,19 @@
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
import lombok.Data;
@Data
public class ExecuteQueryReq {
private User user;
private Integer agentId;
private Integer chatId;
private String queryText;
private Long queryId;
private Integer parseId;
private SemanticParseInfo parseInfo;
private boolean saveAnswer = true;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import java.util.ArrayList;
import java.util.List;

View File

@@ -1,9 +1,8 @@
package com.tencent.supersonic.chat.domain.pojo.config;
import lombok.Data;
package com.tencent.supersonic.chat.api.pojo.request;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/**
* advanced knowledge config

View File

@@ -1,21 +1,18 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.common.enums.TypeEnums;
import java.util.List;
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
import javax.validation.constraints.NotNull;
import lombok.Data;
/**
* information about dictionary about the domain
* information about dictionary about the model
*/
@Data
public class KnowledgeInfo {
public class KnowledgeInfoReq {
/**
* metricIdDimensionIddomainId
* metricIdDimensionIdmodelId
*/
private Long itemId;
@@ -35,4 +32,4 @@ public class KnowledgeInfo {
private KnowledgeAdvancedConfig knowledgeAdvancedConfig;
}
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.domain.pojo.chat;
package com.tencent.supersonic.chat.api.pojo.request;
import lombok.Data;

View File

@@ -0,0 +1,21 @@
package com.tencent.supersonic.chat.api.pojo.request;
import lombok.Data;
@Data
public class PluginQueryReq {
private String name;
private String parseMode;
private String type;
private String model;
private String pattern;
private String createdBy;
}

View File

@@ -0,0 +1,24 @@
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
import com.tencent.supersonic.common.pojo.DateConf;
import com.tencent.supersonic.common.pojo.Order;
import java.util.HashSet;
import java.util.Set;
import lombok.Data;
@Data
public class QueryDataReq {
String queryMode;
SchemaElement model;
Set<SchemaElement> metrics = new HashSet<>();
Set<SchemaElement> dimensions = new HashSet<>();
Set<QueryFilter> dimensionFilters = new HashSet<>();
Set<QueryFilter> metricFilters = new HashSet<>();
private Set<Order> orders = new HashSet<>();
private DateConf dateInfo;
private Long limit;
private Boolean nativeQuery = false;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.api.pojo;
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.semantic.api.query.enums.FilterOperatorEnum;
import java.util.Objects;
@@ -7,7 +7,7 @@ import lombok.ToString;
@Data
@ToString(callSuper = true)
public class Filter {
public class QueryFilter {
private String bizName;
@@ -27,7 +27,7 @@ public class Filter {
if (o == null || getClass() != o.getClass()) {
return false;
}
Filter filter = (Filter) o;
QueryFilter filter = (QueryFilter) o;
return Objects.equals(bizName, filter.bizName) && Objects.equals(name, filter.name)
&& operator == filter.operator && Objects.equals(value, filter.value) && Objects.equals(
elementID, filter.elementID);

View File

@@ -1,16 +1,14 @@
package com.tencent.supersonic.chat.api.pojo;
package com.tencent.supersonic.chat.api.pojo.request;
import lombok.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Data;
@Data
public class QueryFilter {
private List<Filter> filters = new ArrayList<>();
public class QueryFilters {
private List<QueryFilter> filters = new ArrayList<>();
private Map<String, Object> params = new HashMap<>();
}

View File

@@ -0,0 +1,16 @@
package com.tencent.supersonic.chat.api.pojo.request;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import lombok.Data;
@Data
public class QueryReq {
private String queryText;
private Integer chatId;
private Long modelId = 0L;
private User user;
private QueryFilters queryFilters;
private boolean saveAnswer = true;
private Integer agentId;
}

View File

@@ -0,0 +1,16 @@
package com.tencent.supersonic.chat.api.pojo.request;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class RecommendedQuestionReq {
private String question;
}

View File

@@ -0,0 +1,10 @@
package com.tencent.supersonic.chat.api.pojo.response;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data
public class AggregateInfo {
private List<MetricInfo> metricInfos = new ArrayList<>();
}

View File

@@ -0,0 +1,25 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeAdvancedConfig;
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
import java.util.List;
import lombok.Data;
@Data
public class ChatAggRichConfigResp {
/**
* invisible dimensions/metrics
*/
private ItemVisibilityInfo visibility;
/**
* information about dictionary about the model
*/
private List<KnowledgeInfoReq> knowledgeInfos;
private KnowledgeAdvancedConfig globalKnowledgeConfig;
private ChatDefaultRichConfigResp chatDefaultConfig;
}

View File

@@ -0,0 +1,33 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.request.ChatAggConfigReq;
import com.tencent.supersonic.chat.api.pojo.request.ChatDetailConfigReq;
import com.tencent.supersonic.chat.api.pojo.request.RecommendedQuestionReq;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import java.util.Date;
import java.util.List;
import lombok.Data;
@Data
public class ChatConfigResp {
private Long id;
private Long modelId;
private ChatDetailConfigReq chatDetailConfig;
private ChatAggConfigReq chatAggConfig;
private List<RecommendedQuestionReq> recommendedQuestions;
/**
* available status
*/
private StatusEnum statusEnum;
private String createdBy;
private String updatedBy;
private Date createdAt;
private Date updatedAt;
}

View File

@@ -0,0 +1,34 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.request.RecommendedQuestionReq;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import java.util.Date;
import java.util.List;
import lombok.Data;
@Data
public class ChatConfigRichResp {
private Long id;
private Long modelId;
private String modelName;
private String bizName;
private ChatAggRichConfigResp chatAggRichConfig;
private ChatDetailRichConfigResp chatDetailRichConfig;
private List<RecommendedQuestionReq> recommendedQuestions;
/**
* available status
*/
private StatusEnum statusEnum;
private String createdBy;
private String updatedBy;
private Date createdAt;
private Date updatedAt;
}

View File

@@ -0,0 +1,30 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
import com.tencent.supersonic.chat.api.pojo.request.ChatDefaultConfigReq;
import com.tencent.supersonic.common.pojo.Constants;
import java.util.List;
import lombok.Data;
@Data
public class ChatDefaultRichConfigResp {
private List<SchemaElement> dimensions;
private List<SchemaElement> metrics;
/**
* default time span unit
*/
private Integer unit = 1;
/**
* default time type: day
* DAY, WEEK, MONTH, YEAR
*/
private String period = Constants.DAY;
private ChatDefaultConfigReq.TimeMode timeMode;
}

View File

@@ -0,0 +1,26 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeAdvancedConfig;
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
import java.util.List;
import lombok.Data;
@Data
public class ChatDetailRichConfigResp {
/**
* invisible dimensions/metrics
*/
private ItemVisibilityInfo visibility;
/**
* information about dictionary about the model
*/
private List<KnowledgeInfoReq> knowledgeInfos;
private KnowledgeAdvancedConfig globalKnowledgeConfig;
private ChatDefaultRichConfigResp chatDefaultConfig;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.api.pojo;
package com.tencent.supersonic.chat.api.pojo.response;
import lombok.Data;

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.api.pojo;
package com.tencent.supersonic.chat.api.pojo.response;
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +7,7 @@ import lombok.Data;
@Data
public class EntityInfo {
private DomainInfo domainInfo = new DomainInfo();
private ModelInfo modelInfo = new ModelInfo();
private List<DataInfo> dimensions = new ArrayList<>();
private List<DataInfo> metrics = new ArrayList<>();
private String entityId;

View File

@@ -0,0 +1,16 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
import java.util.List;
import lombok.Data;
@Data
public class EntityRichInfoResp {
/**
* entity alias
*/
private List<String> names;
private SchemaElement dimItem;
}

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.domain.pojo.config;
package com.tencent.supersonic.chat.api.pojo.response;
import java.util.List;
import lombok.Data;

View File

@@ -0,0 +1,15 @@
package com.tencent.supersonic.chat.api.pojo.response;
import java.util.Map;
import lombok.Data;
@Data
public class MetricInfo {
private String name;
private String dimension;
private String value;
private String date;
private Map<String, String> statistics;
}

View File

@@ -1,11 +1,11 @@
package com.tencent.supersonic.chat.api.pojo;
package com.tencent.supersonic.chat.api.pojo.response;
import java.io.Serializable;
import java.util.List;
import lombok.Data;
@Data
public class DomainInfo extends DataInfo implements Serializable {
public class ModelInfo extends DataInfo implements Serializable {
private List<String> words;
private String primaryEntityBizName;

View File

@@ -0,0 +1,30 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
import lombok.Data;
import lombok.Getter;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import java.util.List;
@Data
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ParseResp {
private Integer chatId;
private String queryText;
private Long queryId;
private ParseState state;
private List<SemanticParseInfo> selectedParses;
private List<SemanticParseInfo> candidateParses;
public enum ParseState {
COMPLETED,
PENDING,
FAILED
}
}

View File

@@ -1,11 +1,10 @@
package com.tencent.supersonic.chat.domain.pojo.chat;
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.response.QueryResultResp;
import java.util.Date;
import lombok.Data;
@Data
public class ChatQueryVO {
public class QueryResp {
private Long questionId;
private Date createTime;
@@ -13,5 +12,5 @@ public class ChatQueryVO {
private Integer score;
private String feedback;
private String queryText;
private QueryResultResp queryResponse;
private QueryResult queryResult;
}

View File

@@ -1,21 +1,21 @@
package com.tencent.supersonic.chat.api.response;
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.EntityInfo;
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
import com.tencent.supersonic.semantic.api.core.pojo.QueryAuthorization;
import com.tencent.supersonic.semantic.api.core.pojo.QueryColumn;
import com.tencent.supersonic.common.pojo.QueryAuthorization;
import com.tencent.supersonic.common.pojo.QueryColumn;
import java.util.List;
import java.util.Map;
import lombok.Data;
@Data
public class QueryResultResp {
public class QueryResult {
public EntityInfo entityInfo;
public AggregateInfo aggregateInfo;
private Long queryId;
private String queryMode;
private String querySql;
private int queryState;
private QueryState queryState = QueryState.EMPTY;
private List<QueryColumn> queryColumns;
private QueryAuthorization queryAuthorization;
private SemanticParseInfo chatContext;

View File

@@ -0,0 +1,8 @@
package com.tencent.supersonic.chat.api.pojo.response;
public enum QueryState {
SUCCESS,
SEARCH_EXCEPTION,
EMPTY,
INVALID;
}

View File

@@ -0,0 +1,14 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.request.RecommendedQuestionReq;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class RecommendQuestionResp {
private Long modelId;
private List<RecommendedQuestionReq> recommendedQuestions;
}

View File

@@ -0,0 +1,12 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
import java.util.List;
import lombok.Data;
@Data
public class RecommendResp {
private List<SchemaElement> dimensions;
private List<SchemaElement> metrics;
}

View File

@@ -0,0 +1,15 @@
package com.tencent.supersonic.chat.api.pojo.response;
import java.util.List;
import lombok.Data;
@Data
public class SearchResp {
private List<SearchResult> searchResults;
public SearchResp(List<SearchResult> searchResults) {
this.searchResults = searchResults;
}
}

View File

@@ -0,0 +1,45 @@
package com.tencent.supersonic.chat.api.pojo.response;
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
import java.util.Objects;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Setter
@Getter
@Builder
public class SearchResult {
private String recommend;
private String subRecommend;
private String modelName;
private Long modelId;
private SchemaElementType schemaElementType;
private boolean isComplete = true;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SearchResult searchResult1 = (SearchResult) o;
return Objects.equals(recommend, searchResult1.recommend) && Objects.equals(modelName,
searchResult1.modelName);
}
@Override
public int hashCode() {
return Objects.hash(recommend, modelName);
}
}

View File

@@ -0,0 +1,18 @@
package com.tencent.supersonic.chat.api.pojo.response;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class ShowCaseResp {
private Map<Long, List<QueryResp>> showCaseMap;
private int pageSize;
private int current;
}

View File

@@ -1,23 +0,0 @@
package com.tencent.supersonic.chat.api.request;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.api.component.SemanticQuery;
import com.tencent.supersonic.chat.api.pojo.QueryFilter;
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class QueryContextReq {
private String queryText;
private Integer chatId;
private Integer domainId = 0;
private User user;
private QueryFilter queryFilter;
private List<SemanticQuery> candidateQueries = new ArrayList<>();
private SchemaMapInfo mapInfo = new SchemaMapInfo();
private boolean saveAnswer = true;
}

Some files were not shown because too many files have changed in this diff Show More