mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
Compare commits
190 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f0ac2baf8 | ||
|
|
0226ebf341 | ||
|
|
24888228e5 | ||
|
|
717a2d26a9 | ||
|
|
d26eeb3367 | ||
|
|
e6ec689cb1 | ||
|
|
7773442fbf | ||
|
|
37d08007c4 | ||
|
|
07a981216f | ||
|
|
7a0ae9f075 | ||
|
|
7bb0f84bc3 | ||
|
|
d2e9d1bf85 | ||
|
|
da43f790c3 | ||
|
|
da6ffdab27 | ||
|
|
96339f425c | ||
|
|
b59c1303cc | ||
|
|
c8b6af4887 | ||
|
|
b56abd7348 | ||
|
|
8bfd80c2c0 | ||
|
|
d8bc6a02a4 | ||
|
|
5132b77953 | ||
|
|
dc63f4ef14 | ||
|
|
38b4154b9e | ||
|
|
6687856d59 | ||
|
|
c49f3e8f85 | ||
|
|
f96c0871f6 | ||
|
|
1d0b288922 | ||
|
|
5bfef816c4 | ||
|
|
da002338e6 | ||
|
|
1885bea3b8 | ||
|
|
2b2ce7fa53 | ||
|
|
5e70ac9317 | ||
|
|
fbe4114775 | ||
|
|
a3f17b3b68 | ||
|
|
82e2a7e1a3 | ||
|
|
af4a026af6 | ||
|
|
f096c44de0 | ||
|
|
e771efba3f | ||
|
|
679cf204c7 | ||
|
|
e080306b67 | ||
|
|
ee86924205 | ||
|
|
a45fe183d2 | ||
|
|
a1083a92c2 | ||
|
|
af0fe6d1b1 | ||
|
|
e939869348 | ||
|
|
5bcb76a1de | ||
|
|
5a052248dc | ||
|
|
61e7a1d2e9 | ||
|
|
528491717b | ||
|
|
7564256b0a | ||
|
|
c6aecd7860 | ||
|
|
b34268c236 | ||
|
|
ce0eec7aba | ||
|
|
6f620e7537 | ||
|
|
3e8283a7b6 | ||
|
|
3d4c078d95 | ||
|
|
a3d4f18df4 | ||
|
|
26cd73518d | ||
|
|
28f95ddf9e | ||
|
|
2fd22e0769 | ||
|
|
560c26fbf3 | ||
|
|
995c4f8ada | ||
|
|
391c0dccc8 | ||
|
|
9d921dc47f | ||
|
|
4e4943ffd1 | ||
|
|
e07e74064d | ||
|
|
c5fbd0b827 | ||
|
|
89c63cd44d | ||
|
|
bbd61ac937 | ||
|
|
8b88528938 | ||
|
|
474ade7206 | ||
|
|
20697efac1 | ||
|
|
d1ec6badce | ||
|
|
90f7a79380 | ||
|
|
ff20ae4006 | ||
|
|
1b05d6deb1 | ||
|
|
57a727bdff | ||
|
|
2bf30bd75e | ||
|
|
9315dc35f9 | ||
|
|
a655110f5f | ||
|
|
7c711f6105 | ||
|
|
24674fe0be | ||
|
|
f2888c7e6a | ||
|
|
61ecb6274d | ||
|
|
dcbb4dec03 | ||
|
|
d9916c9dc0 | ||
|
|
34b76ffd53 | ||
|
|
1e5cfb51df | ||
|
|
82b2552d9d | ||
|
|
210163a82a | ||
|
|
015f1e5204 | ||
|
|
e9dfb30ccf | ||
|
|
8cf5380cb8 | ||
|
|
bba0a2ff8d | ||
|
|
ca68c445c2 | ||
|
|
c64aa62456 | ||
|
|
d4cc53acae | ||
|
|
7f91993084 | ||
|
|
db9a3fa056 | ||
|
|
5ce81b3724 | ||
|
|
597ec19338 | ||
|
|
b024e4bc3a | ||
|
|
6c2583e364 | ||
|
|
172667d8d8 | ||
|
|
fb97c7b58b | ||
|
|
1a1839af24 | ||
|
|
4a876b97df | ||
|
|
2fd2c5690b | ||
|
|
96d8ba5ec4 | ||
|
|
4b288d9815 | ||
|
|
a7d367baa3 | ||
|
|
15ceca3102 | ||
|
|
871c88d167 | ||
|
|
6a66db7c0e | ||
|
|
4d6cbf31f7 | ||
|
|
2ae94fb38c | ||
|
|
a658b9c45f | ||
|
|
29694be64e | ||
|
|
32e2c1e39d | ||
|
|
782d4ead9e | ||
|
|
3d0183095b | ||
|
|
e9230b5421 | ||
|
|
ea5b63bf3a | ||
|
|
6466999dbc | ||
|
|
69bb64cdbf | ||
|
|
cfde267a06 | ||
|
|
e293be3ebf | ||
|
|
5af76fa7dc | ||
|
|
e548b57d97 | ||
|
|
d9de4aabdd | ||
|
|
1c7b09285f | ||
|
|
5555dc8c45 | ||
|
|
3831f9fdf1 | ||
|
|
92db381b6f | ||
|
|
1df1fe5ad6 | ||
|
|
9e72d239f1 | ||
|
|
0d9afb5d87 | ||
|
|
5474fe1d04 | ||
|
|
633c7eae07 | ||
|
|
48113b41dd | ||
|
|
5d32235c2d | ||
|
|
0334009c70 | ||
|
|
39fd16b918 | ||
|
|
c3ecc05715 | ||
|
|
f2a12e56b7 | ||
|
|
b5cc450758 | ||
|
|
67cbc43956 | ||
|
|
eb18857a9b | ||
|
|
39b5dde11d | ||
|
|
eadd20046e | ||
|
|
f8b818cb82 | ||
|
|
0509242242 | ||
|
|
a9d66b85cc | ||
|
|
abf440c4d4 | ||
|
|
91a6308d9e | ||
|
|
33eecc0cb1 | ||
|
|
57ee55b7da | ||
|
|
6bb317e1c7 | ||
|
|
da9ca36def | ||
|
|
87177155d5 | ||
|
|
82a3e30472 | ||
|
|
3f098a6364 | ||
|
|
9584d7bb2c | ||
|
|
915d4ec4c2 | ||
|
|
5bc88b78a9 | ||
|
|
dcb7f21241 | ||
|
|
aef60c6e83 | ||
|
|
c09b9428b2 | ||
|
|
5bc37fa953 | ||
|
|
bb0df82f58 | ||
|
|
96e94b3096 | ||
|
|
529c8dc79b | ||
|
|
4a867451d5 | ||
|
|
451ae1f6f0 | ||
|
|
357e2c03eb | ||
|
|
2ed7762210 | ||
|
|
d8f53a4e2f | ||
|
|
b3b9687041 | ||
|
|
008c1c35d8 | ||
|
|
91e27bcadb | ||
|
|
9c3f9f7f49 | ||
|
|
4648e8d875 | ||
|
|
5e9c960263 | ||
|
|
df9b469019 | ||
|
|
778f054a95 | ||
|
|
78d8e652cd | ||
|
|
2da0eb126a | ||
|
|
09bd330367 | ||
|
|
52b078e3c5 | ||
|
|
c166041e8d |
89
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
89
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
name: SuperSonic Bug report
|
||||
title: "[Bug] "
|
||||
description: Problems and issues with code of SuperSonic
|
||||
labels: bug
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you very much for submitting feedback to SuperSonic to help SuperSonic develop better.
|
||||
|
||||
If it is an idea or help wanted, please go to:
|
||||
[Github Discussion](https://github.com/tencentmusic/supersonic/discussions)
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Search before asking
|
||||
description: >
|
||||
Please make sure to search in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) first to see
|
||||
whether the same issue was reported already.
|
||||
options:
|
||||
- label: >
|
||||
I had searched in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) and found no similar
|
||||
issues.
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Version
|
||||
description: What is the current version
|
||||
placeholder: >
|
||||
Please provide the version you are using.
|
||||
If it is the trunk version, please input commit id.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: What's Wrong?
|
||||
description: Describe the bug.
|
||||
placeholder: >
|
||||
Describe the specific problem, the more detailed the better.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: What You Expected?
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: How to Reproduce?
|
||||
placeholder: >
|
||||
Please try to give reproducing steps to facilitate quick location of the problem.
|
||||
|
||||
- What actions were performed
|
||||
- Table building statement
|
||||
- Import statement
|
||||
- Cluster information: number of nodes, configuration, etc.
|
||||
|
||||
If it is hard to reproduce, please also explain the general scene.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Anything Else?
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Are you willing to submit PR?
|
||||
description: >
|
||||
We very much look forward to developers or users to help solve the SuperSonic problem together.
|
||||
If you are willing to submit a PR to fix this problem, please tick it.
|
||||
options:
|
||||
- label: Yes I am willing to submit a PR!
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: The Code of Conduct helps create a safe space for everyone. We require that everyone agrees to it.
|
||||
options:
|
||||
- label: >
|
||||
I agree to follow this project's
|
||||
[Code of Conduct](https://www.apache.org/foundation/policies/conduct)
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "Thanks for completing our form!"
|
||||
57
.github/ISSUE_TEMPLATE/enhancement_request.yml
vendored
Normal file
57
.github/ISSUE_TEMPLATE/enhancement_request.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
name: SuperSonic enhancement request
|
||||
description: Add an enhancement for SuperSonic
|
||||
title: "[Enhancement] "
|
||||
labels: enhancement
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you very much for your good enhancement for SuperSonic.
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Search before asking
|
||||
description: >
|
||||
Please make sure to search in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) first to see
|
||||
whether the same issue was reported already.
|
||||
options:
|
||||
- label: >
|
||||
I had searched in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) and found no similar
|
||||
issues.
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Description
|
||||
description: Describe the enhancement what you want, including motivation if it exists.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Solution
|
||||
placeholder: >
|
||||
Add overview of proposed solution.
|
||||
|
||||
Add related materials like links if they exist.
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Are you willing to submit PR?
|
||||
description: >
|
||||
We very much look forward to developers or users to help develop the SuperSonic together.
|
||||
If you are willing to submit a PR to implement this feature, please tick it.
|
||||
options:
|
||||
- label: Yes I am willing to submit a PR!
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: The Code of Conduct helps create a safe space for everyone. We require that everyone agrees to it.
|
||||
options:
|
||||
- label: >
|
||||
I agree to follow this project's
|
||||
[Code of Conduct](https://www.apache.org/foundation/policies/conduct)
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "Thanks for completing our form!"
|
||||
60
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
60
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
name: SuperSonic feature request
|
||||
description: Suggest an idea for SuperSonic
|
||||
title: "[Feature] "
|
||||
labels: feature
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you very much for your good ideas and suggestions for SuperSonic
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Search before asking
|
||||
description: >
|
||||
Please make sure to search in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) first to see
|
||||
whether the same issue was reported already.
|
||||
options:
|
||||
- label: >
|
||||
I had searched in the [issues](https://github.com/tencentmusic/supersonic/issues?q=is%3Aissue) and found no similar
|
||||
issues.
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Description
|
||||
description: Describe your ideas and needs.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Use case
|
||||
placeholder: >
|
||||
What problem does this feature mainly solve, or what scenarios it is suitable for.
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Related issues
|
||||
description: Is there currently another issue associated with this?
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Are you willing to submit PR?
|
||||
description: >
|
||||
We very much look forward to developers or users to help develop the SuperSonic together.
|
||||
If you are willing to submit a PR to implement this feature, please tick it.
|
||||
options:
|
||||
- label: Yes I am willing to submit a PR!
|
||||
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: The Code of Conduct helps create a safe space for everyone. We require that everyone agrees to it.
|
||||
options:
|
||||
- label: >
|
||||
I agree to follow this project's
|
||||
[Code of Conduct](https://www.apache.org/foundation/policies/conduct)
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "Thanks for completing our form!"
|
||||
58
.github/ISSUE_TEMPLATE/question_request.yml
vendored
Normal file
58
.github/ISSUE_TEMPLATE/question_request.yml
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
name: SuperSonic question request
|
||||
description: Ask a question about SuperSonic
|
||||
title: "[question] "
|
||||
labels: question
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
## Ask a Question about SuperSonic
|
||||
Please provide a detailed description of your question or the clarification you seek regarding the SuperSonic project.
|
||||
- type: textarea
|
||||
id: describe-question
|
||||
attributes:
|
||||
label: Describe your question
|
||||
description: Please provide a clear and concise description of your question.
|
||||
placeholder: "Type your question here..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: Provide any additional context or information
|
||||
description: If your question is related to a specific part of the SuperSonic project or if you have already looked through certain documentation, please provide that information here.
|
||||
placeholder: "Add context here..."
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: tried-to-resolve
|
||||
attributes:
|
||||
label: What have you tried to resolve your question
|
||||
description: Let us know what you have done to try and understand or resolve your question. This can help us provide you with the most useful guidance.
|
||||
placeholder: "I've already tried..."
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: environment
|
||||
attributes:
|
||||
label: Your environment
|
||||
description: Share details about your environment to help us reproduce the issue. Include your operating system, version of SuperSonic, and any other relevant details.
|
||||
placeholder: "OS, SuperSonic version, etc..."
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: screenshots-logs
|
||||
attributes:
|
||||
label: Screenshots or Logs
|
||||
description: If applicable, add screenshots or logs to help explain your problem.
|
||||
placeholder: "Paste your logs or attach screenshots here..."
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: additional-information
|
||||
attributes:
|
||||
label: Additional information
|
||||
description: Add any other context or details you think might be helpful for understanding your question.
|
||||
placeholder: "Any other information..."
|
||||
validations:
|
||||
required: false
|
||||
36
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
36
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Pull Request Template
|
||||
|
||||
## Description
|
||||
|
||||
Please include a summary of the change and which issue is fixed. Also include relevant motivation and context. List any dependencies that are required for this change.
|
||||
|
||||
## Type of change
|
||||
|
||||
Please delete options that are not relevant.
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
- [ ] This change requires a documentation update
|
||||
|
||||
## How Has This Been Tested?
|
||||
|
||||
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
|
||||
|
||||
- [ ] Test A
|
||||
- [ ] Test B
|
||||
|
||||
## Checklist:
|
||||
|
||||
- [ ] My code follows the style guidelines of this project
|
||||
- [ ] I have performed a self-review of my own code
|
||||
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||
- [ ] I have made corresponding changes to the documentation
|
||||
- [ ] My changes generate no new warnings
|
||||
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||
- [ ] New and existing unit tests pass locally with my changes
|
||||
- [ ] Any dependent changes have been merged and published in downstream modules
|
||||
|
||||
## Additional information
|
||||
|
||||
Any additional information, configuration or data that might be necessary to reproduce the issue.
|
||||
44
.github/workflows/centos-ci.yml
vendored
Normal file
44
.github/workflows/centos-ci.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
name: supersonic RHEL/CentOS CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: quay.io/centos/centos:stream8 # 使用 CentOS Stream 8 容器
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Reset DNF repositories
|
||||
run: |
|
||||
cd /etc/yum.repos.d/
|
||||
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
|
||||
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
|
||||
- name: Update DNF package index
|
||||
run: dnf makecache
|
||||
- name: Install Java and Maven with retry
|
||||
run: |
|
||||
for i in {1..5}; do
|
||||
dnf install -y java-1.8.0-openjdk-devel maven && break || sleep 15
|
||||
done
|
||||
- name: Verify Java and Maven installation
|
||||
run: |
|
||||
java -version
|
||||
mvn -version
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
- name: Test with Maven
|
||||
run: mvn test
|
||||
23
README.md
23
README.md
@@ -1,4 +1,4 @@
|
||||
[中文介绍](README_CN.md) | [文档中心](https://github.com/tencentmusic/supersonic/wiki)
|
||||
[中文版](README_CN.md) | [日本語版](README_JP.md) | [Docs](https://supersonicbi.github.io/)
|
||||
|
||||

|
||||
|
||||
@@ -9,11 +9,11 @@ SuperSonic is the next-generation BI platform that integrates **Chat BI** (power
|
||||
- Chat BI's Text2SQL gets augmented with context-retrieval from semantic models.
|
||||
- Headless BI's query interface gets extended with natural language API.
|
||||
|
||||
<img src="./docs/images/supersonic_ideas.png" height="75%" width="75%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_ideas.png" height="75%" width="75%" />
|
||||
|
||||
SuperSonic provides a **Chat BI 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 metric/dimension/tag, along with their meaning and relationships) through a **Headless BI interface**. Meanwhile, SuperSonic is designed to be extensible and composable, allowing custom implementations to be added and configured with Java SPI.
|
||||
|
||||
<img src="./docs/images/supersonic_demo.gif" height="100%" width="100%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_demo.gif" height="100%" width="100%" />
|
||||
|
||||
## Motivation
|
||||
|
||||
@@ -40,7 +40,7 @@ With these ideas in mind, we develop SuperSonic as a practical reference impleme
|
||||
|
||||
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="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_components.png" height="65%" width="65%" />
|
||||
|
||||
- **Knowledge Base:** extracts schema information periodically from the semantic models and build dictionary and index to facilitate schema mapping.
|
||||
|
||||
@@ -52,10 +52,15 @@ The high-level architecture and main process flow is as follows:
|
||||
|
||||
- **Semantic Translator:** converts semantic query statement into SQL statement that can be executed against physical data models.
|
||||
|
||||
- **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.
|
||||
- **Chat Plugin:** extends functionality with third-party tools. Given a list of configured plugins with descriptions and sample questions, an LLM will be leveraged to select the most suitable one.
|
||||
|
||||
- **Chat Memory:** encapsulates a collection of historical query trajectories that can be recalled to facilitate few-shot prompting.
|
||||
|
||||
## Quick Demo
|
||||
### Online playground
|
||||
Visit http://117.72.46.148:9080 to register and experience as a new user. Please do not modify system configurations. We will restart to reset configurations regularly every weekend.
|
||||
|
||||
### Local build
|
||||
SuperSonic comes with sample semantic models as well as chat conversations that can be used as a starting point. Please follow the steps:
|
||||
|
||||
- Download the latest prebuilt binary from the [release page](https://github.com/tencentmusic/supersonic/releases)
|
||||
@@ -64,10 +69,14 @@ SuperSonic comes with sample semantic models as well as chat conversations that
|
||||
|
||||
## Build and Development
|
||||
|
||||
Please refer to project [wiki](https://github.com/tencentmusic/supersonic/wiki).
|
||||
Please refer to project [Docs](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/).
|
||||
|
||||
## WeChat Contact
|
||||
|
||||
Please follow SuperSonic wechat official account:
|
||||
|
||||
<img src="./docs/images/supersonic_wechat_oa.png" height="50%" width="50%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_wechat_oa.png" height="50%" width="50%" />
|
||||
|
||||
Welcome to join the WeChat community:
|
||||
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_wechat.png" height="50%" width="50%" />
|
||||
|
||||
23
README_CN.md
23
README_CN.md
@@ -1,3 +1,5 @@
|
||||
[English](README.md) | [日本語版](README_JP.md) | [文档中心](https://supersonicbi.github.io/)
|
||||
|
||||
# SuperSonic
|
||||
|
||||
**SuperSonic融合Chat BI(powered by LLM)和Headless BI(powered by 语义层)打造新一代的BI平台**。这种融合确保了Chat BI能够与传统BI一样访问统一化治理的语义数据模型。此外,两种BI新范式都从中获得收益:
|
||||
@@ -5,11 +7,11 @@
|
||||
- Chat BI的Text2SQL生成通过检索语义数据模型得到增强。
|
||||
- Headless BI的查询接口通过支持自然语言API得到拓展。
|
||||
|
||||
<img src="./docs/images/supersonic_ideas.png" height="75%" width="75%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_ideas.png" height="75%" width="75%" />
|
||||
|
||||
通过SuperSonic的问答对话界面,用户能够使用自然语言查询数据,系统会选择合适的可视化图表呈现结果。SuperSonic不需要修改或复制数据,只需要在物理数据模型之上构建逻辑语义模型(定义指标/维度/实体/标签,以及它们的业务含义、相互关系等),即可开启数据问答体验。与此同时,SuperSonic被设计为可插拔的框架,采用Java SPI机制来扩展定制功能。
|
||||
|
||||
<img src="./docs/images/supersonic_demo.gif" height="100%" width="100%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_demo.gif" height="100%" width="100%" />
|
||||
|
||||
## 项目动机
|
||||
|
||||
@@ -36,7 +38,7 @@
|
||||
|
||||
SuperSonic的整体架构和主流程如下图所示:
|
||||
|
||||
<img src="./docs/images/supersonic_components.png" height="65%" width="65%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_components.png" height="65%" width="65%" />
|
||||
|
||||
- **模型知识库(Knowledge Base):** 定期从语义模型中提取相关的模式信息,构建词典和索引,以便后续的模式映射。
|
||||
|
||||
@@ -50,8 +52,15 @@ SuperSonic的整体架构和主流程如下图所示:
|
||||
|
||||
- **问答插件(Chat Plugin):** 通过第三方工具扩展功能。给定所有配置的插件及其功能描述和示例问题,大语言模型将选择最合适的插件。
|
||||
|
||||
- **问答记忆(Chat Memory):** 将历史的查询轨迹进行封装,可被召回作为few-shot样例嵌入提示词。
|
||||
|
||||
## 快速体验
|
||||
|
||||
### 线上环境体验
|
||||
访问http://117.72.46.148:9080 注册新用户体验. 请勿修改系统配置。我们每周末定期重启重置配置。
|
||||
|
||||
### 本地构建
|
||||
|
||||
SuperSonic自带样例的语义模型和问答对话,只需以下三步即可快速体验:
|
||||
|
||||
- 从[release page](https://github.com/tencentmusic/supersonic/releases)下载预先构建好的发行包
|
||||
@@ -60,10 +69,14 @@ SuperSonic自带样例的语义模型和问答对话,只需以下三步即可
|
||||
|
||||
## 如何构建和部署
|
||||
|
||||
请参考项目[wiki](https://github.com/tencentmusic/supersonic/wiki)。
|
||||
请参考项目[文档](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/)。
|
||||
|
||||
## 微信联系方式
|
||||
|
||||
欢迎关注微信公众号:
|
||||
|
||||
<img src="./docs/images/supersonic_wechat_oa.png" height="50%" width="50%" align="center"/>
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_wechat_oa.png" height="50%" width="50%" />
|
||||
|
||||
欢迎加入微信社群:
|
||||
|
||||
<img src="https://github.com/supersonicbi/supersonic-website/blob/main/static/img/supersonic_wechat.png" height="50%" width="50%" />
|
||||
|
||||
78
README_JP.md
Normal file
78
README_JP.md
Normal file
@@ -0,0 +1,78 @@
|
||||
[英文版](README.md) | [中国語版](README_CN.md)
|
||||
|
||||
# SuperSonic
|
||||
|
||||
**SuperSonicは、LLM(大規模言語モデル)によるChat BIと、セマンティックレイヤーによるHeadless BIを統合した次世代のBIプラットフォームです。** この統合により、Chat BIは従来のBIと同様に、統一されたガバナンスされたセマンティックデータモデルにアクセスできます。さらに、両方のBIパラダイムは統合から恩恵を受けます:
|
||||
|
||||
- Chat BIのText2SQLは、セマンティックモデルからのコンテキスト検索によって強化されます。
|
||||
- Headless BIのクエリインターフェースは、自然言語APIによって拡張されます。
|
||||
|
||||

|
||||
|
||||
SuperSonicは、ユーザーが自然言語でデータをクエリし、適切なチャートで結果を視覚化できる**Chat BIインターフェース**を提供します。このような体験を実現するために必要なのは、**Headless BIインターフェース**を通じて論理的なセマンティックモデル(メトリック/ディメンション/タグの定義、それらの意味と関係など)を構築することだけです。同時に、SuperSonicは拡張可能で構成可能な設計を採用しており、Java SPIを使用してカスタム実装を追加および設定できます。
|
||||
|
||||

|
||||
|
||||
## プロジェクトの動機
|
||||
|
||||
ChatGPTのような大規模言語モデル(LLM)の出現は、情報検索の方法を再定義し、データ分析分野における新しいパラダイムであるChat BIをリードしています。Chat BIを実装するために、学術界と産業界は主に、自然言語をSQLに変換するLLMの能力を活用することに焦点を当てています。これは一般にText2SQLまたはNL2SQLと呼ばれます。一部のアプローチは有望な結果を示していますが、大規模な実世界のアプリケーションでの**信頼性**はまだ不十分です。
|
||||
|
||||
一方で、統一されたセマンティックデータモデルを構築することに焦点を当てた別の新興パラダイムであるHeadless BIも、大きな注目を集めています。Headless BIは、オープンAPIを介して一貫したデータセマンティクスを公開するユニバーサルセマンティックレイヤーを通じて実装されます。
|
||||
|
||||
私たちの観点から見ると、Chat BIとHeadless BIの統合は、Text2SQL生成を2つの側面で強化する可能性があります:
|
||||
|
||||
1. データセマンティクス(ビジネス用語、列の値など)をプロンプトに組み込むことで、LLMがセマンティクスをよりよく理解し、**幻覚を減らす**ことができます。
|
||||
2. 高度なSQL構文(結合、式など)の生成をLLMからセマンティックレイヤーにオフロードすることで、**複雑さを減らす**ことができます。
|
||||
|
||||
これらのアイデアを念頭に置いて、私たちはSuperSonicプロジェクトを開発し、実際の製品でそれを使用しています。同時に、SuperSonicを拡張可能なフレームワークとしてオープンソース化し、データクエリ対話分野のさらなる発展を促進したいと考えています。
|
||||
|
||||
## 初期設定で利用可能な機能
|
||||
|
||||
- *ビジネスユーザー*が自然言語クエリを入力できる組み込みのChat BIインターフェース。
|
||||
- *分析エンジニア*がセマンティックモデルを構築できる組み込みのHeadless BIインターフェース。
|
||||
- 特定のシナリオ(例:デモンストレーション、統合テスト)で推論効率を向上させるための組み込みのルールベースのセマンティックパーサー。
|
||||
- 入力自動補完、マルチターン会話、クエリ後の質問推奨などの高度な機能をサポート。
|
||||
- データセットレベル、列レベル、行レベルの3レベルのデータアクセス制御をサポート。
|
||||
|
||||
## 拡張可能なコンポーネント
|
||||
|
||||
高レベルのアーキテクチャとメインのプロセスフローは以下の通りです:
|
||||
|
||||

|
||||
|
||||
- **モデル知識ベース(Knowledge Base):** セマンティックモデルから定期的にスキーマ情報を抽出し、辞書とインデックスを構築して、スキーママッピングを容易にします。
|
||||
|
||||
- **スキーママッパー(Schema Mapper):** ユーザークエリ内のスキーマ要素(メトリック/ディメンション/エンティティ/値)を識別します。クエリテキストを知識ベースと照合します。
|
||||
|
||||
- **セマンティックパーサー(Semantic Parser):** ユーザークエリを理解し、セマンティッククエリステートメントS2SQLを生成します。
|
||||
|
||||
- **セマンティック修正器(Semantic Corrector):** セマンティッククエリステートメントの妥当性をチェックし、必要に応じて修正と最適化を行います。
|
||||
|
||||
- **セマンティックトランスレーター(Semantic Translator):** セマンティッククエリステートメントを、物理データモデル上で実行可能なSQLステートメントに変換します。
|
||||
|
||||
- **チャットプラグイン(Chat Plugin):** サードパーティツールで機能を拡張します。すべての設定されたプラグインとその機能説明、サンプル質問が与えられた場合、LLMは最も適切なプラグインを選択します。
|
||||
|
||||
## クイックデモ
|
||||
### オンラインプレイグラウンド
|
||||
http://117.72.46.148:9080 にアクセスして、新規ユーザーとして登録して体験してください。システム設定を変更しないでください。毎週末に定期的に再起動して設定をリセットします。
|
||||
|
||||
### ローカルビルド
|
||||
SuperSonicには、サンプルのセマンティックモデルとチャット会話が付属しており、以下の手順で簡単に体験できます:
|
||||
|
||||
- [リリースページ](https://github.com/tencentmusic/supersonic/releases)から最新のプリビルドバイナリをダウンロード
|
||||
- スクリプト "assembly/bin/supersonic-daemon.sh start" を実行して、スタンドアロンJavaサービスを起動
|
||||
- ブラウザで http://localhost:9080 にアクセスして探索を開始
|
||||
|
||||
## ビルドと開発
|
||||
|
||||
プロジェクト[ドキュメント](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/)を参照してください。
|
||||
|
||||
## WeChat連絡先
|
||||
|
||||
SuperSonicの公式WeChatアカウントをフォローしてください:
|
||||
|
||||

|
||||
|
||||
WeChatコミュニティに参加することを歓迎します:
|
||||
|
||||

|
||||
@@ -2,7 +2,8 @@
|
||||
setlocal enabledelayedexpansion
|
||||
chcp 65001
|
||||
|
||||
call supersonic-common.bat %*
|
||||
set "sbinDir=%~dp0"
|
||||
call %sbinDir%/supersonic-common.bat %*
|
||||
|
||||
set "service=%~1"
|
||||
|
||||
@@ -22,12 +23,7 @@ del temp.txt
|
||||
cd %baseDir%
|
||||
|
||||
|
||||
if "%service%"=="%pyllm_service%" (
|
||||
echo start installing python modules required by supersonic-pyllm: %pip_path%
|
||||
%pip_path% install -r %projectDir%\headless\python\requirements.txt"
|
||||
echo install python modules success
|
||||
goto :EOF
|
||||
) else if "%service%"=="webapp" (
|
||||
if "%service%"=="webapp" (
|
||||
call :buildWebapp
|
||||
tar xvf supersonic-webapp.tar.gz
|
||||
move /y supersonic-webapp webapp
|
||||
@@ -44,7 +40,7 @@ if "%service%"=="%pyllm_service%" (
|
||||
:buildJavaService
|
||||
set "model_name=%service%"
|
||||
echo "starting building supersonic-%model_name% service"
|
||||
call mvn -f %projectDir%\launchers\%model_name% clean package -DskipTests
|
||||
call mvn -f %projectDir% clean package -DskipTests
|
||||
IF ERRORLEVEL 1 (
|
||||
ECHO Failed to build backend Java modules.
|
||||
EXIT /B 1
|
||||
|
||||
@@ -44,6 +44,8 @@ function packageRelease {
|
||||
service_name=launchers-${model_name}-${MVN_VERSION}
|
||||
echo "starting packaging supersonic release"
|
||||
cd $buildDir
|
||||
[ -d "$release_dir" ] && rm -rf "$release_dir"
|
||||
[ -f "$release_dir.zip" ] && rm -f "$release_dir.zip"
|
||||
mkdir $release_dir
|
||||
# package webapp
|
||||
tar xvf supersonic-webapp.tar.gz
|
||||
@@ -63,15 +65,11 @@ function packageRelease {
|
||||
}
|
||||
|
||||
#1. build backend services
|
||||
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||
echo "start installing python modules required by supersonic-pyllm: ${pip_path}"
|
||||
requirementPath=$projectDir/headless/python/requirements.txt
|
||||
${pip_path} install -r ${requirementPath}
|
||||
echo "install python modules success"
|
||||
elif [ "$service" == "webapp" ]; then
|
||||
if [ "$service" == "webapp" ]; then
|
||||
buildWebapp
|
||||
target_path=$projectDir/launchers/$STANDALONE_SERVICE/target/classes
|
||||
tar xvf $projectDir/webapp/supersonic-webapp.tar.gz -C $target_path
|
||||
rm -rf $target_path/webapp
|
||||
mv $target_path/supersonic-webapp $target_path/webapp
|
||||
else
|
||||
buildJavaService $service
|
||||
|
||||
@@ -2,8 +2,5 @@ set "sbinDir=%~dp0"
|
||||
set "baseDir=%~dp0.."
|
||||
set "buildDir=%baseDir%\build"
|
||||
set "main_class=com.tencent.supersonic.StandaloneLauncher"
|
||||
set "python_path=python"
|
||||
set "pip_path=pip3"
|
||||
set "standalone_service=standalone"
|
||||
set "pyllm_service=pyllm"
|
||||
set "projectDir=%baseDir%\.."
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# environment parameters
|
||||
python_path=${PYTHON_PATH:-"python3"}
|
||||
pip_path=${PIP_PATH:-"pip3"}
|
||||
|
||||
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
||||
baseDir=$(cd "$sbinDir/.." && pwd -P)
|
||||
runtimeDir=$baseDir/runtime
|
||||
@@ -12,13 +9,8 @@ projectDir=$baseDir/..
|
||||
|
||||
readonly CHAT_APP_NAME="supersonic_chat"
|
||||
readonly HEADLESS_APP_NAME="supersonic_headless"
|
||||
readonly PYLLM_APP_NAME="supersonic_pyllm"
|
||||
readonly STANDALONE_APP_NAME="supersonic_standalone"
|
||||
|
||||
readonly CHAT_SERVICE="chat"
|
||||
readonly HEADLESS_SERVICE="headless"
|
||||
readonly PYLLM_SERVICE="pyllm"
|
||||
readonly STANDALONE_SERVICE="standalone"
|
||||
|
||||
readonly PYLLM_HOST="127.0.0.1"
|
||||
readonly PYLLM_PORT="9092"
|
||||
readonly STANDALONE_SERVICE="standalone"
|
||||
@@ -2,20 +2,23 @@
|
||||
setlocal
|
||||
chcp 65001
|
||||
|
||||
call supersonic-common.bat %*
|
||||
call %sbinDir%/../conf/supersonic-env.bat %*
|
||||
set "sbinDir=%~dp0"
|
||||
call %sbinDir%/supersonic-common.bat %*
|
||||
|
||||
set "command=%~1"
|
||||
set "service=%~2"
|
||||
set "profile=%~3"
|
||||
|
||||
if "%service%"=="" (
|
||||
set "service=%standalone_service%"
|
||||
)
|
||||
set "model_name=%service%"
|
||||
IF "%service%"=="pyllm" (
|
||||
set "llmProxy=PythonLLMProxy"
|
||||
set "model_name=%standalone_service%"
|
||||
|
||||
if "%profile%"=="" (
|
||||
set "profile=local"
|
||||
)
|
||||
|
||||
set "model_name=%service%"
|
||||
|
||||
cd %baseDir%
|
||||
|
||||
if "%command%"=="restart" (
|
||||
@@ -36,63 +39,29 @@ if "%command%"=="restart" (
|
||||
goto :EOF
|
||||
)
|
||||
|
||||
|
||||
: start
|
||||
if "%service%"=="%pyllm_service%" (
|
||||
call :runPythonService
|
||||
call :runJavaService
|
||||
goto :EOF
|
||||
)
|
||||
:start
|
||||
call :runJavaService
|
||||
goto :EOF
|
||||
|
||||
|
||||
: stop
|
||||
call :stopPythonService
|
||||
:stop
|
||||
call :stopJavaService
|
||||
goto :EOF
|
||||
|
||||
|
||||
: reloadExamples
|
||||
set "pythonRunDir=%baseDir%\pyllm"
|
||||
cd "%pythonRunDir%\sql"
|
||||
start %python_path% examples_reload_run.py
|
||||
goto :EOF
|
||||
|
||||
|
||||
: runJavaService
|
||||
:runJavaService
|
||||
echo 'java service starting, see logs in logs/'
|
||||
set "libDir=%baseDir%\lib"
|
||||
set "confDir=%baseDir%\conf"
|
||||
set "webDir=%baseDir%\webapp"
|
||||
set "logDir=%baseDir%\logs"
|
||||
set "classpath=%baseDir%;%webDir%;%libDir%\*;%confDir%"
|
||||
set "java-command=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%"
|
||||
set "java-command=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Dspring.profiles.active=%profile% -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%"
|
||||
if not exist %logDir% mkdir %logDir%
|
||||
start /B java %java-command% >nul 2>&1
|
||||
timeout /t 10 >nul
|
||||
echo 'java service started'
|
||||
goto :EOF
|
||||
|
||||
|
||||
: runPythonService
|
||||
echo 'python service starting, see logs in pyllm\pyllm.log'
|
||||
set "pythonRunDir=%baseDir%\pyllm"
|
||||
start /B %python_path% %pythonRunDir%\supersonic_pyllm.py > %pythonRunDir%\pyllm.log 2>&1
|
||||
timeout /t 10 >nul
|
||||
echo 'python service started'
|
||||
goto :EOF
|
||||
|
||||
|
||||
: stopPythonService
|
||||
for /f "tokens=2" %%i in ('tasklist ^| findstr /i "python"') do (
|
||||
taskkill /PID %%i /F
|
||||
echo "python service (PID = %%i) is killed."
|
||||
)
|
||||
goto :EOF
|
||||
|
||||
|
||||
: stopJavaService
|
||||
:stopJavaService
|
||||
for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do (
|
||||
taskkill /PID %%i /F
|
||||
echo "java service (PID = %%i) is killed."
|
||||
|
||||
@@ -3,21 +3,19 @@
|
||||
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
||||
source $sbinDir/supersonic-common.sh
|
||||
|
||||
set -a
|
||||
source $sbinDir/../conf/supersonic-env.sh
|
||||
set +a
|
||||
|
||||
command=$1
|
||||
service=$2
|
||||
profile=$3
|
||||
|
||||
if [ -z "$service" ]; then
|
||||
service=${STANDALONE_SERVICE}
|
||||
fi
|
||||
|
||||
model_name=$service
|
||||
if [ "$service" == "pyllm" ]; then
|
||||
model_name=${STANDALONE_SERVICE}
|
||||
export llmProxy=PythonLLMProxy
|
||||
if [ -z "$profile" ]; then
|
||||
profile="local"
|
||||
fi
|
||||
|
||||
model_name=$service
|
||||
cd $baseDir
|
||||
|
||||
function setMainClass {
|
||||
@@ -40,11 +38,6 @@ function setAppName {
|
||||
fi
|
||||
}
|
||||
|
||||
function reloadExamples {
|
||||
cd $baseDir/pyllm/sql
|
||||
${python_path} examples_reload_run.py
|
||||
}
|
||||
|
||||
function runJavaService {
|
||||
javaRunDir=$baseDir
|
||||
local_app_name=$1
|
||||
@@ -66,115 +59,53 @@ function runJavaService {
|
||||
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
||||
fi
|
||||
export PATH=$JAVA_HOME/bin:$PATH
|
||||
command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class
|
||||
command="-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m $main_class"
|
||||
|
||||
mkdir -p $javaRunDir/logs
|
||||
if [[ "$is_test" == "true" ]]; then
|
||||
java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
||||
else
|
||||
java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log &
|
||||
fi
|
||||
java -Dspring.profiles.active="$profile" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
||||
}
|
||||
|
||||
function runPythonService {
|
||||
pythonRunDir=$baseDir/pyllm
|
||||
cd $pythonRunDir
|
||||
nohup ${python_path} supersonic_pyllm.py > $pythonRunDir/pyllm.log 2>&1 &
|
||||
# add health check
|
||||
for i in {1..10}
|
||||
do
|
||||
echo "pyllm health check attempt $i..."
|
||||
response=$(curl -s http://${PYLLM_HOST}:${PYLLM_PORT}/health)
|
||||
echo "pyllm health check response: $response"
|
||||
status_ok="Healthy"
|
||||
if [[ $response == *$status_ok* ]] ; then
|
||||
echo "pyllm Health check passed."
|
||||
break
|
||||
else
|
||||
if [ "$i" -eq 10 ]; then
|
||||
echo "pyllm Health check failed after 10 attempts."
|
||||
echo "May still downloading model files. Please check pyllm.log in runtime directory."
|
||||
fi
|
||||
echo "Retrying after 5 seconds..."
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function start()
|
||||
{
|
||||
function start() {
|
||||
local_app_name=$1
|
||||
pid=$(ps aux |grep ${local_app_name} | grep -v grep | awk '{print $2}')
|
||||
echo "Starting ${local_app_name}"
|
||||
pid=$(ps aux | grep ${local_app_name} | grep -v grep | awk '{print $2}')
|
||||
if [[ "$pid" == "" ]]; then
|
||||
if [[ ${local_app_name} == $PYLLM_APP_NAME ]]; then
|
||||
runPythonService ${local_app_name}
|
||||
else
|
||||
runJavaService ${local_app_name}
|
||||
fi
|
||||
runJavaService ${local_app_name}
|
||||
else
|
||||
echo "Process (PID = $pid) is running."
|
||||
return 1
|
||||
fi
|
||||
echo "Start success"
|
||||
}
|
||||
|
||||
function stop()
|
||||
{
|
||||
function stop() {
|
||||
echo "Stopping $1"
|
||||
pid=$(ps aux | grep $1 | grep -v grep | awk '{print $2}')
|
||||
if [[ "$pid" == "" ]]; then
|
||||
echo "Process $1 is not running !"
|
||||
echo "Process $1 is not running!"
|
||||
return 1
|
||||
else
|
||||
kill -9 $pid
|
||||
echo "Process (PID = $pid) is killed !"
|
||||
echo "Process (PID = $pid) is killed!"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
if [[ $1 == $PYLLM_APP_NAME ]]; then
|
||||
reloadExamples
|
||||
fi
|
||||
echo "Stop success"
|
||||
}
|
||||
|
||||
setMainClass
|
||||
setAppName
|
||||
case "$command" in
|
||||
start)
|
||||
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||
echo "Starting $PYLLM_APP_NAME"
|
||||
start $PYLLM_APP_NAME
|
||||
fi
|
||||
echo "Starting ${app_name}"
|
||||
start ${app_name}
|
||||
echo "Start success"
|
||||
;;
|
||||
start ${app_name}
|
||||
;;
|
||||
stop)
|
||||
echo "Stopping $app_name"
|
||||
stop $app_name
|
||||
echo "Stopping $PYLLM_APP_NAME"
|
||||
stop $PYLLM_APP_NAME
|
||||
echo "Stop success"
|
||||
;;
|
||||
reload)
|
||||
echo "Reloading ${app_name}"
|
||||
reload ${app_name}
|
||||
echo "Reload success"
|
||||
;;
|
||||
stop $app_name
|
||||
;;
|
||||
restart)
|
||||
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||
echo "Stopping $PYLLM_APP_NAME"
|
||||
stop $PYLLM_APP_NAME
|
||||
echo "Starting $PYLLM_APP_NAME"
|
||||
start $PYLLM_APP_NAME
|
||||
fi
|
||||
echo "Stopping ${app_name}"
|
||||
stop ${app_name}
|
||||
echo "Starting ${app_name}"
|
||||
start ${app_name}
|
||||
echo "Restart success"
|
||||
;;
|
||||
stop ${app_name}
|
||||
start ${app_name}
|
||||
;;
|
||||
*)
|
||||
echo "Use command {start|stop|restart} to run."
|
||||
exit 1
|
||||
esac
|
||||
echo "Use command {start|stop|restart} to run."
|
||||
exit 1
|
||||
esac
|
||||
@@ -20,14 +20,12 @@
|
||||
<include>*.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/../../headless/python</directory>
|
||||
<outputDirectory>pyllm</outputDirectory>
|
||||
<fileMode>0777</fileMode>
|
||||
<directoryMode>0755</directoryMode>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/../../assembly/bin</directory>
|
||||
<excludes>
|
||||
<exclude>supersonic-build.sh</exclude>
|
||||
<exclude>supersonic-build.bat</exclude>
|
||||
</excludes>
|
||||
<outputDirectory>bin</outputDirectory>
|
||||
<fileMode>0777</fileMode>
|
||||
<directoryMode>0755</directoryMode>
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.tencent.supersonic.auth.api.authentication.request.UserReq;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* UserAdaptor defines some interfaces for obtaining user and organization information
|
||||
@@ -20,7 +21,9 @@ public interface UserAdaptor {
|
||||
|
||||
void register(UserReq userReq);
|
||||
|
||||
String login(UserReq userReq);
|
||||
String login(UserReq userReq, HttpServletRequest request);
|
||||
|
||||
String login(UserReq userReq, String appKey);
|
||||
|
||||
List<User> getUserByOrg(String key);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.tencent.supersonic.auth.authentication.interceptor;
|
||||
package com.tencent.supersonic.auth.api.authentication.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -5,32 +5,51 @@ import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
public class AuthenticationConfig {
|
||||
|
||||
@Value("${authentication.exclude.path:XXX}")
|
||||
@Value("${s2.authentication.exclude.path:XXX}")
|
||||
private String excludePath;
|
||||
|
||||
@Value("${authentication.include.path:/api}")
|
||||
@Value("${s2.authentication.include.path:/api}")
|
||||
private String includePath;
|
||||
|
||||
@Value("${authentication.enable:false}")
|
||||
@Value("${s2.authentication.enable:false}")
|
||||
private boolean enabled;
|
||||
|
||||
@Value("${authentication.token.secret:secret}")
|
||||
private String tokenSecret;
|
||||
@Value("${s2.authentication.token.default.appKey:supersonic}")
|
||||
private String tokenDefaultAppKey;
|
||||
|
||||
@Value("${authentication.token.http.header.key:Authorization}")
|
||||
@Value("${s2.authentication.token.appSecret:supersonic:WIaO9YRRVt+7QtpPvyWsARFngnEcbaKBk"
|
||||
+ "783uGFwMrbJBaochsqCH62L4Kijcb0sZCYoSsiKGV/zPml5MnZ3uQ==}")
|
||||
private String tokenAppSecret;
|
||||
|
||||
@Value("${s2.authentication.token.http.header.key:Authorization}")
|
||||
private String tokenHttpHeaderKey;
|
||||
|
||||
@Value("${authentication.app.appId:appId}")
|
||||
@Value("${s2.authentication.token.http.app.key:App-Key}")
|
||||
private String tokenHttpHeaderAppKey;
|
||||
|
||||
@Value("${s2.authentication.app.appId:appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${authentication.app.timestamp:timestamp}")
|
||||
@Value("${s2.authentication.app.timestamp:timestamp}")
|
||||
private String timestamp;
|
||||
|
||||
@Value("${authentication.app.signature:signature}")
|
||||
@Value("${s2.authentication.app.signature:signature}")
|
||||
private String signature;
|
||||
|
||||
@Value("${s2.authentication.token.timeout:72000000}")
|
||||
private Long tokenTimeout;
|
||||
|
||||
public Map<String, String> getAppKeyToSecretMap() {
|
||||
return Arrays.stream(this.tokenAppSecret.split(","))
|
||||
.map(s -> s.split(":"))
|
||||
.collect(Collectors.toMap(e -> e[0].trim(), e -> e[1].trim()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,9 @@ public class UserConstants {
|
||||
public static final String TOKEN_USER_EMAIL = "token_user_email";
|
||||
|
||||
public static final String TOKEN_IS_ADMIN = "token_is_admin";
|
||||
|
||||
public static final String TOKEN_ALGORITHM = "HS512";
|
||||
|
||||
public static final String TOKEN_CREATE_TIME = "token_create_time";
|
||||
|
||||
public static final String TOKEN_PREFIX = "Bearer";
|
||||
|
||||
public static final Long TOKEN_TIME_OUT = 25920000000L;
|
||||
|
||||
public static final String INTERNAL = "internal";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ public interface UserService {
|
||||
|
||||
void register(UserReq userCmd);
|
||||
|
||||
String login(UserReq userCmd);
|
||||
String login(UserReq userCmd, HttpServletRequest request);
|
||||
|
||||
String login(UserReq userCmd, String appKey);
|
||||
|
||||
Set<String> getUserAllOrgId(String userName);
|
||||
|
||||
|
||||
@@ -11,4 +11,6 @@ public interface UserStrategy {
|
||||
|
||||
User findUser(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
User findUser(String token, String appKey);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package com.tencent.supersonic.auth.api.authentication.utils;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.service.UserStrategy;
|
||||
import com.tencent.supersonic.common.pojo.SystemConfig;
|
||||
import com.tencent.supersonic.common.config.SystemConfig;
|
||||
import com.tencent.supersonic.common.service.SystemConfigService;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
public final class UserHolder {
|
||||
|
||||
@@ -20,6 +19,15 @@ public final class UserHolder {
|
||||
|
||||
public static User findUser(HttpServletRequest request, HttpServletResponse response) {
|
||||
User user = REPO.findUser(request, response);
|
||||
return getUser(user);
|
||||
}
|
||||
|
||||
public static User findUser(String token, String appKey) {
|
||||
User user = REPO.findUser(token, appKey);
|
||||
return getUser(user);
|
||||
}
|
||||
|
||||
private static User getUser(User user) {
|
||||
SystemConfigService sysParameterService = ContextUtils.getBean(SystemConfigService.class);
|
||||
SystemConfig systemConfig = sysParameterService.getSystemConfig();
|
||||
if (!CollectionUtils.isEmpty(systemConfig.getAdmins())
|
||||
|
||||
@@ -38,10 +38,6 @@
|
||||
<artifactId>druid</artifactId>
|
||||
<version>${alibaba.druid.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -50,7 +46,6 @@
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>${pagehelper.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -9,9 +9,13 @@ import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
|
||||
import com.tencent.supersonic.auth.api.authentication.request.UserReq;
|
||||
import com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO;
|
||||
import com.tencent.supersonic.auth.authentication.persistence.repository.UserRepository;
|
||||
import com.tencent.supersonic.common.util.AESEncryptionUtil;
|
||||
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -19,6 +23,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* DefaultUserAdaptor provides a default method to obtain user and organization information
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultUserAdaptor implements UserAdaptor {
|
||||
|
||||
private List<UserDO> getUserDOList() {
|
||||
@@ -72,22 +77,53 @@ public class DefaultUserAdaptor implements UserAdaptor {
|
||||
}
|
||||
UserDO userDO = new UserDO();
|
||||
BeanUtils.copyProperties(userReq, userDO);
|
||||
try {
|
||||
byte[] salt = AESEncryptionUtil.generateSalt(userDO.getName());
|
||||
userDO.setSalt(AESEncryptionUtil.getStringFromBytes(salt));
|
||||
userDO.setPassword(AESEncryptionUtil.encrypt(userReq.getPassword(), salt));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("password encrypt error, please try again");
|
||||
}
|
||||
userRepository.addUser(userDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(UserReq userReq) {
|
||||
public String login(UserReq userReq, HttpServletRequest request) {
|
||||
UserTokenUtils userTokenUtils = ContextUtils.getBean(UserTokenUtils.class);
|
||||
String appKey = userTokenUtils.getAppKey(request);
|
||||
return login(userReq, appKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(UserReq userReq, String appKey) {
|
||||
UserTokenUtils userTokenUtils = ContextUtils.getBean(UserTokenUtils.class);
|
||||
try {
|
||||
UserWithPassword user = getUserWithPassword(userReq);
|
||||
return userTokenUtils.generateToken(user, appKey);
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
throw new RuntimeException("password encrypt error, please try again");
|
||||
}
|
||||
}
|
||||
|
||||
private UserWithPassword getUserWithPassword(UserReq userReq) {
|
||||
UserDO userDO = getUser(userReq.getName());
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("user not exist,please register");
|
||||
}
|
||||
if (userDO.getPassword().equals(userReq.getPassword())) {
|
||||
UserWithPassword user = UserWithPassword.get(userDO.getId(), userDO.getName(), userDO.getDisplayName(),
|
||||
userDO.getEmail(), userDO.getPassword(), userDO.getIsAdmin());
|
||||
return userTokenUtils.generateToken(user);
|
||||
try {
|
||||
String password = AESEncryptionUtil.encrypt(userReq.getPassword(),
|
||||
AESEncryptionUtil.getBytesFromString(userDO.getSalt()));
|
||||
if (userDO.getPassword().equals(password)) {
|
||||
UserWithPassword user = UserWithPassword.get(userDO.getId(), userDO.getName(), userDO.getDisplayName(),
|
||||
userDO.getEmail(), userDO.getPassword(), userDO.getIsAdmin());
|
||||
return user;
|
||||
} else {
|
||||
throw new RuntimeException("password not correct, please try again");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("password encrypt error, please try again");
|
||||
}
|
||||
throw new RuntimeException("password not correct, please try again");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,19 +5,20 @@ import com.tencent.supersonic.auth.api.authentication.constant.UserConstants;
|
||||
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
|
||||
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
|
||||
import com.tencent.supersonic.common.util.S2ThreadContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.catalina.connector.RequestFacade;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.apache.tomcat.util.http.MimeHeaders;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
|
||||
@@ -32,7 +33,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
protected boolean isExcludedUri(String uri) {
|
||||
String excludePathStr = authenticationConfig.getExcludePath();
|
||||
if (Strings.isEmpty(excludePathStr)) {
|
||||
if (StringUtils.isEmpty(excludePathStr)) {
|
||||
return false;
|
||||
}
|
||||
List<String> excludePaths = Arrays.asList(excludePathStr.split(","));
|
||||
@@ -44,7 +45,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
protected boolean isIncludedUri(String uri) {
|
||||
String includePathStr = authenticationConfig.getIncludePath();
|
||||
if (Strings.isEmpty(includePathStr)) {
|
||||
if (StringUtils.isEmpty(includePathStr)) {
|
||||
return false;
|
||||
}
|
||||
List<String> includePaths = Arrays.asList(includePathStr.split(","));
|
||||
@@ -64,7 +65,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
return StringUtils.isNotBlank(appId);
|
||||
}
|
||||
|
||||
protected void reflectSetparam(HttpServletRequest request, String key, String value) {
|
||||
protected void reflectSetParam(HttpServletRequest request, String key, String value) {
|
||||
try {
|
||||
if (request instanceof StandardMultipartHttpServletRequest) {
|
||||
RequestFacade servletRequest =
|
||||
@@ -98,7 +99,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
o2.addValue(key).setString(value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("reflectSetParam error:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tencent.supersonic.auth.authentication.interceptor;
|
||||
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||
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;
|
||||
@@ -66,8 +67,8 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
|
||||
}
|
||||
|
||||
private void setFakerUser(HttpServletRequest request) {
|
||||
String token = userTokenUtils.generateAdminToken();
|
||||
reflectSetparam(request, authenticationConfig.getTokenHttpHeaderKey(), token);
|
||||
String token = userTokenUtils.generateAdminToken(request);
|
||||
reflectSetParam(request, authenticationConfig.getTokenHttpHeaderKey(), token);
|
||||
setContext(User.getFakeUser().getName(), request);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ public class UserDO {
|
||||
*/
|
||||
private String password;
|
||||
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -79,6 +81,14 @@ public class UserDO {
|
||||
this.password = password == null ? null : password.trim();
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
this.salt = salt == null ? null : salt.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return display_name
|
||||
|
||||
@@ -65,8 +65,8 @@ public class UserController {
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public String login(@RequestBody UserReq userCmd) {
|
||||
return userService.login(userCmd);
|
||||
public String login(@RequestBody UserReq userCmd, HttpServletRequest request) {
|
||||
return userService.login(userCmd, request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ 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 com.tencent.supersonic.auth.authentication.utils.ComponentFactory;
|
||||
import com.tencent.supersonic.common.pojo.SystemConfig;
|
||||
import com.tencent.supersonic.common.config.SystemConfig;
|
||||
import com.tencent.supersonic.common.service.SystemConfigService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -68,8 +68,13 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(UserReq userReq) {
|
||||
return ComponentFactory.getUserAdaptor().login(userReq);
|
||||
public String login(UserReq userReq, HttpServletRequest request) {
|
||||
return ComponentFactory.getUserAdaptor().login(userReq, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(UserReq userReq, String appKey) {
|
||||
return ComponentFactory.getUserAdaptor().login(userReq, appKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ public class FakeUserStrategy implements UserStrategy {
|
||||
return User.getFakeUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUser(String token, String appKey) {
|
||||
return User.getFakeUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,4 +28,9 @@ public class HttpHeaderUserStrategy implements UserStrategy {
|
||||
public User findUser(HttpServletRequest request, HttpServletResponse response) {
|
||||
return userTokenUtils.getUser(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUser(String token, String appKey) {
|
||||
return userTokenUtils.getUser(token, appKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
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;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_IS_ADMIN;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_PREFIX;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_TIME_OUT;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_DISPLAY_NAME;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_EMAIL;
|
||||
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;
|
||||
@@ -17,14 +7,25 @@ import com.tencent.supersonic.common.pojo.exception.AccessException;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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;
|
||||
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_CREATE_TIME;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_IS_ADMIN;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_PREFIX;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_DISPLAY_NAME;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_EMAIL;
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -36,7 +37,12 @@ public class UserTokenUtils {
|
||||
this.authenticationConfig = authenticationConfig;
|
||||
}
|
||||
|
||||
public String generateToken(UserWithPassword user) {
|
||||
public String generateToken(UserWithPassword user, HttpServletRequest request) {
|
||||
String appKey = getAppKey(request);
|
||||
return generateToken(user, appKey);
|
||||
}
|
||||
|
||||
public String generateToken(UserWithPassword user, String appKey) {
|
||||
Map<String, Object> claims = new HashMap<>(5);
|
||||
claims.put(TOKEN_USER_ID, user.getId());
|
||||
claims.put(TOKEN_USER_NAME, StringUtils.isEmpty(user.getName()) ? "" : user.getName());
|
||||
@@ -44,23 +50,31 @@ public class UserTokenUtils {
|
||||
claims.put(TOKEN_USER_DISPLAY_NAME, user.getDisplayName());
|
||||
claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis());
|
||||
claims.put(TOKEN_IS_ADMIN, user.getIsAdmin());
|
||||
return generate(claims);
|
||||
return generate(claims, appKey);
|
||||
}
|
||||
|
||||
public String generateAdminToken() {
|
||||
Map<String, Object> claims = new HashMap<>(5);
|
||||
claims.put(TOKEN_USER_ID, "1");
|
||||
claims.put(TOKEN_USER_NAME, "admin");
|
||||
claims.put(TOKEN_USER_PASSWORD, "admin");
|
||||
claims.put(TOKEN_USER_DISPLAY_NAME, "admin");
|
||||
claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis());
|
||||
claims.put(TOKEN_IS_ADMIN, 1);
|
||||
return generate(claims);
|
||||
public String generateAdminToken(HttpServletRequest request) {
|
||||
UserWithPassword admin = new UserWithPassword("admin");
|
||||
admin.setId(1L);
|
||||
admin.setName("admin");
|
||||
admin.setPassword("c3VwZXJzb25pY0BiaWNvbdktJJYWw6A3rEmBUPzbn/6DNeYnD+y3mAwDKEMS3KVT");
|
||||
admin.setDisplayName("admin");
|
||||
admin.setIsAdmin(1);
|
||||
return generateToken(admin, request);
|
||||
}
|
||||
|
||||
public User getUser(HttpServletRequest request) {
|
||||
String token = request.getHeader(authenticationConfig.getTokenHttpHeaderKey());
|
||||
final Claims claims = getClaims(token);
|
||||
final Claims claims = getClaims(token, request);
|
||||
return getUser(claims);
|
||||
}
|
||||
|
||||
public User getUser(String token, String appKey) {
|
||||
final Claims claims = getClaims(token, appKey);
|
||||
return getUser(claims);
|
||||
}
|
||||
|
||||
private User getUser(Claims claims) {
|
||||
Long userId = Long.parseLong(claims.getOrDefault(TOKEN_USER_ID, 0).toString());
|
||||
String userName = String.valueOf(claims.get(TOKEN_USER_NAME));
|
||||
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
|
||||
@@ -77,7 +91,7 @@ public class UserTokenUtils {
|
||||
log.warn("{}, uri: {}", message, request.getServletPath());
|
||||
throw new AccessException(message);
|
||||
}
|
||||
final Claims claims = getClaims(token);
|
||||
final Claims claims = getClaims(token, request);
|
||||
Long userId = Long.parseLong(claims.getOrDefault(TOKEN_USER_ID, 0).toString());
|
||||
String userName = String.valueOf(claims.get(TOKEN_USER_NAME));
|
||||
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
|
||||
@@ -88,35 +102,69 @@ public class UserTokenUtils {
|
||||
return UserWithPassword.get(userId, userName, displayName, email, password, isAdmin);
|
||||
}
|
||||
|
||||
private Claims getClaims(String token) {
|
||||
private Claims getClaims(String token, HttpServletRequest request) {
|
||||
Claims claims;
|
||||
try {
|
||||
claims = Jwts.parser()
|
||||
.setSigningKey(authenticationConfig.getTokenSecret().getBytes(StandardCharsets.UTF_8))
|
||||
.parseClaimsJws(token.startsWith(TOKEN_PREFIX)
|
||||
? token.substring(token.indexOf(TOKEN_PREFIX) + TOKEN_PREFIX.length()).trim() :
|
||||
token.trim()).getBody();
|
||||
String appKey = getAppKey(request);
|
||||
claims = getClaims(token, appKey);
|
||||
} catch (Exception e) {
|
||||
throw new AccessException("parse user info from token failed :" + token);
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
private String generate(Map<String, Object> claims) {
|
||||
return toTokenString(claims);
|
||||
private Claims getClaims(String token, String appKey) {
|
||||
Claims claims;
|
||||
try {
|
||||
String tokenSecret = getTokenSecret(appKey);
|
||||
claims = Jwts.parser()
|
||||
.setSigningKey(tokenSecret.getBytes(StandardCharsets.UTF_8))
|
||||
.build().parseClaimsJws(getTokenString(token)).getBody();
|
||||
} catch (Exception e) {
|
||||
log.error("getClaims", e);
|
||||
throw new AccessException("parse user info from token failed :" + token);
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
private String toTokenString(Map<String, Object> claims) {
|
||||
long expiration = Long.parseLong(claims.get(TOKEN_CREATE_TIME) + "") + TOKEN_TIME_OUT;
|
||||
private static String getTokenString(String token) {
|
||||
return token.startsWith(TOKEN_PREFIX) ? token.substring(token.indexOf(TOKEN_PREFIX)
|
||||
+ TOKEN_PREFIX.length()).trim() : token.trim();
|
||||
}
|
||||
|
||||
private String generate(Map<String, Object> claims, String appKey) {
|
||||
return toTokenString(claims, appKey);
|
||||
}
|
||||
|
||||
private String toTokenString(Map<String, Object> claims, String appKey) {
|
||||
Long tokenTimeout = authenticationConfig.getTokenTimeout();
|
||||
long expiration = Long.parseLong(claims.get(TOKEN_CREATE_TIME) + "") + tokenTimeout;
|
||||
Date expirationDate = new Date(expiration);
|
||||
String tokenSecret = getTokenSecret(appKey);
|
||||
|
||||
SignatureAlgorithm.valueOf(TOKEN_ALGORITHM);
|
||||
return Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.setSubject(claims.get(TOKEN_USER_NAME).toString())
|
||||
.setExpiration(new Date(expiration))
|
||||
.signWith(SignatureAlgorithm.valueOf(TOKEN_ALGORITHM),
|
||||
authenticationConfig.getTokenSecret().getBytes(StandardCharsets.UTF_8))
|
||||
.setExpiration(expirationDate)
|
||||
.signWith(new SecretKeySpec(tokenSecret.getBytes(StandardCharsets.UTF_8),
|
||||
SignatureAlgorithm.HS512.getJcaName()), SignatureAlgorithm.HS512)
|
||||
.compact();
|
||||
}
|
||||
|
||||
private String getTokenSecret(String appKey) {
|
||||
Map<String, String> appKeyToSecretMap = authenticationConfig.getAppKeyToSecretMap();
|
||||
String secret = appKeyToSecretMap.get(appKey);
|
||||
if (StringUtils.isBlank(secret)) {
|
||||
throw new AccessException("get secret from appKey failed :" + appKey);
|
||||
}
|
||||
return secret;
|
||||
}
|
||||
|
||||
public String getAppKey(HttpServletRequest request) {
|
||||
String appKey = request.getHeader(authenticationConfig.getTokenHttpHeaderAppKey());
|
||||
if (StringUtils.isBlank(appKey)) {
|
||||
appKey = authenticationConfig.getTokenDefaultAppKey();
|
||||
}
|
||||
return appKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<result column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="password" jdbcType="VARCHAR" property="password" />
|
||||
<result column="salt" jdbcType="VARCHAR" property="salt" />
|
||||
<result column="display_name" jdbcType="VARCHAR" property="displayName" />
|
||||
<result column="email" jdbcType="VARCHAR" property="email" />
|
||||
<result column="is_admin" jdbcType="INTEGER" property="isAdmin" />
|
||||
@@ -39,7 +40,7 @@
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, name, password, display_name, email, is_admin
|
||||
id, name, password, salt, display_name, email, is_admin
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample" resultMap="BaseResultMap">
|
||||
select
|
||||
@@ -59,10 +60,10 @@
|
||||
</if>
|
||||
</select>
|
||||
<insert id="insert" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
|
||||
insert into s2_user (id, name, password,
|
||||
insert into s2_user (id, name, password, salt,
|
||||
display_name, email, is_admin
|
||||
)
|
||||
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
|
||||
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR},
|
||||
#{displayName,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{isAdmin,jdbcType=INTEGER}
|
||||
)
|
||||
</insert>
|
||||
@@ -78,6 +79,9 @@
|
||||
<if test="password != null">
|
||||
password,
|
||||
</if>
|
||||
<if test="password != null">
|
||||
salt,
|
||||
</if>
|
||||
<if test="displayName != null">
|
||||
display_name,
|
||||
</if>
|
||||
@@ -98,6 +102,9 @@
|
||||
<if test="password != null">
|
||||
#{password,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="salt != null">
|
||||
#{salt,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="displayName != null">
|
||||
#{displayName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
package com.tencent.supersonic.auth.authorization.service;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
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.AuthGroup;
|
||||
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.AuthRule;
|
||||
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 com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
|
||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRule;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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
|
||||
@@ -117,7 +118,8 @@ public class AuthServiceImpl implements AuthService {
|
||||
if (!CollectionUtils.isEmpty(authGroups)) {
|
||||
for (AuthGroup group : authGroups) {
|
||||
if (group.getDimensionFilters() != null
|
||||
&& group.getDimensionFilters().stream().anyMatch(expr -> !Strings.isNullOrEmpty(expr))) {
|
||||
&& group.getDimensionFilters().stream().anyMatch(expr ->
|
||||
!StringUtils.isEmpty(expr))) {
|
||||
DimensionFilter df = new DimensionFilter();
|
||||
df.setDescription(group.getDimensionFilterDescription());
|
||||
df.setExpressions(group.getDimensionFilters());
|
||||
|
||||
84
benchmark/benchmark.md
Normal file
84
benchmark/benchmark.md
Normal file
@@ -0,0 +1,84 @@
|
||||
## 使用场景
|
||||
产品上线阶段批量测试问答对话的问题,统计测试结果。
|
||||
注意:与evaluation模块的区别,evaluation是构建数据集多个模型的横向评估,benchmark是选定模型下,批量自动化业务问题的测试。
|
||||
## 功能说明
|
||||
批量自动化测试问答对话测试,支持单轮问答测试。
|
||||
|
||||
## 使用说明
|
||||
- 注意1:建议在开发测试环境的执行,如果需要在生产环境的测试,请避开用户使用高峰期。
|
||||
- 注意2: python版本要求3.8可以运行。3.8.5版本测试通过。以上python版本未测试。
|
||||
1. 准备测试问题
|
||||
|
||||
将问题写入`test_data.csv`文件,格式如下:
|
||||
```csv
|
||||
question
|
||||
各BG期间在职、入职、离职人员的平均薪资是多少?(注意:薪资不包括香港视源、广视以及并购控股子公司青松、仙视的数据。)
|
||||
各BG期间入职且仍在职的人数有多少?
|
||||
各BG当月的净增长人数及其增长率是多少?
|
||||
```
|
||||
将文件放入`benchmark/data`目录下。
|
||||
|
||||
2. 执行测试
|
||||
```bash
|
||||
python benchmark -u http://localhost:3100 -a 6 -c 141 -f data/renli.csv -p zds
|
||||
```
|
||||
参数说明:
|
||||
- -a: 问答对话的id
|
||||
- -c: chat_id
|
||||
- -f: 测试问题文件
|
||||
- -u: 用户id
|
||||
如果执行报错,没有安装相关python包,可以执行`pip install -r requirements.txt`安装相关包。
|
||||
|
||||
3. 查看测试结果
|
||||
当前,只能在数据库中查看测试结果。
|
||||
```sql
|
||||
select question_id,chat_id,create_time,query_text,
|
||||
JSON_EXTRACT(parse_info,'$.sqlInfo.s2SQL') as s2sql,
|
||||
JSON_EXTRACT(parse_info,'$.sqlInfo.correctS2SQL') as correctS2SQL,
|
||||
JSON_EXTRACT(parse_info,'$.sqlInfo.querySQL') as querySQL,
|
||||
'请标记正确的SQL' as correctSQL,
|
||||
'请标记生成SQL是否正确' as isOk,
|
||||
'请分类不正确的原因' as reason
|
||||
from s2_chat_parse scp where user_name = 'zhaodongsheng' and chat_id = '141';
|
||||
|
||||
select question_id,chat_id,create_time,query_text,
|
||||
JSON_EXTRACT(query_result,'$.querySql') as querySql,
|
||||
JSON_EXTRACT(query_result,'$.queryResults') as queryResults
|
||||
from s2_chat_query where user_name = 'zhaodongsheng' and chat_id = '141' and query_state = 1;
|
||||
|
||||
```
|
||||
4. 查看帮助
|
||||
```bash
|
||||
python benchmark.py --help
|
||||
usage: benchmark.py [-h] -u URL -a AGENTID -c CHATID -f FILEPATH -p USERNAME
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-u URL, --url URL url:问答系统url,例如:https://chatdata-dev.test.com
|
||||
-a AGENTID, --agentId AGENTID
|
||||
agentId:助手ID
|
||||
-c CHATID, --chatId CHATID
|
||||
chatId:会话ID,需要通过浏览器开发者模式获取
|
||||
-f FILEPATH, --filePath FILEPATH
|
||||
filePath:问题文件路径, csv格式. 请提前上传到benchmark/data目录下
|
||||
-p USERNAME, --userName USERNAME
|
||||
userName:用户名,用户获取登录token
|
||||
```
|
||||
|
||||
## 演示效果
|
||||
```bash
|
||||
python benchmark.py -u https://chatdata-dev.test.com -a 3 -c 35 -f data/shuce.csv -p zds
|
||||
批量测试配置信息[url: https://chatdata-dev.test.com agentId: 3 chatId: 35 filePath: data/shuce.csv userName: zds ]
|
||||
请确认输入的压力测试信息是否正确:
|
||||
1. Yes
|
||||
2. No
|
||||
1
|
||||
start to ask question: 各BG期间在职、入职、离职人员的平均薪资是多少?(注意:薪资不包括香港视源、广视以及并购控股子公司青松、仙视的数据。)
|
||||
start to ask question: 各BG期间入职且仍在职的人数有多少?
|
||||
start to ask question: 各BG当月的净增长人数及其增长率是多少?
|
||||
```
|
||||
|
||||
## TODO
|
||||
- [x] 问答对话测试
|
||||
- [ ] 多轮对话测试
|
||||
- [ ] 问答对话测试结果展示
|
||||
104
benchmark/benchmark.py
Normal file
104
benchmark/benchmark.py
Normal file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -----------------------------------------------------------------------------------
|
||||
'''
|
||||
@filename : batchmark.py
|
||||
@time : 2024/06/20
|
||||
@author : zhaodongsheng
|
||||
@Version : 1.0
|
||||
@description : 批量问答测试
|
||||
'''
|
||||
# -----------------------------------------------------------------------------------
|
||||
import pandas as pd
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
import jwt
|
||||
import traceback
|
||||
|
||||
class BatchTest:
|
||||
def __init__(self, url, agentId, chatId, userName):
|
||||
self.base_url = url + '/api/chat/query/'
|
||||
self.agentId = agentId
|
||||
self.auth_token = self.__get_authorization(userName)
|
||||
self.chatId = chatId
|
||||
|
||||
def parse(self, query_text):
|
||||
url = self.base_url + 'parse'
|
||||
data = {
|
||||
'queryText': query_text,
|
||||
'agentId': self.agentId,
|
||||
'chatId': self.chatId,
|
||||
}
|
||||
headers = {
|
||||
'Authorization': 'Bearer ' + self.auth_token,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
return response.json()
|
||||
|
||||
def execute(self, query_text, queryId):
|
||||
url = self.base_url + 'execute'
|
||||
data = {
|
||||
'queryText': query_text,
|
||||
'parseId': 1,
|
||||
'chatId': self.chatId,
|
||||
'queryId': queryId,
|
||||
}
|
||||
headers = {
|
||||
'Authorization': 'Bearer ' + self.auth_token,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
return response.json()
|
||||
|
||||
def read_question_from_csv(self, filePath):
|
||||
df = pd.read_csv(filePath)
|
||||
return df
|
||||
|
||||
def __get_authorization(self, userName):
|
||||
# secret 请和 com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig.tokenAppSecret 保持一致
|
||||
secret = "WIaO9YRRVt+7QtpPvyWsARFngnEcbaKBk783uGFwMrbJBaochsqCH62L4Kijcb0sZCYoSsiKGV/zPml5MnZ3uQ=="
|
||||
exp = time.time() + 100000000
|
||||
token= jwt.encode({"token_user_name": userName,"exp": exp}, secret, algorithm="HS512")
|
||||
return token
|
||||
|
||||
|
||||
def benchmark(url:str, agentId:str, chatId:str, filePath:str, userName:str):
|
||||
batch_test = BatchTest(url, agentId, chatId, userName)
|
||||
df = batch_test.read_question_from_csv(filePath)
|
||||
for index, row in df.iterrows():
|
||||
question = row['question']
|
||||
print('start to ask question:', question)
|
||||
# 捕获异常,防止程序中断
|
||||
try:
|
||||
parse_resp = batch_test.parse(question)
|
||||
batch_test.execute(question, parse_resp['data']['queryId'])
|
||||
except Exception as e:
|
||||
print('error:', e)
|
||||
traceback.print_exc()
|
||||
continue
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-u', '--url', type=str, required=True, help='url:问答系统url,例如:https://chatdata-dev.test.com')
|
||||
parser.add_argument('-a', '--agentId', type=str, required=True, help='agentId:助手ID')
|
||||
parser.add_argument('-c', '--chatId', type=str, required=True, help='chatId:会话ID,需要通过浏览器开发者模式获取')
|
||||
parser.add_argument('-f', '--filePath', type=str, required=True, help='filePath:问题文件路径, csv格式. 请提前上传到benchmark/data目录下')
|
||||
parser.add_argument('-p', '--userName', type=str, required=True, help='userName:用户名,用户获取登录token')
|
||||
args = parser.parse_args()
|
||||
|
||||
print('批量测试配置信息[url:', args.url,'agentId:', args.agentId, 'chatId:', args.chatId, 'filePath:', args.filePath, 'userName:', args.userName, ']')
|
||||
print('请确认输入的压力测试信息是否正确:')
|
||||
print('1. Yes')
|
||||
print('2. No')
|
||||
confirm = input()
|
||||
if confirm == '1' or confirm == 'Yes' or confirm == 'yes' or confirm == 'YES':
|
||||
benchmark(args.url, args.agentId, args.chatId, args.filePath, args.userName)
|
||||
else:
|
||||
print('请重新输入压力测试配置信息: url, agentId, chatId, filePath, userName')
|
||||
3
benchmark/data/caiwu.csv
Normal file
3
benchmark/data/caiwu.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
question
|
||||
每个业务组(BG)的员工人数是多少?
|
||||
每个业务组的损益情况如何?
|
||||
|
8
benchmark/data/renli.csv
Normal file
8
benchmark/data/renli.csv
Normal file
@@ -0,0 +1,8 @@
|
||||
question
|
||||
在职人员的男女比例是多少?
|
||||
期间入职且离职的人数及其占比如何?
|
||||
期间新入职社招人员的平均年龄是多少?
|
||||
期间入职且在职的人数有多少?
|
||||
期间在职人员的平均年龄是多少?
|
||||
当月的净增长人数及其增长率是多少?
|
||||
期间新入职社招人员的年龄分布情况如何?
|
||||
|
4
benchmark/data/shuce.csv
Normal file
4
benchmark/data/shuce.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
question
|
||||
在广东省内,哪一个学校的累计集备数最多,请返回该学校的学校名称
|
||||
在广东省内,哪一个学校的累计集体备课数最多,请返回该学校的学校名称
|
||||
|
||||
|
5
benchmark/requirements.txt
Normal file
5
benchmark/requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
pandas==2.0.3
|
||||
PyJWT==2.8.0
|
||||
requests==2.28.2
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.enums;
|
||||
|
||||
|
||||
public enum MemoryReviewResult {
|
||||
|
||||
POSITIVE,
|
||||
NEGATIVE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.enums;
|
||||
|
||||
|
||||
public enum MemoryStatus {
|
||||
|
||||
PENDING,
|
||||
ENABLED,
|
||||
DISABLED;
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public class ChatExecuteReq {
|
||||
private User user;
|
||||
private Integer agentId;
|
||||
private Long queryId;
|
||||
private Integer chatId;
|
||||
private int parseId;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.request;
|
||||
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMemoryFilter {
|
||||
|
||||
private Integer agentId;
|
||||
|
||||
private String question;
|
||||
|
||||
private List<String> questions;
|
||||
|
||||
private MemoryStatus status;
|
||||
|
||||
private MemoryReviewResult llmReviewRet;
|
||||
|
||||
private MemoryReviewResult humanReviewRet;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.request;
|
||||
|
||||
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
|
||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class ChatMemoryUpdateReq extends RecordInfo {
|
||||
|
||||
@NotNull(message = "id不可为空")
|
||||
private Long id;
|
||||
|
||||
private String dbSchema;
|
||||
|
||||
private String s2sql;
|
||||
|
||||
private MemoryStatus status;
|
||||
|
||||
private MemoryReviewResult humanReviewRet;
|
||||
|
||||
private String humanReviewCmt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.request;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.PageBaseReq;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class PageMemoryReq extends PageBaseReq {
|
||||
|
||||
private ChatMemoryFilter chatMemoryFilter = new ChatMemoryFilter();
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.response;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseTimeCostResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
@@ -19,5 +20,6 @@ public class QueryResp {
|
||||
private QueryResult queryResult;
|
||||
private List<SemanticParseInfo> parseInfos;
|
||||
private List<SimilarQueryRecallResp> similarQueries;
|
||||
private ParseTimeCostResp parseTimeCost = new ParseTimeCostResp();
|
||||
|
||||
}
|
||||
@@ -4,7 +4,8 @@ package com.tencent.supersonic.chat.server.agent;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.tencent.supersonic.headless.api.pojo.LLMConfig;
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import com.tencent.supersonic.common.config.VisualConfig;
|
||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -33,6 +34,7 @@ public class Agent extends RecordInfo {
|
||||
private String agentConfig;
|
||||
private LLMConfig llmConfig;
|
||||
private MultiTurnConfig multiTurnConfig;
|
||||
private VisualConfig visualConfig;
|
||||
|
||||
public List<String> getTools(AgentToolType type) {
|
||||
Map map = JSONObject.parseObject(agentConfig, Map.class);
|
||||
@@ -69,6 +71,10 @@ public class Agent extends RecordInfo {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean containsPluginTool() {
|
||||
return !CollectionUtils.isEmpty(getParserTools(AgentToolType.PLUGIN));
|
||||
}
|
||||
|
||||
public boolean containsLLMParserTool() {
|
||||
return !CollectionUtils.isEmpty(getParserTools(AgentToolType.NL2SQL_LLM));
|
||||
}
|
||||
@@ -82,6 +88,19 @@ public class Agent extends RecordInfo {
|
||||
|| !CollectionUtils.isEmpty(getParserTools(AgentToolType.NL2SQL_RULE));
|
||||
}
|
||||
|
||||
public boolean containsAnyTool() {
|
||||
Map map = JSONObject.parseObject(agentConfig, Map.class);
|
||||
if (CollectionUtils.isEmpty(map)) {
|
||||
return false;
|
||||
}
|
||||
List<Map> toolList = (List) map.get("tools");
|
||||
if (CollectionUtils.isEmpty(toolList)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Set<Long> getDataSetIds() {
|
||||
Set<Long> dataSetIds = getDataSetIds(null);
|
||||
if (containsAllModel(dataSetIds)) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.tencent.supersonic.chat.server.executor;
|
||||
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||
import com.tencent.supersonic.chat.server.parser.ParserConfig;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.ChatQueryRepository;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatExecuteContext;
|
||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryState;
|
||||
import dev.langchain4j.data.message.AiMessage;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.input.Prompt;
|
||||
import dev.langchain4j.model.input.PromptTemplate;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import dev.langchain4j.model.provider.ChatLanguageModelProvider;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.tencent.supersonic.chat.server.parser.ParserConfig.PARSER_MULTI_TURN_ENABLE;
|
||||
|
||||
public class PlainTextExecutor implements ChatExecutor {
|
||||
|
||||
private static final String INSTRUCTION = ""
|
||||
+ "#Role: You are a nice person to talk to.\n"
|
||||
+ "#Task: Respond quickly and nicely to the user."
|
||||
+ "#Rules: 1.ALWAYS use the same language as the input.\n"
|
||||
+ "#History Inputs: %s\n"
|
||||
+ "#Current Input: %s\n"
|
||||
+ "#Your response: ";
|
||||
|
||||
@Override
|
||||
public QueryResult execute(ChatExecuteContext chatExecuteContext) {
|
||||
if (!"PLAIN_TEXT".equals(chatExecuteContext.getParseInfo().getQueryMode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String promptStr = String.format(INSTRUCTION, getHistoryInputs(chatExecuteContext),
|
||||
chatExecuteContext.getQueryText());
|
||||
Prompt prompt = PromptTemplate.from(promptStr).apply(Collections.EMPTY_MAP);
|
||||
|
||||
AgentService agentService = ContextUtils.getBean(AgentService.class);
|
||||
Agent chatAgent = agentService.getAgent(chatExecuteContext.getAgentId());
|
||||
|
||||
ChatLanguageModel chatLanguageModel = ChatLanguageModelProvider.provide(chatAgent.getLlmConfig());
|
||||
Response<AiMessage> response = chatLanguageModel.generate(prompt.toUserMessage());
|
||||
|
||||
QueryResult result = new QueryResult();
|
||||
result.setQueryState(QueryState.SUCCESS);
|
||||
result.setQueryMode(chatExecuteContext.getParseInfo().getQueryMode());
|
||||
result.setTextResult(response.content().text());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getHistoryInputs(ChatExecuteContext chatExecuteContext) {
|
||||
StringBuilder historyInput = new StringBuilder();
|
||||
|
||||
AgentService agentService = ContextUtils.getBean(AgentService.class);
|
||||
Agent chatAgent = agentService.getAgent(chatExecuteContext.getAgentId());
|
||||
|
||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
||||
MultiTurnConfig agentMultiTurnConfig = chatAgent.getMultiTurnConfig();
|
||||
Boolean globalMultiTurnConfig = Boolean.valueOf(parserConfig.getParameterValue(PARSER_MULTI_TURN_ENABLE));
|
||||
Boolean multiTurnConfig = agentMultiTurnConfig != null
|
||||
? agentMultiTurnConfig.isEnableMultiTurn() : globalMultiTurnConfig;
|
||||
|
||||
if (Boolean.TRUE.equals(multiTurnConfig)) {
|
||||
List<ParseResp> parseResps = getHistoryParseResult(chatExecuteContext.getChatId(), 5);
|
||||
parseResps.stream().forEach(p -> {
|
||||
historyInput.append(p.getQueryText());
|
||||
historyInput.append(";");
|
||||
});
|
||||
}
|
||||
|
||||
return historyInput.toString();
|
||||
}
|
||||
|
||||
private List<ParseResp> getHistoryParseResult(int chatId, int multiNum) {
|
||||
ChatQueryRepository chatQueryRepository = ContextUtils.getBean(ChatQueryRepository.class);
|
||||
List<ParseResp> contextualParseInfoList = chatQueryRepository.getContextualParseInfo(chatId)
|
||||
.stream().filter(p -> p.getState() != ParseResp.ParseState.FAILED).collect(Collectors.toList());
|
||||
|
||||
List<ParseResp> contextualList = contextualParseInfoList.subList(0,
|
||||
Math.min(multiNum, contextualParseInfoList.size()));
|
||||
Collections.reverse(contextualList);
|
||||
|
||||
return contextualList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +1,49 @@
|
||||
package com.tencent.supersonic.chat.server.executor;
|
||||
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatExecuteContext;
|
||||
import com.tencent.supersonic.chat.server.service.MemoryService;
|
||||
import com.tencent.supersonic.chat.server.util.ResultFormatter;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ExecuteQueryReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.headless.server.service.ChatQueryService;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryState;
|
||||
import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMSqlQuery;
|
||||
import com.tencent.supersonic.headless.server.facade.service.ChatQueryService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.Date;
|
||||
|
||||
public class SqlExecutor implements ChatExecutor {
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public QueryResult execute(ChatExecuteContext chatExecuteContext) {
|
||||
SemanticParseInfo parseInfo = chatExecuteContext.getParseInfo();
|
||||
if (PluginQueryManager.isPluginQuery(parseInfo.getQueryMode())) {
|
||||
return null;
|
||||
}
|
||||
ExecuteQueryReq executeQueryReq = buildExecuteReq(chatExecuteContext);
|
||||
ChatQueryService chatQueryService = ContextUtils.getBean(ChatQueryService.class);
|
||||
QueryResult queryResult = chatQueryService.performExecution(executeQueryReq);
|
||||
String textResult = ResultFormatter.transform2TextNew(queryResult.getQueryColumns(),
|
||||
queryResult.getQueryResults());
|
||||
queryResult.setTextResult(textResult);
|
||||
if (queryResult != null) {
|
||||
String textResult = ResultFormatter.transform2TextNew(queryResult.getQueryColumns(),
|
||||
queryResult.getQueryResults());
|
||||
queryResult.setTextResult(textResult);
|
||||
|
||||
if (queryResult.getQueryState().equals(QueryState.SUCCESS)
|
||||
&& queryResult.getQueryMode().equals(LLMSqlQuery.QUERY_MODE)) {
|
||||
MemoryService memoryService = ContextUtils.getBean(MemoryService.class);
|
||||
memoryService.createMemory(ChatMemoryDO.builder()
|
||||
.agentId(chatExecuteContext.getAgentId())
|
||||
.status(MemoryStatus.PENDING)
|
||||
.question(chatExecuteContext.getQueryText())
|
||||
.s2sql(chatExecuteContext.getParseInfo().getSqlInfo().getS2SQL())
|
||||
.dbSchema(buildSchemaStr(chatExecuteContext.getParseInfo()))
|
||||
.createdBy(chatExecuteContext.getUser().getName())
|
||||
.createdAt(new Date())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
@@ -40,4 +59,36 @@ public class SqlExecutor implements ChatExecutor {
|
||||
.build();
|
||||
}
|
||||
|
||||
public String buildSchemaStr(SemanticParseInfo parseInfo) {
|
||||
String tableStr = parseInfo.getDataSet().getName();
|
||||
StringBuilder metricStr = new StringBuilder();
|
||||
StringBuilder dimensionStr = new StringBuilder();
|
||||
|
||||
parseInfo.getMetrics().stream().forEach(
|
||||
metric -> {
|
||||
metricStr.append(metric.getName());
|
||||
if (StringUtils.isNotEmpty(metric.getDescription())) {
|
||||
metricStr.append(" COMMENT '" + metric.getDescription() + "'");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(metric.getDefaultAgg())) {
|
||||
metricStr.append(" AGGREGATE '" + metric.getDefaultAgg().toUpperCase() + "'");
|
||||
}
|
||||
metricStr.append(",");
|
||||
}
|
||||
);
|
||||
|
||||
parseInfo.getDimensions().stream().forEach(
|
||||
dimension -> {
|
||||
dimensionStr.append(dimension.getName());
|
||||
if (StringUtils.isNotEmpty(dimension.getDescription())) {
|
||||
dimensionStr.append(" COMMENT '" + dimension.getDescription() + "'");
|
||||
}
|
||||
dimensionStr.append(",");
|
||||
}
|
||||
);
|
||||
|
||||
String template = "Table: %s, Metrics: [%s], Dimensions: [%s]";
|
||||
return String.format(template, tableStr, metricStr, dimensionStr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.tencent.supersonic.chat.server.memory;
|
||||
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||
import com.tencent.supersonic.chat.server.service.MemoryService;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.input.Prompt;
|
||||
import dev.langchain4j.model.input.PromptTemplate;
|
||||
import dev.langchain4j.model.provider.ChatLanguageModelProvider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MemoryReviewTask {
|
||||
|
||||
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
||||
|
||||
private static final String INSTRUCTION = ""
|
||||
+ "#Role: You are a senior data engineer experienced in writing SQL.\n"
|
||||
+ "#Task: Your will be provided with a user question and the SQL written by junior engineer,"
|
||||
+ "please take a review and give your opinion.\n"
|
||||
+ "#Rules: "
|
||||
+ "1.ALWAYS follow the output format: `opinion=(POSITIVE|NEGATIVE),comment=(your comment)`."
|
||||
+ "2.DO NOT check the usage of `数据日期` field and `datediff()` function.\n"
|
||||
+ "#Question: %s\n"
|
||||
+ "#Schema: %s\n"
|
||||
+ "#SQL: %s\n"
|
||||
+ "#Response: ";
|
||||
|
||||
private static final Pattern OUTPUT_PATTERN = Pattern.compile("opinion=(.*),.*comment=(.*)");
|
||||
|
||||
@Autowired
|
||||
private MemoryService memoryService;
|
||||
|
||||
@Autowired
|
||||
private AgentService agentService;
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 1000)
|
||||
public void review() {
|
||||
memoryService.getMemoriesForLlmReview().stream()
|
||||
.forEach(m -> {
|
||||
Agent chatAgent = agentService.getAgent(m.getAgentId());
|
||||
if (Objects.nonNull(chatAgent)) {
|
||||
String promptStr = String.format(INSTRUCTION, m.getQuestion(), m.getDbSchema(), m.getS2sql());
|
||||
Prompt prompt = PromptTemplate.from(promptStr).apply(Collections.EMPTY_MAP);
|
||||
|
||||
keyPipelineLog.info("MemoryReviewTask reqPrompt:{}", promptStr);
|
||||
ChatLanguageModel chatLanguageModel = ChatLanguageModelProvider.provide(
|
||||
chatAgent.getLlmConfig());
|
||||
if (Objects.nonNull(chatLanguageModel)) {
|
||||
String response = chatLanguageModel.generate(prompt.toUserMessage()).content().text();
|
||||
keyPipelineLog.info("MemoryReviewTask modelResp:{}", response);
|
||||
|
||||
Matcher matcher = OUTPUT_PATTERN.matcher(response);
|
||||
if (matcher.find()) {
|
||||
m.setLlmReviewRet(MemoryReviewResult.valueOf(matcher.group(1)));
|
||||
m.setLlmReviewCmt(matcher.group(2));
|
||||
memoryService.updateMemory(m);
|
||||
}
|
||||
} else {
|
||||
log.debug("ChatLanguageModel not found for agent:{}", chatAgent.getId());
|
||||
}
|
||||
} else {
|
||||
log.debug("Agent not found for memory:{}", m.getAgentId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package com.tencent.supersonic.chat.server.parser;
|
||||
|
||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.ChatQueryRepository;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.chat.server.util.QueryReqConverter;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.LLMConfig;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.MapResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.headless.core.utils.S2ChatModelProvider;
|
||||
import com.tencent.supersonic.headless.server.service.ChatQueryService;
|
||||
import dev.langchain4j.data.message.AiMessage;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.input.Prompt;
|
||||
import dev.langchain4j.model.input.PromptTemplate;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.tencent.supersonic.chat.server.parser.ParserConfig.PARSER_MULTI_TURN_ENABLE;
|
||||
|
||||
@Slf4j
|
||||
public class MultiTurnParser implements ChatParser {
|
||||
|
||||
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
||||
|
||||
private static final PromptTemplate promptTemplate = PromptTemplate.from(
|
||||
"You are a data product manager experienced in data requirements."
|
||||
+ "Your will be provided with current and history questions asked by a user,"
|
||||
+ "along with their mapped schema elements(metric, dimension and value), "
|
||||
+ "please try understanding the semantics and rewrite a question"
|
||||
+ "(keep relevant entities, metrics, dimensions, values and date ranges)."
|
||||
+ "Current Question: {{curtQuestion}} "
|
||||
+ "Current Mapped Schema: {{curtSchema}} "
|
||||
+ "History Question: {{histQuestion}} "
|
||||
+ "History Mapped Schema: {{histSchema}} "
|
||||
+ "Rewritten Question: ");
|
||||
|
||||
@Override
|
||||
public void parse(ChatParseContext chatParseContext, ParseResp parseResp) {
|
||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
||||
MultiTurnConfig agentMultiTurnConfig = chatParseContext.getAgent().getMultiTurnConfig();
|
||||
Boolean globalMultiTurnConfig = Boolean.valueOf(parserConfig.getParameterValue(PARSER_MULTI_TURN_ENABLE));
|
||||
|
||||
Boolean multiTurnConfig = agentMultiTurnConfig != null
|
||||
? agentMultiTurnConfig.isEnableMultiTurn() : globalMultiTurnConfig;
|
||||
if (!Boolean.TRUE.equals(multiTurnConfig)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// derive mapping result of current question and parsing result of last question.
|
||||
ChatQueryService chatQueryService = ContextUtils.getBean(ChatQueryService.class);
|
||||
QueryReq queryReq = QueryReqConverter.buildText2SqlQueryReq(chatParseContext);
|
||||
MapResp currentMapResult = chatQueryService.performMapping(queryReq);
|
||||
|
||||
List<ParseResp> historyParseResults = getHistoryParseResult(chatParseContext.getChatId(), 1);
|
||||
if (historyParseResults.size() == 0) {
|
||||
return;
|
||||
}
|
||||
ParseResp lastParseResult = historyParseResults.get(0);
|
||||
Long dataId = lastParseResult.getSelectedParses().get(0).getDataSetId();
|
||||
|
||||
String curtMapStr = generateSchemaPrompt(currentMapResult.getMapInfo().getMatchedElements(dataId));
|
||||
String histMapStr = generateSchemaPrompt(lastParseResult.getSelectedParses().get(0).getElementMatches());
|
||||
String rewrittenQuery = rewriteQuery(RewriteContext.builder()
|
||||
.curtQuestion(currentMapResult.getQueryText())
|
||||
.histQuestion(lastParseResult.getQueryText())
|
||||
.curtSchema(curtMapStr)
|
||||
.histSchema(histMapStr)
|
||||
.llmConfig(queryReq.getLlmConfig())
|
||||
.build());
|
||||
chatParseContext.setQueryText(rewrittenQuery);
|
||||
log.info("Last Query: {} Current Query: {}, Rewritten Query: {}",
|
||||
lastParseResult.getQueryText(), currentMapResult.getQueryText(), rewrittenQuery);
|
||||
}
|
||||
|
||||
private String rewriteQuery(RewriteContext context) {
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
variables.put("curtQuestion", context.getCurtQuestion());
|
||||
variables.put("histQuestion", context.getHistQuestion());
|
||||
variables.put("curtSchema", context.getCurtSchema());
|
||||
variables.put("histSchema", context.getHistSchema());
|
||||
|
||||
Prompt prompt = promptTemplate.apply(variables);
|
||||
keyPipelineLog.info("MultiTurnParser reqPrompt:{}", prompt.toSystemMessage());
|
||||
|
||||
ChatLanguageModel chatLanguageModel = S2ChatModelProvider.provide(context.getLlmConfig());
|
||||
Response<AiMessage> response = chatLanguageModel.generate(prompt.toSystemMessage());
|
||||
|
||||
String result = response.content().text();
|
||||
keyPipelineLog.info("MultiTurnParser modelResp:{}", result);
|
||||
return response.content().text();
|
||||
}
|
||||
|
||||
private String generateSchemaPrompt(List<SchemaElementMatch> elementMatches) {
|
||||
List<String> metrics = new ArrayList<>();
|
||||
List<String> dimensions = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
for (SchemaElementMatch match : elementMatches) {
|
||||
if (match.getElement().getType().equals(SchemaElementType.METRIC)) {
|
||||
metrics.add(match.getWord());
|
||||
} else if (match.getElement().getType().equals(SchemaElementType.DIMENSION)) {
|
||||
dimensions.add(match.getWord());
|
||||
} else if (match.getElement().getType().equals(SchemaElementType.VALUE)) {
|
||||
values.add(match.getWord());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder prompt = new StringBuilder();
|
||||
prompt.append(String.format("'metrics:':[%s]", String.join(",", metrics)));
|
||||
prompt.append(",");
|
||||
prompt.append(String.format("'dimensions:':[%s]", String.join(",", dimensions)));
|
||||
prompt.append(",");
|
||||
prompt.append(String.format("'values:':[%s]", String.join(",", values)));
|
||||
|
||||
return prompt.toString();
|
||||
}
|
||||
|
||||
private List<ParseResp> getHistoryParseResult(int chatId, int multiNum) {
|
||||
ChatQueryRepository chatQueryRepository = ContextUtils.getBean(ChatQueryRepository.class);
|
||||
List<ParseResp> contextualParseInfoList = chatQueryRepository.getContextualParseInfo(chatId)
|
||||
.stream().filter(p -> p.getState() != ParseResp.ParseState.FAILED).collect(Collectors.toList());
|
||||
|
||||
List<ParseResp> contextualList = contextualParseInfoList.subList(0,
|
||||
Math.min(multiNum, contextualParseInfoList.size()));
|
||||
Collections.reverse(contextualList);
|
||||
return contextualList;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public static class RewriteContext {
|
||||
private String curtQuestion;
|
||||
private String histQuestion;
|
||||
private String curtSchema;
|
||||
private String histSchema;
|
||||
private LLMConfig llmConfig;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,10 @@ public class NL2PluginParser implements ChatParser {
|
||||
|
||||
@Override
|
||||
public void parse(ChatParseContext chatParseContext, ParseResp parseResp) {
|
||||
if (!chatParseContext.getAgent().containsPluginTool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pluginRecognizers.forEach(pluginRecognizer -> {
|
||||
pluginRecognizer.recognize(chatParseContext, parseResp);
|
||||
log.info("{} recallResult:{}", pluginRecognizer.getClass().getSimpleName(),
|
||||
|
||||
@@ -1,35 +1,75 @@
|
||||
package com.tencent.supersonic.chat.server.parser;
|
||||
|
||||
import static com.tencent.supersonic.chat.server.parser.ParserConfig.PARSER_MULTI_TURN_ENABLE;
|
||||
|
||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.ChatQueryRepository;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.chat.server.util.QueryReqConverter;
|
||||
import com.tencent.supersonic.common.config.EmbeddingConfig;
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import com.tencent.supersonic.common.pojo.SqlExemplar;
|
||||
import com.tencent.supersonic.common.service.impl.ExemplarServiceImpl;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.MapResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.headless.server.service.ChatQueryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import com.tencent.supersonic.headless.server.facade.service.ChatQueryService;
|
||||
import dev.langchain4j.data.message.AiMessage;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.input.Prompt;
|
||||
import dev.langchain4j.model.input.PromptTemplate;
|
||||
import dev.langchain4j.model.output.Response;
|
||||
import dev.langchain4j.model.provider.ChatLanguageModelProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Slf4j
|
||||
public class NL2SQLParser implements ChatParser {
|
||||
|
||||
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
||||
|
||||
private static final String REWRITE_INSTRUCTION = ""
|
||||
+ "#Role: You are a data product manager experienced in data requirements.\n"
|
||||
+ "#Task: Your will be provided with current and history questions asked by a user,"
|
||||
+ "along with their mapped schema elements(metric, dimension and value),"
|
||||
+ "please try understanding the semantics and rewrite a question.\n"
|
||||
+ "#Rules: "
|
||||
+ "1.ALWAYS keep relevant entities, metrics, dimensions, values and date ranges. "
|
||||
+ "2.ONLY respond with the rewritten question.\n"
|
||||
+ "#Current Question: %s\n"
|
||||
+ "#Current Mapped Schema: %s\n"
|
||||
+ "#History Question: %s\n"
|
||||
+ "#History Mapped Schema: %s\n"
|
||||
+ "#History SQL: %s\n"
|
||||
+ "#Rewritten Question: ";
|
||||
|
||||
@Override
|
||||
public void parse(ChatParseContext chatParseContext, ParseResp parseResp) {
|
||||
if (!chatParseContext.enableNL2SQL()) {
|
||||
return;
|
||||
}
|
||||
if (checkSkip(parseResp)) {
|
||||
if (!chatParseContext.enableNL2SQL() || checkSkip(parseResp)) {
|
||||
return;
|
||||
}
|
||||
processMultiTurn(chatParseContext);
|
||||
|
||||
QueryReq queryReq = QueryReqConverter.buildText2SqlQueryReq(chatParseContext);
|
||||
addExemplars(chatParseContext.getAgent().getId(), queryReq);
|
||||
|
||||
ChatQueryService chatQueryService = ContextUtils.getBean(ChatQueryService.class);
|
||||
ParseResp text2SqlParseResp = chatQueryService.performParsing(queryReq);
|
||||
@@ -95,4 +135,114 @@ public class NL2SQLParser implements ChatParser {
|
||||
parseInfo.setTextInfo(textBuilder.toString());
|
||||
}
|
||||
|
||||
private void processMultiTurn(ChatParseContext chatParseContext) {
|
||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
||||
MultiTurnConfig agentMultiTurnConfig = chatParseContext.getAgent().getMultiTurnConfig();
|
||||
Boolean globalMultiTurnConfig = Boolean.valueOf(parserConfig.getParameterValue(PARSER_MULTI_TURN_ENABLE));
|
||||
|
||||
Boolean multiTurnConfig = agentMultiTurnConfig != null
|
||||
? agentMultiTurnConfig.isEnableMultiTurn() : globalMultiTurnConfig;
|
||||
if (!Boolean.TRUE.equals(multiTurnConfig)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// derive mapping result of current question and parsing result of last question.
|
||||
ChatQueryService chatQueryService = ContextUtils.getBean(ChatQueryService.class);
|
||||
QueryReq queryReq = QueryReqConverter.buildText2SqlQueryReq(chatParseContext);
|
||||
MapResp currentMapResult = chatQueryService.performMapping(queryReq);
|
||||
|
||||
List<ParseResp> historyParseResults = getHistoryParseResult(chatParseContext.getChatId(), 1);
|
||||
if (historyParseResults.size() == 0) {
|
||||
return;
|
||||
}
|
||||
ParseResp lastParseResult = historyParseResults.get(0);
|
||||
Long dataId = lastParseResult.getSelectedParses().get(0).getDataSetId();
|
||||
|
||||
String curtMapStr = generateSchemaPrompt(currentMapResult.getMapInfo().getMatchedElements(dataId));
|
||||
String histMapStr = generateSchemaPrompt(lastParseResult.getSelectedParses().get(0).getElementMatches());
|
||||
String histSQL = lastParseResult.getSelectedParses().get(0).getSqlInfo().getCorrectS2SQL();
|
||||
String rewrittenQuery = rewriteQuery(RewriteContext.builder()
|
||||
.curtQuestion(currentMapResult.getQueryText())
|
||||
.histQuestion(lastParseResult.getQueryText())
|
||||
.curtSchema(curtMapStr)
|
||||
.histSchema(histMapStr)
|
||||
.histSQL(histSQL)
|
||||
.llmConfig(queryReq.getLlmConfig())
|
||||
.build());
|
||||
chatParseContext.setQueryText(rewrittenQuery);
|
||||
log.info("Last Query: {} Current Query: {}, Rewritten Query: {}",
|
||||
lastParseResult.getQueryText(), currentMapResult.getQueryText(), rewrittenQuery);
|
||||
}
|
||||
|
||||
private String rewriteQuery(RewriteContext context) {
|
||||
String promptStr = String.format(REWRITE_INSTRUCTION, context.getCurtQuestion(), context.getCurtSchema(),
|
||||
context.getHistQuestion(), context.getHistSchema(), context.getHistSQL());
|
||||
Prompt prompt = PromptTemplate.from(promptStr).apply(Collections.EMPTY_MAP);
|
||||
keyPipelineLog.info("NL2SQLParser reqPrompt:{}", promptStr);
|
||||
|
||||
ChatLanguageModel chatLanguageModel = ChatLanguageModelProvider.provide(context.getLlmConfig());
|
||||
Response<AiMessage> response = chatLanguageModel.generate(prompt.toUserMessage());
|
||||
|
||||
String result = response.content().text();
|
||||
keyPipelineLog.info("NL2SQLParser modelResp:{}", result);
|
||||
return response.content().text();
|
||||
}
|
||||
|
||||
private String generateSchemaPrompt(List<SchemaElementMatch> elementMatches) {
|
||||
List<String> metrics = new ArrayList<>();
|
||||
List<String> dimensions = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
for (SchemaElementMatch match : elementMatches) {
|
||||
if (match.getElement().getType().equals(SchemaElementType.METRIC)) {
|
||||
metrics.add(match.getWord());
|
||||
} else if (match.getElement().getType().equals(SchemaElementType.DIMENSION)) {
|
||||
dimensions.add(match.getWord());
|
||||
} else if (match.getElement().getType().equals(SchemaElementType.VALUE)) {
|
||||
values.add(match.getWord());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder prompt = new StringBuilder();
|
||||
prompt.append(String.format("'metrics:':[%s]", String.join(",", metrics)));
|
||||
prompt.append(",");
|
||||
prompt.append(String.format("'dimensions:':[%s]", String.join(",", dimensions)));
|
||||
prompt.append(",");
|
||||
prompt.append(String.format("'values:':[%s]", String.join(",", values)));
|
||||
|
||||
return prompt.toString();
|
||||
}
|
||||
|
||||
private List<ParseResp> getHistoryParseResult(int chatId, int multiNum) {
|
||||
ChatQueryRepository chatQueryRepository = ContextUtils.getBean(ChatQueryRepository.class);
|
||||
List<ParseResp> contextualParseInfoList = chatQueryRepository.getContextualParseInfo(chatId)
|
||||
.stream().filter(p -> p.getState() != ParseResp.ParseState.FAILED).collect(Collectors.toList());
|
||||
|
||||
List<ParseResp> contextualList = contextualParseInfoList.subList(0,
|
||||
Math.min(multiNum, contextualParseInfoList.size()));
|
||||
Collections.reverse(contextualList);
|
||||
return contextualList;
|
||||
}
|
||||
|
||||
private void addExemplars(Integer agentId, QueryReq queryReq) {
|
||||
ExemplarServiceImpl exemplarManager = ContextUtils.getBean(ExemplarServiceImpl.class);
|
||||
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
||||
String memoryCollectionName = embeddingConfig.getMemoryCollectionName(agentId);
|
||||
List<SqlExemplar> exemplars = exemplarManager.recallExemplars(memoryCollectionName,
|
||||
queryReq.getQueryText(), 5);
|
||||
queryReq.getExemplars().addAll(exemplars);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class RewriteContext {
|
||||
|
||||
private String curtQuestion;
|
||||
private String histQuestion;
|
||||
private String curtSchema;
|
||||
private String histSchema;
|
||||
private String histSQL;
|
||||
private LLMConfig llmConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tencent.supersonic.chat.server.parser;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.ParameterConfig;
|
||||
import com.tencent.supersonic.common.config.ParameterConfig;
|
||||
import com.tencent.supersonic.common.pojo.Parameter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.tencent.supersonic.chat.server.parser;
|
||||
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
|
||||
|
||||
public class PlainTextParser implements ChatParser {
|
||||
|
||||
@Override
|
||||
public void parse(ChatParseContext chatParseContext, ParseResp parseResp) {
|
||||
if (chatParseContext.getAgent().containsAnyTool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SemanticParseInfo parseInfo = new SemanticParseInfo();
|
||||
parseInfo.setQueryMode("PLAIN_TEXT");
|
||||
parseResp.getSelectedParses().add(parseInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tencent.supersonic.common.config.VisualConfig;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -60,4 +61,6 @@ public class AgentDO {
|
||||
|
||||
private String multiTurnConfig;
|
||||
|
||||
private String visualConfig;
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryStatus;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ToString
|
||||
@TableName("s2_chat_memory")
|
||||
public class ChatMemoryDO {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("question")
|
||||
private String question;
|
||||
|
||||
@TableField("agent_id")
|
||||
private Integer agentId;
|
||||
|
||||
@TableField("db_schema")
|
||||
private String dbSchema;
|
||||
|
||||
@TableField("s2_sql")
|
||||
private String s2sql;
|
||||
|
||||
@TableField("status")
|
||||
private MemoryStatus status;
|
||||
|
||||
@TableField("llm_review")
|
||||
private MemoryReviewResult llmReviewRet;
|
||||
|
||||
@TableField("llm_comment")
|
||||
private String llmReviewCmt;
|
||||
|
||||
@TableField("human_review")
|
||||
private MemoryReviewResult humanReviewRet;
|
||||
|
||||
@TableField("human_comment")
|
||||
private String humanReviewCmt;
|
||||
|
||||
@TableField("created_by")
|
||||
private String createdBy;
|
||||
|
||||
@TableField("created_at")
|
||||
private Date createdAt;
|
||||
|
||||
@TableField("updated_by")
|
||||
private String updatedBy;
|
||||
|
||||
@TableField("updated_at")
|
||||
private Date updatedAt;
|
||||
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("s2_chat_query")
|
||||
public class ChatQueryDO {
|
||||
/**
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long questionId;
|
||||
|
||||
/**
|
||||
@@ -47,4 +52,6 @@ public class ChatQueryDO {
|
||||
|
||||
private String similarQueries;
|
||||
|
||||
private String parseTimeCost;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,790 +0,0 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatQueryDOExample {
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
protected String orderByClause;
|
||||
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
protected boolean distinct;
|
||||
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
protected Integer limitStart;
|
||||
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
protected Integer limitEnd;
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public ChatQueryDOExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitStart(Integer limitStart) {
|
||||
this.limitStart = limitStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitStart() {
|
||||
return limitStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitEnd(Integer limitEnd) {
|
||||
this.limitEnd = limitEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitEnd() {
|
||||
return limitEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_chat_query null
|
||||
*/
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdIsNull() {
|
||||
addCriterion("question_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdIsNotNull() {
|
||||
addCriterion("question_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdEqualTo(Long value) {
|
||||
addCriterion("question_id =", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdNotEqualTo(Long value) {
|
||||
addCriterion("question_id <>", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdGreaterThan(Long value) {
|
||||
addCriterion("question_id >", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("question_id >=", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdLessThan(Long value) {
|
||||
addCriterion("question_id <", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("question_id <=", value, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdIn(List<Long> values) {
|
||||
addCriterion("question_id in", values, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdNotIn(List<Long> values) {
|
||||
addCriterion("question_id not in", values, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdBetween(Long value1, Long value2) {
|
||||
addCriterion("question_id between", value1, value2, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQuestionIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("question_id not between", value1, value2, "questionId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdIsNull() {
|
||||
addCriterion("agent_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdIsNotNull() {
|
||||
addCriterion("agent_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdEqualTo(Integer value) {
|
||||
addCriterion("agent_id =", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdNotEqualTo(Integer value) {
|
||||
addCriterion("agent_id <>", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdGreaterThan(Integer value) {
|
||||
addCriterion("agent_id >", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdGreaterThanOrEqualTo(Integer value) {
|
||||
addCriterion("agent_id >=", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdLessThan(Integer value) {
|
||||
addCriterion("agent_id <", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdLessThanOrEqualTo(Integer value) {
|
||||
addCriterion("agent_id <=", value, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdIn(List<Integer> values) {
|
||||
addCriterion("agent_id in", values, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdNotIn(List<Integer> values) {
|
||||
addCriterion("agent_id not in", values, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdBetween(Integer value1, Integer value2) {
|
||||
addCriterion("agent_id between", value1, value2, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andAgentIdNotBetween(Integer value1, Integer value2) {
|
||||
addCriterion("agent_id not between", value1, value2, "agentId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIsNull() {
|
||||
addCriterion("create_time is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIsNotNull() {
|
||||
addCriterion("create_time is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeEqualTo(Date value) {
|
||||
addCriterion("create_time =", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotEqualTo(Date value) {
|
||||
addCriterion("create_time <>", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeGreaterThan(Date value) {
|
||||
addCriterion("create_time >", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) {
|
||||
addCriterion("create_time >=", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeLessThan(Date value) {
|
||||
addCriterion("create_time <", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeLessThanOrEqualTo(Date value) {
|
||||
addCriterion("create_time <=", value, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIn(List<Date> values) {
|
||||
addCriterion("create_time in", values, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotIn(List<Date> values) {
|
||||
addCriterion("create_time not in", values, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeBetween(Date value1, Date value2) {
|
||||
addCriterion("create_time between", value1, value2, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeNotBetween(Date value1, Date value2) {
|
||||
addCriterion("create_time not between", value1, value2, "createTime");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameIsNull() {
|
||||
addCriterion("user_name is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameIsNotNull() {
|
||||
addCriterion("user_name is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameEqualTo(String value) {
|
||||
addCriterion("user_name =", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameNotEqualTo(String value) {
|
||||
addCriterion("user_name <>", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameGreaterThan(String value) {
|
||||
addCriterion("user_name >", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("user_name >=", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameLessThan(String value) {
|
||||
addCriterion("user_name <", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameLessThanOrEqualTo(String value) {
|
||||
addCriterion("user_name <=", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameLike(String value) {
|
||||
addCriterion("user_name like", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameNotLike(String value) {
|
||||
addCriterion("user_name not like", value, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameIn(List<String> values) {
|
||||
addCriterion("user_name in", values, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameNotIn(List<String> values) {
|
||||
addCriterion("user_name not in", values, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameBetween(String value1, String value2) {
|
||||
addCriterion("user_name between", value1, value2, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUserNameNotBetween(String value1, String value2) {
|
||||
addCriterion("user_name not between", value1, value2, "userName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateIsNull() {
|
||||
addCriterion("query_state is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateIsNotNull() {
|
||||
addCriterion("query_state is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateEqualTo(Integer value) {
|
||||
addCriterion("query_state =", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateNotEqualTo(Integer value) {
|
||||
addCriterion("query_state <>", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateGreaterThan(Integer value) {
|
||||
addCriterion("query_state >", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateGreaterThanOrEqualTo(Integer value) {
|
||||
addCriterion("query_state >=", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateLessThan(Integer value) {
|
||||
addCriterion("query_state <", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateLessThanOrEqualTo(Integer value) {
|
||||
addCriterion("query_state <=", value, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateIn(List<Integer> values) {
|
||||
addCriterion("query_state in", values, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateNotIn(List<Integer> values) {
|
||||
addCriterion("query_state not in", values, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateBetween(Integer value1, Integer value2) {
|
||||
addCriterion("query_state between", value1, value2, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andQueryStateNotBetween(Integer value1, Integer value2) {
|
||||
addCriterion("query_state not between", value1, value2, "queryState");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdIsNull() {
|
||||
addCriterion("chat_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdIsNotNull() {
|
||||
addCriterion("chat_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdEqualTo(Long value) {
|
||||
addCriterion("chat_id =", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdNotEqualTo(Long value) {
|
||||
addCriterion("chat_id <>", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdGreaterThan(Long value) {
|
||||
addCriterion("chat_id >", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("chat_id >=", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdLessThan(Long value) {
|
||||
addCriterion("chat_id <", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("chat_id <=", value, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdIn(List<Long> values) {
|
||||
addCriterion("chat_id in", values, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdNotIn(List<Long> values) {
|
||||
addCriterion("chat_id not in", values, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdBetween(Long value1, Long value2) {
|
||||
addCriterion("chat_id between", value1, value2, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andChatIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("chat_id not between", value1, value2, "chatId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreIsNull() {
|
||||
addCriterion("score is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreIsNotNull() {
|
||||
addCriterion("score is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreEqualTo(Integer value) {
|
||||
addCriterion("score =", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreNotEqualTo(Integer value) {
|
||||
addCriterion("score <>", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreGreaterThan(Integer value) {
|
||||
addCriterion("score >", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreGreaterThanOrEqualTo(Integer value) {
|
||||
addCriterion("score >=", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreLessThan(Integer value) {
|
||||
addCriterion("score <", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreLessThanOrEqualTo(Integer value) {
|
||||
addCriterion("score <=", value, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreIn(List<Integer> values) {
|
||||
addCriterion("score in", values, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreNotIn(List<Integer> values) {
|
||||
addCriterion("score not in", values, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreBetween(Integer value1, Integer value2) {
|
||||
addCriterion("score between", value1, value2, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScoreNotBetween(Integer value1, Integer value2) {
|
||||
addCriterion("score not between", value1, value2, "score");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackIsNull() {
|
||||
addCriterion("feedback is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackIsNotNull() {
|
||||
addCriterion("feedback is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackEqualTo(String value) {
|
||||
addCriterion("feedback =", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackNotEqualTo(String value) {
|
||||
addCriterion("feedback <>", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackGreaterThan(String value) {
|
||||
addCriterion("feedback >", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("feedback >=", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackLessThan(String value) {
|
||||
addCriterion("feedback <", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackLessThanOrEqualTo(String value) {
|
||||
addCriterion("feedback <=", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackLike(String value) {
|
||||
addCriterion("feedback like", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackNotLike(String value) {
|
||||
addCriterion("feedback not like", value, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackIn(List<String> values) {
|
||||
addCriterion("feedback in", values, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackNotIn(List<String> values) {
|
||||
addCriterion("feedback not in", values, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackBetween(String value1, String value2) {
|
||||
addCriterion("feedback between", value1, value2, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andFeedbackNotBetween(String value1, String value2) {
|
||||
addCriterion("feedback not between", value1, value2, "feedback");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_chat_query
|
||||
*/
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_chat_query null
|
||||
*/
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,960 +0,0 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.dataobject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class PluginDOExample {
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
protected String orderByClause;
|
||||
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
protected boolean distinct;
|
||||
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
protected Integer limitStart;
|
||||
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
protected Integer limitEnd;
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public PluginDOExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitStart(Integer limitStart) {
|
||||
this.limitStart = limitStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitStart() {
|
||||
return limitStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitEnd(Integer limitEnd) {
|
||||
this.limitEnd = limitEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitEnd() {
|
||||
return limitEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_plugin null
|
||||
*/
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andIdIsNull() {
|
||||
addCriterion("id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIsNotNull() {
|
||||
addCriterion("id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdEqualTo(Long value) {
|
||||
addCriterion("id =", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotEqualTo(Long value) {
|
||||
addCriterion("id <>", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThan(Long value) {
|
||||
addCriterion("id >", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("id >=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThan(Long value) {
|
||||
addCriterion("id <", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("id <=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIn(List<Long> values) {
|
||||
addCriterion("id in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotIn(List<Long> values) {
|
||||
addCriterion("id not in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdBetween(Long value1, Long value2) {
|
||||
addCriterion("id between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("id not between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIsNull() {
|
||||
addCriterion("type is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIsNotNull() {
|
||||
addCriterion("type is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeEqualTo(String value) {
|
||||
addCriterion("type =", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotEqualTo(String value) {
|
||||
addCriterion("type <>", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeGreaterThan(String value) {
|
||||
addCriterion("type >", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("type >=", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLessThan(String value) {
|
||||
addCriterion("type <", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLessThanOrEqualTo(String value) {
|
||||
addCriterion("type <=", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeLike(String value) {
|
||||
addCriterion("type like", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotLike(String value) {
|
||||
addCriterion("type not like", value, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeIn(List<String> values) {
|
||||
addCriterion("type in", values, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotIn(List<String> values) {
|
||||
addCriterion("type not in", values, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeBetween(String value1, String value2) {
|
||||
addCriterion("type between", value1, value2, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTypeNotBetween(String value1, String value2) {
|
||||
addCriterion("type not between", value1, value2, "type");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelIsNull() {
|
||||
addCriterion("model is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelIsNotNull() {
|
||||
addCriterion("model is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelEqualTo(String value) {
|
||||
addCriterion("model =", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelNotEqualTo(String value) {
|
||||
addCriterion("model <>", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelGreaterThan(String value) {
|
||||
addCriterion("model >", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("model >=", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelLessThan(String value) {
|
||||
addCriterion("model <", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelLessThanOrEqualTo(String value) {
|
||||
addCriterion("model <=", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelLike(String value) {
|
||||
addCriterion("model like", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelNotLike(String value) {
|
||||
addCriterion("model not like", value, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelIn(List<String> values) {
|
||||
addCriterion("model in", values, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelNotIn(List<String> values) {
|
||||
addCriterion("model not in", values, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelBetween(String value1, String value2) {
|
||||
addCriterion("model between", value1, value2, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andModelNotBetween(String value1, String value2) {
|
||||
addCriterion("model not between", value1, value2, "model");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternIsNull() {
|
||||
addCriterion("pattern is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternIsNotNull() {
|
||||
addCriterion("pattern is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternEqualTo(String value) {
|
||||
addCriterion("pattern =", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternNotEqualTo(String value) {
|
||||
addCriterion("pattern <>", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternGreaterThan(String value) {
|
||||
addCriterion("pattern >", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("pattern >=", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternLessThan(String value) {
|
||||
addCriterion("pattern <", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternLessThanOrEqualTo(String value) {
|
||||
addCriterion("pattern <=", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternLike(String value) {
|
||||
addCriterion("pattern like", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternNotLike(String value) {
|
||||
addCriterion("pattern not like", value, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternIn(List<String> values) {
|
||||
addCriterion("pattern in", values, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternNotIn(List<String> values) {
|
||||
addCriterion("pattern not in", values, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternBetween(String value1, String value2) {
|
||||
addCriterion("pattern between", value1, value2, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andPatternNotBetween(String value1, String value2) {
|
||||
addCriterion("pattern not between", value1, value2, "pattern");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeIsNull() {
|
||||
addCriterion("parse_mode is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeIsNotNull() {
|
||||
addCriterion("parse_mode is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeEqualTo(String value) {
|
||||
addCriterion("parse_mode =", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeNotEqualTo(String value) {
|
||||
addCriterion("parse_mode <>", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeGreaterThan(String value) {
|
||||
addCriterion("parse_mode >", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("parse_mode >=", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeLessThan(String value) {
|
||||
addCriterion("parse_mode <", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeLessThanOrEqualTo(String value) {
|
||||
addCriterion("parse_mode <=", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeLike(String value) {
|
||||
addCriterion("parse_mode like", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeNotLike(String value) {
|
||||
addCriterion("parse_mode not like", value, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeIn(List<String> values) {
|
||||
addCriterion("parse_mode in", values, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeNotIn(List<String> values) {
|
||||
addCriterion("parse_mode not in", values, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeBetween(String value1, String value2) {
|
||||
addCriterion("parse_mode between", value1, value2, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andParseModeNotBetween(String value1, String value2) {
|
||||
addCriterion("parse_mode not between", value1, value2, "parseMode");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIsNull() {
|
||||
addCriterion("name is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIsNotNull() {
|
||||
addCriterion("name is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameEqualTo(String value) {
|
||||
addCriterion("name =", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotEqualTo(String value) {
|
||||
addCriterion("name <>", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameGreaterThan(String value) {
|
||||
addCriterion("name >", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("name >=", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLessThan(String value) {
|
||||
addCriterion("name <", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLessThanOrEqualTo(String value) {
|
||||
addCriterion("name <=", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameLike(String value) {
|
||||
addCriterion("name like", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotLike(String value) {
|
||||
addCriterion("name not like", value, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameIn(List<String> values) {
|
||||
addCriterion("name in", values, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotIn(List<String> values) {
|
||||
addCriterion("name not in", values, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameBetween(String value1, String value2) {
|
||||
addCriterion("name between", value1, value2, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNameNotBetween(String value1, String value2) {
|
||||
addCriterion("name not between", value1, value2, "name");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtIsNull() {
|
||||
addCriterion("created_at is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtIsNotNull() {
|
||||
addCriterion("created_at is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtEqualTo(Date value) {
|
||||
addCriterion("created_at =", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtNotEqualTo(Date value) {
|
||||
addCriterion("created_at <>", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtGreaterThan(Date value) {
|
||||
addCriterion("created_at >", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtGreaterThanOrEqualTo(Date value) {
|
||||
addCriterion("created_at >=", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtLessThan(Date value) {
|
||||
addCriterion("created_at <", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtLessThanOrEqualTo(Date value) {
|
||||
addCriterion("created_at <=", value, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtIn(List<Date> values) {
|
||||
addCriterion("created_at in", values, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtNotIn(List<Date> values) {
|
||||
addCriterion("created_at not in", values, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtBetween(Date value1, Date value2) {
|
||||
addCriterion("created_at between", value1, value2, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedAtNotBetween(Date value1, Date value2) {
|
||||
addCriterion("created_at not between", value1, value2, "createdAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByIsNull() {
|
||||
addCriterion("created_by is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByIsNotNull() {
|
||||
addCriterion("created_by is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByEqualTo(String value) {
|
||||
addCriterion("created_by =", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByNotEqualTo(String value) {
|
||||
addCriterion("created_by <>", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByGreaterThan(String value) {
|
||||
addCriterion("created_by >", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("created_by >=", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByLessThan(String value) {
|
||||
addCriterion("created_by <", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByLessThanOrEqualTo(String value) {
|
||||
addCriterion("created_by <=", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByLike(String value) {
|
||||
addCriterion("created_by like", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByNotLike(String value) {
|
||||
addCriterion("created_by not like", value, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByIn(List<String> values) {
|
||||
addCriterion("created_by in", values, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByNotIn(List<String> values) {
|
||||
addCriterion("created_by not in", values, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByBetween(String value1, String value2) {
|
||||
addCriterion("created_by between", value1, value2, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreatedByNotBetween(String value1, String value2) {
|
||||
addCriterion("created_by not between", value1, value2, "createdBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtIsNull() {
|
||||
addCriterion("updated_at is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtIsNotNull() {
|
||||
addCriterion("updated_at is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtEqualTo(Date value) {
|
||||
addCriterion("updated_at =", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtNotEqualTo(Date value) {
|
||||
addCriterion("updated_at <>", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtGreaterThan(Date value) {
|
||||
addCriterion("updated_at >", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtGreaterThanOrEqualTo(Date value) {
|
||||
addCriterion("updated_at >=", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtLessThan(Date value) {
|
||||
addCriterion("updated_at <", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtLessThanOrEqualTo(Date value) {
|
||||
addCriterion("updated_at <=", value, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtIn(List<Date> values) {
|
||||
addCriterion("updated_at in", values, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtNotIn(List<Date> values) {
|
||||
addCriterion("updated_at not in", values, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtBetween(Date value1, Date value2) {
|
||||
addCriterion("updated_at between", value1, value2, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedAtNotBetween(Date value1, Date value2) {
|
||||
addCriterion("updated_at not between", value1, value2, "updatedAt");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByIsNull() {
|
||||
addCriterion("updated_by is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByIsNotNull() {
|
||||
addCriterion("updated_by is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByEqualTo(String value) {
|
||||
addCriterion("updated_by =", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByNotEqualTo(String value) {
|
||||
addCriterion("updated_by <>", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByGreaterThan(String value) {
|
||||
addCriterion("updated_by >", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("updated_by >=", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByLessThan(String value) {
|
||||
addCriterion("updated_by <", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByLessThanOrEqualTo(String value) {
|
||||
addCriterion("updated_by <=", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByLike(String value) {
|
||||
addCriterion("updated_by like", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByNotLike(String value) {
|
||||
addCriterion("updated_by not like", value, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByIn(List<String> values) {
|
||||
addCriterion("updated_by in", values, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByNotIn(List<String> values) {
|
||||
addCriterion("updated_by not in", values, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByBetween(String value1, String value2) {
|
||||
addCriterion("updated_by between", value1, value2, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andUpdatedByNotBetween(String value1, String value2) {
|
||||
addCriterion("updated_by not between", value1, value2, "updatedBy");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_plugin
|
||||
*/
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* s2_plugin null
|
||||
*/
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ChatMemoryMapper extends BaseMapper<ChatMemoryDO> {
|
||||
|
||||
}
|
||||
@@ -1,21 +1,10 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDOExample;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ChatQueryDOMapper {
|
||||
public interface ChatQueryDOMapper extends BaseMapper<ChatQueryDO> {
|
||||
|
||||
int insert(ChatQueryDO record);
|
||||
|
||||
List<ChatQueryDO> selectByExampleWithBLOBs(ChatQueryDOExample example);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(ChatQueryDO record);
|
||||
|
||||
Boolean deleteByPrimaryKey(Long questionId);
|
||||
|
||||
ChatQueryDO selectByPrimaryKey(Long questionId);
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.repository;
|
||||
|
||||
import com.tencent.supersonic.headless.core.pojo.ChatContext;
|
||||
|
||||
public interface ChatContextRepository {
|
||||
|
||||
ChatContext getOrCreateContext(int chatId);
|
||||
|
||||
void updateContext(ChatContext chatCtx);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChatMemoryRepository {
|
||||
void createMemory(ChatMemoryDO chatMemoryDO);
|
||||
|
||||
void updateMemory(ChatMemoryDO chatMemoryDO);
|
||||
|
||||
ChatMemoryDO getMemory(Long id);
|
||||
|
||||
List<ChatMemoryDO> getMemories(QueryWrapper<ChatMemoryDO> queryWrapper);
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatParseDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDO;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,10 +22,10 @@ public interface ChatQueryRepository {
|
||||
|
||||
List<QueryResp> queryShowCase(PageQueryInfoReq pageQueryInfoCommend, int agentId);
|
||||
|
||||
ChatQueryDO getLastChatQuery(long chatId);
|
||||
|
||||
int updateChatQuery(ChatQueryDO chatQueryDO);
|
||||
|
||||
void updateChatQuery(ChatQueryDO chatQueryDO, UpdateWrapper<ChatQueryDO> updateWrapper);
|
||||
|
||||
Long createChatQuery(ChatParseReq chatParseReq);
|
||||
|
||||
List<ChatParseDO> batchSaveParseInfo(ChatParseReq chatParseReq, ParseResp parseResult,
|
||||
@@ -34,8 +35,6 @@ public interface ChatQueryRepository {
|
||||
|
||||
List<ChatParseDO> getParseInfoList(List<Long> questionIds);
|
||||
|
||||
Boolean deleteChatQuery(Long questionId);
|
||||
|
||||
List<ParseResp> getContextualParseInfo(Integer chatId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.repository.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.mapper.ChatMemoryMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.ChatMemoryRepository;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Primary
|
||||
public class ChatMemoryRepositoryImpl implements ChatMemoryRepository {
|
||||
|
||||
private final ChatMemoryMapper chatMemoryMapper;
|
||||
|
||||
public ChatMemoryRepositoryImpl(ChatMemoryMapper chatMemoryMapper) {
|
||||
this.chatMemoryMapper = chatMemoryMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMemory(ChatMemoryDO chatMemoryDO) {
|
||||
chatMemoryMapper.insert(chatMemoryDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMemory(ChatMemoryDO chatMemoryDO) {
|
||||
chatMemoryMapper.updateById(chatMemoryDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatMemoryDO getMemory(Long id) {
|
||||
return chatMemoryMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChatMemoryDO> getMemories(QueryWrapper<ChatMemoryDO> queryWrapper) {
|
||||
return chatMemoryMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.tencent.supersonic.chat.server.persistence.repository.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
@@ -8,8 +10,6 @@ import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.SimilarQueryRecallResp;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatParseDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDOExample;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDOExample.Criteria;
|
||||
import com.tencent.supersonic.chat.server.persistence.mapper.ChatParseMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.mapper.ChatQueryDOMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.mapper.custom.ShowCaseCustomMapper;
|
||||
@@ -19,10 +19,12 @@ import com.tencent.supersonic.common.util.PageUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseTimeCostResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -38,37 +40,33 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
|
||||
private final ChatQueryDOMapper chatQueryDOMapper;
|
||||
@Autowired
|
||||
private ChatQueryDOMapper chatQueryDOMapper;
|
||||
|
||||
private final ChatParseMapper chatParseMapper;
|
||||
@Autowired
|
||||
private ChatParseMapper chatParseMapper;
|
||||
|
||||
private final ShowCaseCustomMapper showCaseCustomMapper;
|
||||
|
||||
public ChatQueryRepositoryImpl(ChatQueryDOMapper chatQueryDOMapper,
|
||||
ChatParseMapper chatParseMapper,
|
||||
ShowCaseCustomMapper showCaseCustomMapper) {
|
||||
this.chatQueryDOMapper = chatQueryDOMapper;
|
||||
this.chatParseMapper = chatParseMapper;
|
||||
this.showCaseCustomMapper = showCaseCustomMapper;
|
||||
}
|
||||
@Autowired
|
||||
private ShowCaseCustomMapper showCaseCustomMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<QueryResp> getChatQuery(PageQueryInfoReq pageQueryInfoReq, Long chatId) {
|
||||
ChatQueryDOExample example = new ChatQueryDOExample();
|
||||
example.setOrderByClause("question_id desc");
|
||||
Criteria criteria = example.createCriteria();
|
||||
QueryWrapper<ChatQueryDO> queryWrapper = new QueryWrapper<>();
|
||||
if (chatId != null) {
|
||||
criteria.andChatIdEqualTo(chatId);
|
||||
queryWrapper.lambda().eq(ChatQueryDO::getChatId, chatId);
|
||||
}
|
||||
if (StringUtils.isNotBlank(pageQueryInfoReq.getUserName())) {
|
||||
criteria.andUserNameEqualTo(pageQueryInfoReq.getUserName());
|
||||
queryWrapper.lambda().eq(ChatQueryDO::getUserName, pageQueryInfoReq.getUserName());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(pageQueryInfoReq.getIds())) {
|
||||
criteria.andQuestionIdIn(pageQueryInfoReq.getIds());
|
||||
queryWrapper.lambda().in(ChatQueryDO::getQuestionId, pageQueryInfoReq.getIds());
|
||||
}
|
||||
|
||||
queryWrapper.lambda().orderByDesc(ChatQueryDO::getQuestionId);
|
||||
|
||||
PageInfo<ChatQueryDO> pageInfo = PageHelper.startPage(pageQueryInfoReq.getCurrent(),
|
||||
pageQueryInfoReq.getPageSize())
|
||||
.doSelectPageInfo(() -> chatQueryDOMapper.selectByExampleWithBLOBs(example));
|
||||
.doSelectPageInfo(() -> chatQueryDOMapper.selectList(queryWrapper));
|
||||
|
||||
PageInfo<QueryResp> chatQueryVOPageInfo = PageUtils.pageInfo2PageInfoVo(pageInfo);
|
||||
chatQueryVOPageInfo.setList(
|
||||
@@ -89,7 +87,7 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
|
||||
@Override
|
||||
public ChatQueryDO getChatQueryDO(Long queryId) {
|
||||
return chatQueryDOMapper.selectByPrimaryKey(queryId);
|
||||
return chatQueryDOMapper.selectById(queryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,6 +108,8 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
}
|
||||
queryResp.setSimilarQueries(JSONObject.parseArray(chatQueryDO.getSimilarQueries(),
|
||||
SimilarQueryRecallResp.class));
|
||||
queryResp.setParseTimeCost(JsonUtil.toObject(chatQueryDO.getParseTimeCost(),
|
||||
ParseTimeCostResp.class));
|
||||
return queryResp;
|
||||
}
|
||||
|
||||
@@ -161,23 +161,13 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatQueryDO getLastChatQuery(long chatId) {
|
||||
ChatQueryDOExample example = new ChatQueryDOExample();
|
||||
example.setOrderByClause("question_id desc");
|
||||
example.setLimitEnd(1);
|
||||
example.setLimitStart(0);
|
||||
Criteria criteria = example.createCriteria();
|
||||
criteria.andChatIdEqualTo(chatId);
|
||||
List<ChatQueryDO> chatQueryDOS = chatQueryDOMapper.selectByExampleWithBLOBs(example);
|
||||
if (!CollectionUtils.isEmpty(chatQueryDOS)) {
|
||||
return chatQueryDOS.get(0);
|
||||
}
|
||||
return null;
|
||||
public int updateChatQuery(ChatQueryDO chatQueryDO) {
|
||||
return chatQueryDOMapper.updateById(chatQueryDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateChatQuery(ChatQueryDO chatQueryDO) {
|
||||
return chatQueryDOMapper.updateByPrimaryKeyWithBLOBs(chatQueryDO);
|
||||
public void updateChatQuery(ChatQueryDO chatQueryDO, UpdateWrapper<ChatQueryDO> updateWrapper) {
|
||||
chatQueryDOMapper.update(chatQueryDO, updateWrapper);
|
||||
}
|
||||
|
||||
public ChatParseDO getParseInfo(Long questionId, int parseId) {
|
||||
@@ -189,11 +179,6 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
|
||||
return chatParseMapper.getParseInfoList(questionIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteChatQuery(Long questionId) {
|
||||
return chatQueryDOMapper.deleteByPrimaryKey(questionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ParseResp> getContextualParseInfo(Integer chatId) {
|
||||
List<ChatParseDO> chatParseDOList = chatParseMapper.getContextualParseInfo(chatId);
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.tencent.supersonic.chat.server.persistence.mapper.PluginDOMapper;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.PluginRepository;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -39,7 +39,7 @@ public class PluginRepositoryImpl implements PluginRepository {
|
||||
|
||||
for (PluginDO pluginDO : pluginDOS) {
|
||||
String pattern = pluginDO.getPattern();
|
||||
if (Strings.isNotEmpty(pattern)) {
|
||||
if (StringUtils.isNotEmpty(pattern)) {
|
||||
|
||||
Pattern pluginPattern = Pattern.compile(pattern);
|
||||
Matcher pluginMatcher = pluginPattern.matcher(queryText);
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Plugin extends RecordInfo {
|
||||
public class ChatPlugin extends RecordInfo {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Plugin extends RecordInfo {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public boolean isContainsAllModel() {
|
||||
public boolean isContainsAllDataSet() {
|
||||
return CollectionUtils.isNotEmpty(dataSetList) && dataSetList.contains(-1L);
|
||||
}
|
||||
|
||||
@@ -14,17 +14,17 @@ import com.tencent.supersonic.chat.server.plugin.event.PluginUpdateEvent;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.chat.server.service.PluginService;
|
||||
import com.tencent.supersonic.common.config.EmbeddingConfig;
|
||||
import com.tencent.supersonic.common.util.ComponentFactory;
|
||||
import com.tencent.supersonic.common.service.EmbeddingService;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.common.util.embedding.EmbeddingQuery;
|
||||
import com.tencent.supersonic.common.util.embedding.Retrieval;
|
||||
import com.tencent.supersonic.common.util.embedding.RetrieveQuery;
|
||||
import com.tencent.supersonic.common.util.embedding.RetrieveQueryResult;
|
||||
import com.tencent.supersonic.common.util.embedding.S2EmbeddingStore;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
||||
import dev.langchain4j.data.segment.TextSegment;
|
||||
import dev.langchain4j.store.embedding.Retrieval;
|
||||
import dev.langchain4j.store.embedding.RetrieveQuery;
|
||||
import dev.langchain4j.store.embedding.RetrieveQueryResult;
|
||||
import dev.langchain4j.store.embedding.TextSegmentConvert;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -49,12 +49,13 @@ public class PluginManager {
|
||||
@Autowired
|
||||
private EmbeddingConfig embeddingConfig;
|
||||
|
||||
private S2EmbeddingStore s2EmbeddingStore = ComponentFactory.getS2EmbeddingStore();
|
||||
@Autowired
|
||||
private EmbeddingService embeddingService;
|
||||
|
||||
public static List<Plugin> getPluginAgentCanSupport(ChatParseContext chatParseContext) {
|
||||
public static List<ChatPlugin> getPluginAgentCanSupport(ChatParseContext chatParseContext) {
|
||||
PluginService pluginService = ContextUtils.getBean(PluginService.class);
|
||||
Agent agent = chatParseContext.getAgent();
|
||||
List<Plugin> plugins = pluginService.getPluginList();
|
||||
List<ChatPlugin> plugins = pluginService.getPluginList();
|
||||
if (Objects.isNull(agent)) {
|
||||
return plugins;
|
||||
}
|
||||
@@ -66,7 +67,7 @@ public class PluginManager {
|
||||
plugins = plugins.stream().filter(plugin -> pluginIds.contains(plugin.getId()))
|
||||
.collect(Collectors.toList());
|
||||
log.info("plugins witch can be supported by cur agent :{} {}", agent.getName(),
|
||||
plugins.stream().map(Plugin::getName).collect(Collectors.toList()));
|
||||
plugins.stream().map(ChatPlugin::getName).collect(Collectors.toList()));
|
||||
return plugins;
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class PluginManager {
|
||||
|
||||
@EventListener
|
||||
public void addPlugin(PluginAddEvent pluginAddEvent) {
|
||||
Plugin plugin = pluginAddEvent.getPlugin();
|
||||
ChatPlugin plugin = pluginAddEvent.getPlugin();
|
||||
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
||||
requestEmbeddingPluginAdd(convert(Lists.newArrayList(plugin)));
|
||||
}
|
||||
@@ -92,8 +93,8 @@ public class PluginManager {
|
||||
|
||||
@EventListener
|
||||
public void updatePlugin(PluginUpdateEvent pluginUpdateEvent) {
|
||||
Plugin oldPlugin = pluginUpdateEvent.getOldPlugin();
|
||||
Plugin newPlugin = pluginUpdateEvent.getNewPlugin();
|
||||
ChatPlugin oldPlugin = pluginUpdateEvent.getOldPlugin();
|
||||
ChatPlugin newPlugin = pluginUpdateEvent.getNewPlugin();
|
||||
if (CollectionUtils.isNotEmpty(oldPlugin.getExampleQuestionList())) {
|
||||
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(oldPlugin)));
|
||||
}
|
||||
@@ -104,7 +105,7 @@ public class PluginManager {
|
||||
|
||||
@EventListener
|
||||
public void delPlugin(PluginDelEvent pluginDelEvent) {
|
||||
Plugin plugin = pluginDelEvent.getPlugin();
|
||||
ChatPlugin plugin = pluginDelEvent.getPlugin();
|
||||
if (CollectionUtils.isNotEmpty(plugin.getExampleQuestionList())) {
|
||||
requestEmbeddingPluginDelete(getEmbeddingId(Lists.newArrayList(plugin)));
|
||||
}
|
||||
@@ -116,25 +117,21 @@ public class PluginManager {
|
||||
}
|
||||
String presetCollection = embeddingConfig.getPresetCollection();
|
||||
|
||||
List<EmbeddingQuery> queries = new ArrayList<>();
|
||||
List<TextSegment> queries = new ArrayList<>();
|
||||
for (String id : queryIds) {
|
||||
EmbeddingQuery embeddingQuery = new EmbeddingQuery();
|
||||
embeddingQuery.setQueryId(id);
|
||||
queries.add(embeddingQuery);
|
||||
TextSegment query = TextSegment.from("");
|
||||
TextSegmentConvert.addQueryId(query, id);
|
||||
queries.add(query);
|
||||
}
|
||||
s2EmbeddingStore.deleteQuery(presetCollection, queries);
|
||||
embeddingService.deleteQuery(presetCollection, queries);
|
||||
}
|
||||
|
||||
public void requestEmbeddingPluginAdd(List<EmbeddingQuery> queries) {
|
||||
public void requestEmbeddingPluginAdd(List<TextSegment> queries) {
|
||||
if (CollectionUtils.isEmpty(queries)) {
|
||||
return;
|
||||
}
|
||||
String presetCollection = embeddingConfig.getPresetCollection();
|
||||
s2EmbeddingStore.addQuery(presetCollection, queries);
|
||||
}
|
||||
|
||||
public void requestEmbeddingPluginAddALL(List<Plugin> plugins) {
|
||||
requestEmbeddingPluginAdd(convert(plugins));
|
||||
embeddingService.addQuery(presetCollection, queries);
|
||||
}
|
||||
|
||||
public RetrieveQueryResult recognize(String embeddingText) {
|
||||
@@ -143,7 +140,7 @@ public class PluginManager {
|
||||
.queryTextsList(Collections.singletonList(embeddingText))
|
||||
.build();
|
||||
|
||||
List<RetrieveQueryResult> resultList = s2EmbeddingStore.retrieveQuery(embeddingConfig.getPresetCollection(),
|
||||
List<RetrieveQueryResult> resultList = embeddingService.retrieveQuery(embeddingConfig.getPresetCollection(),
|
||||
retrieveQuery, embeddingConfig.getNResult());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(resultList)) {
|
||||
@@ -158,15 +155,14 @@ public class PluginManager {
|
||||
throw new RuntimeException("get embedding result failed");
|
||||
}
|
||||
|
||||
public List<EmbeddingQuery> convert(List<Plugin> plugins) {
|
||||
List<EmbeddingQuery> queries = Lists.newArrayList();
|
||||
for (Plugin plugin : plugins) {
|
||||
public List<TextSegment> convert(List<ChatPlugin> plugins) {
|
||||
List<TextSegment> queries = Lists.newArrayList();
|
||||
for (ChatPlugin plugin : plugins) {
|
||||
List<String> exampleQuestions = plugin.getExampleQuestionList();
|
||||
int num = 0;
|
||||
for (String pattern : exampleQuestions) {
|
||||
EmbeddingQuery query = new EmbeddingQuery();
|
||||
query.setQueryId(generateUniqueEmbeddingId(num, plugin.getId()));
|
||||
query.setQuery(pattern);
|
||||
TextSegment query = TextSegment.from(pattern);
|
||||
TextSegmentConvert.addQueryId(query, generateUniqueEmbeddingId(num, plugin.getId()));
|
||||
queries.add(query);
|
||||
num++;
|
||||
}
|
||||
@@ -174,10 +170,10 @@ public class PluginManager {
|
||||
return queries;
|
||||
}
|
||||
|
||||
private Set<String> getEmbeddingId(List<Plugin> plugins) {
|
||||
private Set<String> getEmbeddingId(List<ChatPlugin> plugins) {
|
||||
Set<String> embeddingIdSet = new HashSet<>();
|
||||
for (EmbeddingQuery query : convert(plugins)) {
|
||||
embeddingIdSet.add(query.getQueryId());
|
||||
for (TextSegment query : convert(plugins)) {
|
||||
TextSegmentConvert.addQueryId(query, TextSegmentConvert.getQueryId(query));
|
||||
}
|
||||
return embeddingIdSet;
|
||||
}
|
||||
@@ -195,28 +191,28 @@ public class PluginManager {
|
||||
return String.valueOf(Integer.parseInt(id) / 1000);
|
||||
}
|
||||
|
||||
public static Pair<Boolean, Set<Long>> resolve(Plugin plugin, ChatParseContext chatParseContext) {
|
||||
public static Pair<Boolean, Set<Long>> resolve(ChatPlugin plugin, ChatParseContext chatParseContext) {
|
||||
SchemaMapInfo schemaMapInfo = chatParseContext.getMapInfo();
|
||||
Set<Long> pluginMatchedModel = getPluginMatchedModel(plugin, chatParseContext);
|
||||
if (CollectionUtils.isEmpty(pluginMatchedModel) && !plugin.isContainsAllModel()) {
|
||||
Set<Long> pluginMatchedDataSet = getPluginMatchedDataSet(plugin, chatParseContext);
|
||||
if (CollectionUtils.isEmpty(pluginMatchedDataSet) && !plugin.isContainsAllDataSet()) {
|
||||
return Pair.of(false, Sets.newHashSet());
|
||||
}
|
||||
List<ParamOption> paramOptions = getSemanticOption(plugin);
|
||||
if (CollectionUtils.isEmpty(paramOptions)) {
|
||||
return Pair.of(true, pluginMatchedModel);
|
||||
return Pair.of(true, pluginMatchedDataSet);
|
||||
}
|
||||
Set<Long> matchedModel = Sets.newHashSet();
|
||||
Set<Long> matchedDataSet = Sets.newHashSet();
|
||||
Map<Long, List<ParamOption>> paramOptionMap = paramOptions.stream()
|
||||
.collect(Collectors.groupingBy(ParamOption::getModelId));
|
||||
for (Long modelId : paramOptionMap.keySet()) {
|
||||
List<ParamOption> params = paramOptionMap.get(modelId);
|
||||
.collect(Collectors.groupingBy(ParamOption::getDataSetId));
|
||||
for (Long dataSetId : paramOptionMap.keySet()) {
|
||||
List<ParamOption> params = paramOptionMap.get(dataSetId);
|
||||
if (CollectionUtils.isEmpty(params)) {
|
||||
matchedModel.add(modelId);
|
||||
matchedDataSet.add(dataSetId);
|
||||
continue;
|
||||
}
|
||||
boolean matched = true;
|
||||
for (ParamOption paramOption : params) {
|
||||
Set<Long> elementIdSet = getSchemaElementMatch(modelId, schemaMapInfo);
|
||||
Set<Long> elementIdSet = getSchemaElementMatch(dataSetId, schemaMapInfo);
|
||||
if (CollectionUtils.isEmpty(elementIdSet)) {
|
||||
matched = false;
|
||||
break;
|
||||
@@ -227,13 +223,13 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
if (matched) {
|
||||
matchedModel.add(modelId);
|
||||
matchedDataSet.add(dataSetId);
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isEmpty(matchedModel)) {
|
||||
if (CollectionUtils.isEmpty(matchedDataSet)) {
|
||||
return Pair.of(false, Sets.newHashSet());
|
||||
}
|
||||
return Pair.of(true, matchedModel);
|
||||
return Pair.of(true, matchedDataSet);
|
||||
}
|
||||
|
||||
private static Set<Long> getSchemaElementMatch(Long modelId, SchemaMapInfo schemaMapInfo) {
|
||||
@@ -249,13 +245,13 @@ public class PluginManager {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static List<ParamOption> getSemanticOption(Plugin plugin) {
|
||||
private static List<ParamOption> getSemanticOption(ChatPlugin plugin) {
|
||||
WebBase webBase = JSONObject.parseObject(plugin.getConfig(), WebBase.class);
|
||||
if (Objects.isNull(webBase)) {
|
||||
return null;
|
||||
}
|
||||
List<ParamOption> paramOptions = webBase.getParamOptions();
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(paramOptions)) {
|
||||
if (CollectionUtils.isEmpty(paramOptions)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return paramOptions.stream()
|
||||
@@ -263,19 +259,19 @@ public class PluginManager {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Set<Long> getPluginMatchedModel(Plugin plugin, ChatParseContext chatParseContext) {
|
||||
private static Set<Long> getPluginMatchedDataSet(ChatPlugin plugin, ChatParseContext chatParseContext) {
|
||||
Set<Long> matchedDataSets = chatParseContext.getMapInfo().getMatchedDataSetInfos();
|
||||
if (plugin.isContainsAllModel()) {
|
||||
if (plugin.isContainsAllDataSet()) {
|
||||
return Sets.newHashSet(plugin.getDefaultMode());
|
||||
}
|
||||
List<Long> modelIds = plugin.getDataSetList();
|
||||
Set<Long> pluginMatchedModel = Sets.newHashSet();
|
||||
for (Long modelId : modelIds) {
|
||||
if (matchedDataSets.contains(modelId)) {
|
||||
pluginMatchedModel.add(modelId);
|
||||
List<Long> dataSetList = plugin.getDataSetList();
|
||||
Set<Long> pluginMatchedDataSet = Sets.newHashSet();
|
||||
for (Long dataSetId : dataSetList) {
|
||||
if (matchedDataSets.contains(dataSetId)) {
|
||||
pluginMatchedDataSet.add(dataSetId);
|
||||
}
|
||||
}
|
||||
return pluginMatchedModel;
|
||||
return pluginMatchedDataSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class PluginParseResult {
|
||||
|
||||
private Plugin plugin;
|
||||
private ChatPlugin plugin;
|
||||
private QueryFilters queryFilters;
|
||||
private double distance;
|
||||
private String queryText;
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Set;
|
||||
@NoArgsConstructor
|
||||
public class PluginRecallResult {
|
||||
|
||||
private Plugin plugin;
|
||||
private ChatPlugin plugin;
|
||||
|
||||
private Set<Long> dataSetIds;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ParamOption {
|
||||
|
||||
private String keyAlias;
|
||||
|
||||
private Long modelId;
|
||||
private Long dataSetId;
|
||||
|
||||
private Long elementId;
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ public abstract class PluginSemanticQuery {
|
||||
webBaseResult.setUrl(webPage.getUrl());
|
||||
Map<String, Object> elementValueMap = getElementMap(pluginParseResult);
|
||||
List<ParamOption> paramOptions = Lists.newArrayList();
|
||||
if (!CollectionUtils.isEmpty(webPage.getParamOptions()) && !CollectionUtils.isEmpty(elementValueMap)) {
|
||||
if (!CollectionUtils.isEmpty(webPage.getParamOptions())) {
|
||||
for (ParamOption paramOption : webPage.getParamOptions()) {
|
||||
if (paramOption.getModelId() != null
|
||||
&& !parseInfo.getDataSetId().equals(paramOption.getModelId())) {
|
||||
if (paramOption.getDataSetId() != null
|
||||
&& !parseInfo.getDataSetId().equals(paramOption.getDataSetId())) {
|
||||
continue;
|
||||
}
|
||||
paramOptions.add(paramOption);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.tencent.supersonic.chat.server.plugin.build.webpage;
|
||||
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||
import com.tencent.supersonic.chat.server.plugin.build.PluginSemanticQuery;
|
||||
@@ -25,7 +25,7 @@ public class WebPageQuery extends PluginSemanticQuery {
|
||||
}
|
||||
|
||||
protected WebPageResp buildResponse(PluginParseResult pluginParseResult) {
|
||||
Plugin plugin = pluginParseResult.getPlugin();
|
||||
ChatPlugin plugin = pluginParseResult.getPlugin();
|
||||
WebPageResp webPageResponse = new WebPageResp();
|
||||
webPageResponse.setName(plugin.getName());
|
||||
webPageResponse.setPluginId(plugin.getId());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tencent.supersonic.chat.server.plugin.build.webservice;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginQueryManager;
|
||||
import com.tencent.supersonic.chat.server.plugin.build.ParamOption;
|
||||
@@ -61,7 +61,7 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
||||
if (data.get("columns") != null) {
|
||||
queryResult.setQueryColumns((List<QueryColumn>) data.get("columns"));
|
||||
}
|
||||
queryResult.setTextResult(String.valueOf(data.get("textInfo")));
|
||||
queryResult.setTextResult(String.valueOf(data.get("data")));
|
||||
queryResult.setQueryState(QueryState.SUCCESS);
|
||||
} catch (Exception e) {
|
||||
log.info("webServiceResponse result has an exception:{}", e.getMessage());
|
||||
@@ -71,7 +71,7 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
||||
|
||||
protected WebServiceResp buildResponse(PluginParseResult pluginParseResult) {
|
||||
WebServiceResp webServiceResponse = new WebServiceResp();
|
||||
Plugin plugin = pluginParseResult.getPlugin();
|
||||
ChatPlugin plugin = pluginParseResult.getPlugin();
|
||||
WebBase webBase = fillWebBaseResult(JsonUtil.toObject(plugin.getConfig(), WebBase.class), pluginParseResult);
|
||||
webServiceResponse.setWebBase(webBase);
|
||||
List<ParamOption> paramOptions = webBase.getParamOptions();
|
||||
@@ -80,7 +80,8 @@ public class WebServiceQuery extends PluginSemanticQuery {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(params), headers);
|
||||
URI requestUrl = UriComponentsBuilder.fromHttpUrl(webBase.getUrl()).build().encode().toUri();
|
||||
String url = webBase.getUrl() + "?queryText=" + pluginParseResult.getQueryText();
|
||||
URI requestUrl = UriComponentsBuilder.fromHttpUrl(url).build().encode().toUri();
|
||||
ResponseEntity responseEntity = null;
|
||||
Object objectResponse = null;
|
||||
restTemplate = ContextUtils.getBean(RestTemplate.class);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.tencent.supersonic.chat.server.plugin.event;
|
||||
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class PluginAddEvent extends ApplicationEvent {
|
||||
|
||||
private Plugin plugin;
|
||||
private ChatPlugin plugin;
|
||||
|
||||
public PluginAddEvent(Object source, Plugin plugin) {
|
||||
public PluginAddEvent(Object source, ChatPlugin plugin) {
|
||||
super(source);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
public ChatPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.tencent.supersonic.chat.server.plugin.event;
|
||||
|
||||
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class PluginDelEvent extends ApplicationEvent {
|
||||
|
||||
private Plugin plugin;
|
||||
private ChatPlugin plugin;
|
||||
|
||||
public PluginDelEvent(Object source, Plugin plugin) {
|
||||
public PluginDelEvent(Object source, ChatPlugin plugin) {
|
||||
super(source);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Plugin getPlugin() {
|
||||
public ChatPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.tencent.supersonic.chat.server.plugin.event;
|
||||
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
public class PluginUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private Plugin oldPlugin;
|
||||
private ChatPlugin oldPlugin;
|
||||
|
||||
private Plugin newPlugin;
|
||||
private ChatPlugin newPlugin;
|
||||
|
||||
public PluginUpdateEvent(Object source, Plugin oldPlugin, Plugin newPlugin) {
|
||||
public PluginUpdateEvent(Object source, ChatPlugin oldPlugin, ChatPlugin newPlugin) {
|
||||
super(source);
|
||||
this.oldPlugin = oldPlugin;
|
||||
this.newPlugin = newPlugin;
|
||||
}
|
||||
|
||||
public Plugin getOldPlugin() {
|
||||
public ChatPlugin getOldPlugin() {
|
||||
return oldPlugin;
|
||||
}
|
||||
|
||||
public Plugin getNewPlugin() {
|
||||
public ChatPlugin getNewPlugin() {
|
||||
return newPlugin;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.tencent.supersonic.chat.server.plugin.recognize;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginParseResult;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
||||
@@ -45,9 +45,9 @@ public abstract class PluginRecognizer {
|
||||
|
||||
public void buildQuery(ChatParseContext chatParseContext, ParseResp parseResp,
|
||||
PluginRecallResult pluginRecallResult) {
|
||||
Plugin plugin = pluginRecallResult.getPlugin();
|
||||
ChatPlugin plugin = pluginRecallResult.getPlugin();
|
||||
Set<Long> dataSetIds = pluginRecallResult.getDataSetIds();
|
||||
if (plugin.isContainsAllModel()) {
|
||||
if (plugin.isContainsAllDataSet()) {
|
||||
dataSetIds = Sets.newHashSet(-1L);
|
||||
}
|
||||
for (Long dataSetId : dataSetIds) {
|
||||
@@ -59,11 +59,11 @@ public abstract class PluginRecognizer {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Plugin> getPluginList(ChatParseContext chatParseContext) {
|
||||
protected List<ChatPlugin> getPluginList(ChatParseContext chatParseContext) {
|
||||
return PluginManager.getPluginAgentCanSupport(chatParseContext);
|
||||
}
|
||||
|
||||
protected SemanticParseInfo buildSemanticParseInfo(Long dataSetId, Plugin plugin,
|
||||
protected SemanticParseInfo buildSemanticParseInfo(Long dataSetId, ChatPlugin plugin,
|
||||
ChatParseContext chatParseContext, double distance) {
|
||||
List<SchemaElementMatch> schemaElementMatches = chatParseContext.getMapInfo().getMatchedElements(dataSetId);
|
||||
QueryFilters queryFilters = chatParseContext.getQueryFilters();
|
||||
|
||||
@@ -2,19 +2,15 @@ package com.tencent.supersonic.chat.server.plugin.recognize.embedding;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.chat.server.plugin.ParseMode;
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginManager;
|
||||
import com.tencent.supersonic.chat.server.plugin.PluginRecallResult;
|
||||
import com.tencent.supersonic.chat.server.plugin.recognize.PluginRecognizer;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.common.config.EmbeddingConfig;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.common.util.embedding.Retrieval;
|
||||
import com.tencent.supersonic.common.util.embedding.RetrieveQueryResult;
|
||||
import com.tencent.supersonic.headless.core.chat.parser.llm.PythonLLMProxy;
|
||||
import com.tencent.supersonic.headless.core.utils.ComponentFactory;
|
||||
import dev.langchain4j.store.embedding.Retrieval;
|
||||
import dev.langchain4j.store.embedding.RetrieveQueryResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -31,11 +27,7 @@ import java.util.stream.Collectors;
|
||||
public class EmbeddingRecallRecognizer extends PluginRecognizer {
|
||||
|
||||
public boolean checkPreCondition(ChatParseContext chatParseContext) {
|
||||
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
||||
if (StringUtils.isBlank(embeddingConfig.getUrl()) && ComponentFactory.getLLMProxy() instanceof PythonLLMProxy) {
|
||||
return false;
|
||||
}
|
||||
List<Plugin> plugins = getPluginList(chatParseContext);
|
||||
List<ChatPlugin> plugins = getPluginList(chatParseContext);
|
||||
return !CollectionUtils.isEmpty(plugins);
|
||||
}
|
||||
|
||||
@@ -45,10 +37,10 @@ public class EmbeddingRecallRecognizer extends PluginRecognizer {
|
||||
if (CollectionUtils.isEmpty(embeddingRetrievals)) {
|
||||
return null;
|
||||
}
|
||||
List<Plugin> plugins = getPluginList(chatParseContext);
|
||||
Map<Long, Plugin> pluginMap = plugins.stream().collect(Collectors.toMap(Plugin::getId, p -> p));
|
||||
List<ChatPlugin> plugins = getPluginList(chatParseContext);
|
||||
Map<Long, ChatPlugin> pluginMap = plugins.stream().collect(Collectors.toMap(ChatPlugin::getId, p -> p));
|
||||
for (Retrieval embeddingRetrieval : embeddingRetrievals) {
|
||||
Plugin plugin = pluginMap.get(Long.parseLong(embeddingRetrieval.getId()));
|
||||
ChatPlugin plugin = pluginMap.get(Long.parseLong(embeddingRetrieval.getId()));
|
||||
if (plugin == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ChatExecuteContext {
|
||||
private User user;
|
||||
private Integer agentId;
|
||||
private Long queryId;
|
||||
private Integer chatId;
|
||||
private int parseId;
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.tencent.supersonic.headless.api.pojo.RelatedSchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.headless.server.service.impl.SemanticService;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Comparator;
|
||||
@@ -40,7 +40,7 @@ public class DimensionRecommendProcessor implements ExecuteResultProcessor {
|
||||
}
|
||||
|
||||
private List<SchemaElement> getDimensions(Long metricId, Long dataSetId) {
|
||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||
SemanticLayerService semanticService = ContextUtils.getBean(SemanticLayerService.class);
|
||||
DataSetSchema dataSetSchema = semanticService.getDataSetSchema(dataSetId);
|
||||
List<Long> drillDownDimensions = Lists.newArrayList();
|
||||
Set<SchemaElement> metricElements = dataSetSchema.getMetrics();
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
package com.tencent.supersonic.chat.server.processor.execute;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT_INT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT_INT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.TIMES_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatExecuteContext;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
@@ -10,6 +20,7 @@ import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||
import com.tencent.supersonic.common.pojo.enums.RatioOverType;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.common.util.DateUtils;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlSelectHelper;
|
||||
import com.tencent.supersonic.headless.api.pojo.AggregateInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
@@ -18,12 +29,8 @@ import com.tencent.supersonic.headless.api.pojo.request.QueryStructReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||
import com.tencent.supersonic.headless.core.config.AggregatorConfig;
|
||||
import com.tencent.supersonic.headless.core.utils.QueryReqBuilder;
|
||||
import com.tencent.supersonic.headless.server.service.QueryService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.tencent.supersonic.headless.chat.utils.QueryReqBuilder;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
@@ -34,23 +41,17 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT_INT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT_INT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.TIMES_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Add ratio queries for metric queries.
|
||||
@@ -74,9 +75,9 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
||||
|
||||
public AggregateInfo getAggregateInfo(User user, SemanticParseInfo semanticParseInfo, QueryResult queryResult) {
|
||||
|
||||
Set<String> resultMetricNames = queryResult.getQueryColumns()
|
||||
.stream().map(c -> c.getNameEn()).collect(Collectors.toSet());
|
||||
|
||||
Set<String> resultMetricNames = new HashSet<>();
|
||||
queryResult.getQueryColumns()
|
||||
.stream().forEach(c -> resultMetricNames.addAll(SqlSelectHelper.getColumnFromExpr(c.getNameEn())));
|
||||
Optional<SchemaElement> ratioMetric = semanticParseInfo.getMetrics().stream()
|
||||
.filter(m -> resultMetricNames.contains(m.getBizName())).findFirst();
|
||||
|
||||
@@ -126,14 +127,14 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
||||
|
||||
@SneakyThrows
|
||||
private MetricInfo queryRatio(User user, SemanticParseInfo semanticParseInfo, SchemaElement metric,
|
||||
AggOperatorEnum aggOperatorEnum, QueryResult queryResult) {
|
||||
AggOperatorEnum aggOperatorEnum, QueryResult queryResult) {
|
||||
|
||||
QueryStructReq queryStructReq = QueryReqBuilder.buildStructRatioReq(semanticParseInfo, metric, aggOperatorEnum);
|
||||
String dateField = QueryReqBuilder.getDateField(semanticParseInfo.getDateInfo());
|
||||
queryStructReq.setGroups(new ArrayList<>(Arrays.asList(dateField)));
|
||||
queryStructReq.setDateInfo(getRatioDateConf(aggOperatorEnum, semanticParseInfo, queryResult));
|
||||
queryStructReq.setConvertToSql(false);
|
||||
QueryService queryService = ContextUtils.getBean(QueryService.class);
|
||||
SemanticLayerService queryService = ContextUtils.getBean(SemanticLayerService.class);
|
||||
SemanticQueryResp queryResp = queryService.queryByReq(queryStructReq, user);
|
||||
MetricInfo metricInfo = new MetricInfo();
|
||||
metricInfo.setStatistics(new HashMap<>());
|
||||
|
||||
@@ -3,16 +3,18 @@ package com.tencent.supersonic.chat.server.processor.execute;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatExecuteContext;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.common.util.embedding.Retrieval;
|
||||
import com.tencent.supersonic.common.util.embedding.RetrieveQuery;
|
||||
import com.tencent.supersonic.common.util.embedding.RetrieveQueryResult;
|
||||
import dev.langchain4j.store.embedding.Retrieval;
|
||||
import dev.langchain4j.store.embedding.RetrieveQuery;
|
||||
import dev.langchain4j.store.embedding.RetrieveQueryResult;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
import com.tencent.supersonic.headless.core.chat.knowledge.MetaEmbeddingService;
|
||||
import com.tencent.supersonic.headless.chat.knowledge.MetaEmbeddingService;
|
||||
import java.util.Objects;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -66,8 +68,13 @@ public class MetricRecommendProcessor implements ExecuteResultProcessor {
|
||||
}
|
||||
for (Retrieval retrieval : retrievals) {
|
||||
if (!metricIds.contains(Retrieval.getLongId(retrieval.getId()))) {
|
||||
SchemaElement schemaElement = JSONObject.parseObject(JSONObject.toJSONString(retrieval.getMetadata()),
|
||||
SchemaElement.class);
|
||||
if (Objects.nonNull(retrieval.getMetadata().get("id"))) {
|
||||
String idStr = retrieval.getMetadata().get("id").toString()
|
||||
.replaceAll(DictWordType.NATURE_SPILT, "");
|
||||
retrieval.getMetadata().put("id", idStr);
|
||||
}
|
||||
String metaStr = JSONObject.toJSONString(retrieval.getMetadata());
|
||||
SchemaElement schemaElement = JSONObject.parseObject(metaStr, SchemaElement.class);
|
||||
if (retrieval.getMetadata().containsKey("dataSetId")) {
|
||||
String dataSetId = retrieval.getMetadata().get("dataSetId").toString()
|
||||
.replace(Constants.UNDERLINE, "");
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.EntityInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.headless.core.chat.query.QueryManager;
|
||||
import com.tencent.supersonic.headless.server.service.impl.SemanticService;
|
||||
import com.tencent.supersonic.headless.chat.query.QueryManager;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,11 +26,12 @@ public class EntityInfoProcessor implements ParseResultProcessor {
|
||||
}
|
||||
selectedParses.forEach(parseInfo -> {
|
||||
String queryMode = parseInfo.getQueryMode();
|
||||
if (QueryManager.containsRuleQuery(queryMode)) {
|
||||
if (QueryManager.containsRuleQuery(queryMode) || "PLAIN".equals(queryMode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//1. set entity info
|
||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||
SemanticLayerService semanticService = ContextUtils.getBean(SemanticLayerService.class);
|
||||
DataSetSchema dataSetSchema = semanticService.getDataSetSchema(parseInfo.getDataSetId());
|
||||
EntityInfo entityInfo = semanticService.getEntityInfo(parseInfo, dataSetSchema, chatParseContext.getUser());
|
||||
if (QueryManager.isTagQuery(queryMode)
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
package com.tencent.supersonic.chat.server.processor.parse;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.SimilarQueryRecallResp;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatQueryDO;
|
||||
import com.tencent.supersonic.chat.server.persistence.repository.ChatQueryRepository;
|
||||
import com.tencent.supersonic.chat.server.pojo.ChatParseContext;
|
||||
import com.tencent.supersonic.chat.server.util.SimilarQueryManager;
|
||||
import com.tencent.supersonic.common.config.EmbeddingConfig;
|
||||
import com.tencent.supersonic.common.pojo.SqlExemplar;
|
||||
import com.tencent.supersonic.common.service.ExemplarService;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -43,25 +40,12 @@ public class QueryRecommendProcessor implements ParseResultProcessor {
|
||||
}
|
||||
|
||||
public List<SimilarQueryRecallResp> getSimilarQueries(String queryText, Integer agentId) {
|
||||
//1. recall solved query by queryText
|
||||
SimilarQueryManager solvedQueryManager = ContextUtils.getBean(SimilarQueryManager.class);
|
||||
List<SimilarQueryRecallResp> similarQueries = solvedQueryManager.recallSimilarQuery(queryText, agentId);
|
||||
if (CollectionUtils.isEmpty(similarQueries)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
//2. remove low score query
|
||||
List<Long> queryIds = similarQueries.stream()
|
||||
.map(SimilarQueryRecallResp::getQueryId).collect(Collectors.toList());
|
||||
int lowScoreThreshold = 3;
|
||||
List<QueryResp> queryResps = getChatQuery(queryIds);
|
||||
if (CollectionUtils.isEmpty(queryResps)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
Set<Long> lowScoreQueryIds = queryResps.stream().filter(queryResp ->
|
||||
queryResp.getScore() != null && queryResp.getScore() <= lowScoreThreshold)
|
||||
.map(QueryResp::getQuestionId).collect(Collectors.toSet());
|
||||
return similarQueries.stream().filter(solvedQueryRecallResp ->
|
||||
!lowScoreQueryIds.contains(solvedQueryRecallResp.getQueryId()))
|
||||
ExemplarService exemplarService = ContextUtils.getBean(ExemplarService.class);
|
||||
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
||||
String memoryCollectionName = embeddingConfig.getMemoryCollectionName(agentId);
|
||||
List<SqlExemplar> exemplars = exemplarService.recallExemplars(memoryCollectionName, queryText, 5);
|
||||
return exemplars.stream().map(sqlExemplar ->
|
||||
SimilarQueryRecallResp.builder().queryText(sqlExemplar.getQuestion()).build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -70,19 +54,12 @@ public class QueryRecommendProcessor implements ParseResultProcessor {
|
||||
return chatQueryRepository.getChatQueryDO(queryId);
|
||||
}
|
||||
|
||||
private List<QueryResp> getChatQuery(List<Long> queryIds) {
|
||||
ChatQueryRepository chatQueryRepository = ContextUtils.getBean(ChatQueryRepository.class);
|
||||
PageQueryInfoReq pageQueryInfoReq = new PageQueryInfoReq();
|
||||
pageQueryInfoReq.setIds(queryIds);
|
||||
pageQueryInfoReq.setPageSize(100);
|
||||
pageQueryInfoReq.setCurrent(1);
|
||||
PageInfo<QueryResp> queryRespPageInfo = chatQueryRepository.getChatQuery(pageQueryInfoReq, null);
|
||||
return queryRespPageInfo.getList();
|
||||
}
|
||||
|
||||
private void updateChatQuery(ChatQueryDO chatQueryDO) {
|
||||
ChatQueryRepository chatQueryRepository = ContextUtils.getBean(ChatQueryRepository.class);
|
||||
chatQueryRepository.updateChatQuery(chatQueryDO);
|
||||
UpdateWrapper<ChatQueryDO> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("question_id", chatQueryDO.getQuestionId());
|
||||
updateWrapper.set("similar_queries", chatQueryDO.getSimilarQueries());
|
||||
chatQueryRepository.updateChatQuery(chatQueryDO, updateWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||
import com.tencent.supersonic.chat.server.util.LLMConnHelper;
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -26,21 +28,19 @@ public class AgentController {
|
||||
private AgentService agentService;
|
||||
|
||||
@PostMapping
|
||||
public boolean createAgent(@RequestBody Agent agent,
|
||||
public Agent createAgent(@RequestBody Agent agent,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
agentService.createAgent(agent, user);
|
||||
return true;
|
||||
return agentService.createAgent(agent, user);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public boolean updateAgent(@RequestBody Agent agent,
|
||||
public Agent updateAgent(@RequestBody Agent agent,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
agentService.updateAgent(agent, user);
|
||||
return true;
|
||||
return agentService.updateAgent(agent, user);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -49,6 +49,11 @@ public class AgentController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/testLLMConn")
|
||||
public boolean testLLMConn(@RequestBody LLMConfig llmConfig) {
|
||||
return LLMConnHelper.testConnection(llmConfig);
|
||||
}
|
||||
|
||||
@RequestMapping("/getAgentList")
|
||||
public List<Agent> getAgentList() {
|
||||
return agentService.getAgents();
|
||||
|
||||
@@ -8,8 +8,9 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||
import com.tencent.supersonic.chat.server.service.ConfigService;
|
||||
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ItemResp;
|
||||
import com.tencent.supersonic.headless.server.service.SchemaService;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -32,7 +33,7 @@ public class ChatConfigController {
|
||||
private ConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private SchemaService schemaService;
|
||||
private SemanticLayerService semanticLayerService;
|
||||
|
||||
@PostMapping
|
||||
public Long addChatConfig(@RequestBody ChatConfigBaseReq extendBaseCmd,
|
||||
@@ -70,7 +71,12 @@ public class ChatConfigController {
|
||||
|
||||
@GetMapping("/getDomainDataSetTree")
|
||||
public List<ItemResp> getDomainDataSetTree() {
|
||||
return schemaService.getDomainDataSetTree();
|
||||
return semanticLayerService.getDomainDataSetTree();
|
||||
}
|
||||
|
||||
@GetMapping("/getDataSetSchema/{id}")
|
||||
public DataSetSchema getDataSetSchema(@PathVariable("id") Long id) {
|
||||
return semanticLayerService.getDataSetSchema(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.DimensionValueReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.tencent.supersonic.chat.server.rest;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
import com.tencent.supersonic.chat.server.service.MemoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping({"/api/chat/memory"})
|
||||
public class MemoryController {
|
||||
|
||||
@Autowired
|
||||
private MemoryService memoryService;
|
||||
|
||||
@PostMapping("/updateMemory")
|
||||
public Boolean updateMemory(@RequestBody ChatMemoryUpdateReq chatMemoryUpdateReq,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
memoryService.updateMemory(chatMemoryUpdateReq, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequestMapping("/pageMemories")
|
||||
public PageInfo<ChatMemoryDO> pageMemories(@RequestBody PageMemoryReq pageMemoryReq) {
|
||||
return memoryService.pageMemories(pageMemoryReq);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,21 @@
|
||||
package com.tencent.supersonic.chat.server.rest;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.PluginQueryReq;
|
||||
import com.tencent.supersonic.chat.server.plugin.Plugin;
|
||||
import com.tencent.supersonic.chat.server.plugin.ChatPlugin;
|
||||
import com.tencent.supersonic.chat.server.service.PluginService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
@@ -25,7 +28,7 @@ public class PluginController {
|
||||
protected PluginService pluginService;
|
||||
|
||||
@PostMapping
|
||||
public boolean createPlugin(@RequestBody Plugin plugin,
|
||||
public boolean createPlugin(@RequestBody ChatPlugin plugin,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
@@ -34,7 +37,7 @@ public class PluginController {
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public boolean updatePlugin(@RequestBody Plugin plugin,
|
||||
public boolean updatePlugin(@RequestBody ChatPlugin plugin,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
@@ -49,16 +52,23 @@ public class PluginController {
|
||||
}
|
||||
|
||||
@RequestMapping("/getPluginList")
|
||||
public List<Plugin> getPluginList() {
|
||||
public List<ChatPlugin> getPluginList() {
|
||||
return pluginService.getPluginList();
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
List<Plugin> query(@RequestBody PluginQueryReq pluginQueryReq,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
List<ChatPlugin> query(@RequestBody PluginQueryReq pluginQueryReq,
|
||||
HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
return pluginService.queryWithAuthCheck(pluginQueryReq, user);
|
||||
}
|
||||
|
||||
@AuthenticationIgnore
|
||||
@PostMapping("/pluginDemo")
|
||||
public String pluginDemo(@RequestParam("queryText") String queryText,
|
||||
@RequestBody Object object) {
|
||||
return String.format("已收到您的问题:%s, 但这只是一个demo~", queryText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ public interface AgentService {
|
||||
|
||||
List<Agent> getAgents();
|
||||
|
||||
Integer createAgent(Agent agent, User user);
|
||||
Agent createAgent(Agent agent, User user);
|
||||
|
||||
void updateAgent(Agent agent, User user);
|
||||
Agent updateAgent(Agent agent, User user);
|
||||
|
||||
Agent getAgent(Integer id);
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ public interface ChatManageService {
|
||||
|
||||
int updateQuery(ChatQueryDO chatQueryDO);
|
||||
|
||||
void updateParseCostTime(ParseResp parseResp);
|
||||
|
||||
List<ChatParseDO> batchAddParse(ChatParseReq chatParseReq, ParseResp parseResult);
|
||||
|
||||
SemanticParseInfo getParseInfo(Long questionId, int parseId);
|
||||
|
||||
@@ -20,6 +20,8 @@ public interface ChatService {
|
||||
|
||||
QueryResult performExecution(ChatExecuteReq chatExecuteReq) throws Exception;
|
||||
|
||||
QueryResult parseAndExecute(int chatId, int agentId, String queryText);
|
||||
|
||||
Object queryData(ChatQueryDataReq chatQueryDataReq, User user) throws Exception;
|
||||
|
||||
SemanticParseInfo queryContext(Integer chatId);
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||
import com.tencent.supersonic.chat.server.config.ChatConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ConfigService {
|
||||
|
||||
@@ -21,8 +20,6 @@ public interface ConfigService {
|
||||
|
||||
ItemNameVisibilityInfo getItemNameVisibility(ChatConfig chatConfig);
|
||||
|
||||
ItemNameVisibilityInfo getVisibilityByModelId(Long modelId);
|
||||
|
||||
List<ChatConfigResp> search(ChatConfigFilter filter, User user);
|
||||
|
||||
ChatConfigRichResp getConfigRichInfo(Long modelId);
|
||||
@@ -31,5 +28,4 @@ public interface ConfigService {
|
||||
|
||||
List<ChatConfigRichResp> getAllChatRichConfig();
|
||||
|
||||
Map<Long, ChatConfigRichResp> getModelIdToChatRichConfig();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.tencent.supersonic.chat.server.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MemoryService {
|
||||
void createMemory(ChatMemoryDO memory);
|
||||
|
||||
void updateMemory(ChatMemoryUpdateReq chatMemoryUpdateReq, User user);
|
||||
|
||||
void updateMemory(ChatMemoryDO memory);
|
||||
|
||||
PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq);
|
||||
|
||||
List<ChatMemoryDO> getMemories(ChatMemoryFilter chatMemoryFilter);
|
||||
|
||||
List<ChatMemoryDO> getMemoriesForLlmReview();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user