DataEase+MaxKB:让BI再多个“A”
一、前言
当前DataEase BI更多聚焦于BI展示层,然而,在与组件Copilot 以及后续计划替换的 Sqlbot的融合方面,目前仍存在一些亟待解决的问题,当它们尝试与 DataEase 进行结合应用时,出现了两种较为突出的状况。
一方面,Copilot与 DataEase 的集成割裂感过于强烈。这种割裂不仅体现在操作流程上,用户需要在不同组件之间频繁切换,增加了操作的复杂性和繁琐程度;还表现在数据交互层面,组件之间无法实现无缝的数据传递与共享,导致数据的一致性和连贯性受到影响,极大地降低了用户的使用体验。
另一方面,Sqlbot组件在进行数据查询时,往往针对的是全局数据集。这意味着无论用户当前正在关注哪个具体的大屏展示内容,组件所返回的查询结果都是基于整个数据集的宏观信息。但用户在实际使用过程中,通常更希望针对当前所展示大屏中的特定数据进行问答交互和深入解析,以获取与当前展示内容紧密相关的详细信息和分析结果。现有的这种查询方式与用户实际需求之间存在明显偏差,无法精准满足用户对于当前展示大屏数据问答和解析的期望。
基于上述痛点,我们将MaxKB对应应用嵌入DataEase公共链接大屏,可以实现针对当前大屏的智能问答。
二、实现
1、环境准备
·部署DataEase:详见 https://dataease.io/docs/v2/installation/online_installation/
·部署Maxkb:详见 https://maxkb.cn/docs/v2/installation/online_installtion/
2、MaxKB应用制作
2.1 函数库编写
·生成DataEase token
import jwt
import requestsfrom Crypto.Cipher import AES from Crypto.Util.Padding import pad from base64 import b64encode from uuid import uuid4 import time def generate_token(accessKey,secretKey): """生成包含AES加密签名的JWT令牌""" # 生成唯一ID和时间戳 unique_id = str(uuid4()) timestamp = str(time.time_ns() // 1000000) # AES加密逻辑(原aes_encrypt方法的功能) src = accessKey + "|" + unique_id + "|" + timestamp secret_key = secretKey.encode('utf-8') iv = accessKey.encode('utf-8') cipher = AES.new(secret_key, AES.MODE_CBC, iv) encrypted = cipher.encrypt(pad(src.encode('utf-8'), AES.block_size)) signature = b64encode(encrypted).decode('utf-8') # 生成并返回JWT令牌 token = jwt.encode( {'accessKey': accessKey, 'signature': signature}, secretKey, algorithm='HS256' ) return token
·调用DataEase查询看板详情接口
import requests
import json def findById(token,id,busiFlag,domain): # 生成签名和令牌 # 设置请求头 headers = { 'Accept': '*/*', 'Content-Type': 'application/json', 'x-de-ask-token': token } requestData = { 'id': id, 'busiFlag': busiFlag, 'source':'main', 'resourceTable':'core' } # 发送请求 response = requests.post(domain+'/de2api/dataVisualization/findById', headers=headers, json=requestData) responseJson = json.loads(response.text) title_map = {} for key, value in responseJson['data']['canvasViewInfo'].items(): # 获取每个对象的title作为新的键 title = value.get('title') if title: # 确保title存在(避免空值) title_map[title] = value return title_map
·获取图表数据
import requests
import json def getData(token,key,canvasViewMap,domain): # 生成签名和令牌 # 设置请求头 headers = { 'Accept': '*/*', 'Content-Type': 'application/json', 'x-de-ask-token': token } # 发送请求 response = requests.post(domain+'/de2api/chartData/getData', headers=headers, json=canvasViewMap[key]) responseJson = json.loads(response.text) data = responseJson['data']['data'] shortname_to_name = { field["fieldShortName"]: field["name"] for field in data["fields"] } mapped_table_rows = [] for row in data["tableRow"]: mapped_row = { shortname_to_name[shortname]: value for shortname, value in row.items() } mapped_table_rows.append(mapped_row) return mapped_table_rows
2.2高级编排
注:
1、其中涉及的id等信息与de嵌入式那里获取类似,应用见附件
2、原理是通过接口查询视图标题(所以视图必须得有标题且不一样,故富文本不支持)
3、中间会用到大模型提取视图标题,目前有些客户本地部署的大模型不能正确提取标题
3、部署Nginx
yum install gcc pcre-devel openssl-devel -y
wget http://nginx.org/download/nginx-1.20.2.tar.gz && tar -zxvf nginx-1.20.2.tar.gz && cd nginx-1.20.2 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_v2_module --with-http_sub_module && make && make install
cat /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server_tokens off; server { listen 8088 ; location / { proxy_pass http://localhost:9080/;#DataEase server_name_in_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; sub_filter '</head>' '<script async defer src="http://XXX:8080/chat/api/embed?protocol=http&host=XXX:8080&token=XXXX"></script>'; #MaxKB应用嵌入 sub_filter_once on; } } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } } }
4、效果展示
三、优化点
- 应用中的提示词可以根据实际需求优化,也可以与智能问数场景结合;
- 当前nginx那边多个大屏+对应mk应用需要多个url代理
通过网盘分享的文件:DataEase.mk
链接: https://pan.baidu.com/s/1bRJLBHasveXR4l4wPPaE8g?pwd=7htt 提取码: 7htt