Skip to content

Commit 6849f9c

Browse files
committed
Merge branch 'main' of https://github.com/dataease/SQLBot
2 parents 19096e9 + 9fa388c commit 6849f9c

File tree

12 files changed

+104
-83
lines changed

12 files changed

+104
-83
lines changed

backend/apps/chat/models/chat_model.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class AiModelQuestion(BaseModel):
111111
sub_query: Optional[list[dict]] = None
112112

113113
def sql_sys_question(self):
114-
return get_sql_template()['system'].format(engine=self.engine, schema=self.db_schema, question=self.question, lang=self.lang)
114+
return get_sql_template()['system'].format(engine=self.engine, schema=self.db_schema, question=self.question,
115+
lang=self.lang)
115116

116117
def sql_user_question(self):
117118
return get_sql_template()['user'].format(engine=self.engine, schema=self.db_schema, question=self.question,
@@ -153,22 +154,29 @@ def filter_sys_question(self):
153154

154155
def filter_user_question(self):
155156
return get_permissions_template()['user'].format(sql=self.sql, filter=self.filter)
156-
157-
def dynamic_sys_question(self):
157+
158+
def dynamic_sys_question(self):
158159
return get_dynamic_template()['system'].format(lang=self.lang, engine=self.engine)
159-
160-
def dynamic_user_question(self):
160+
161+
def dynamic_user_question(self):
161162
return get_dynamic_template()['user'].format(sql=self.sql, sub_query=self.sub_query)
162163

164+
163165
class ChatQuestion(AiModelQuestion):
164-
question: str = Body(description='用户提问')
165-
chat_id: int = Body(description='会话ID')
166+
question: str
167+
chat_id: int
166168

167169

168170
class ChatMcp(ChatQuestion):
169-
token: str = Body(description='token')
171+
token: str
170172

171173

172174
class ChatStart(BaseModel):
173175
username: str = Body(description='用户名')
174176
password: str = Body(description='密码')
177+
178+
179+
class McpQuestion(BaseModel):
180+
question: str = Body(description='用户提问')
181+
chat_id: int = Body(description='会话ID')
182+
token: str = Body(description='token')

backend/apps/chat/task/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ def run_analysis_or_predict_task(self, action_type: str):
10321032
def validate_history_ds(self):
10331033
_ds = self.ds
10341034
if not self.current_assistant:
1035-
current_ds = self.session.exec(CoreDatasource, _ds.id)
1035+
current_ds = self.session.get(CoreDatasource, _ds.id)
10361036
if not current_ds:
10371037
raise Exception('ds is invalid')
10381038
else:

backend/apps/mcp/mcp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sqlmodel import select
1313

1414
from apps.chat.api.chat import create_chat
15-
from apps.chat.models.chat_model import ChatMcp, CreateChat, ChatStart
15+
from apps.chat.models.chat_model import ChatMcp, CreateChat, ChatStart, McpQuestion
1616
from apps.chat.task.llm import LLMService
1717
from apps.system.crud.user import authenticate
1818
from apps.system.crud.user import get_db_user
@@ -76,7 +76,7 @@ async def mcp_start(session: SessionDep, chat: ChatStart):
7676

7777

7878
@router.post("/mcp_question", operation_id="mcp_question")
79-
async def mcp_question(session: SessionDep, chat: ChatMcp):
79+
async def mcp_question(session: SessionDep, chat: McpQuestion):
8080
try:
8181
payload = jwt.decode(
8282
chat.token, settings.SECRET_KEY, algorithms=[security.ALGORITHM]
@@ -105,8 +105,9 @@ async def mcp_question(session: SessionDep, chat: ChatMcp):
105105
if session_user.status != 1:
106106
raise HTTPException(status_code=400, detail="Inactive user")
107107

108+
mcp_chat = ChatMcp(token=chat.token, chat_id=chat.chat_id, question=chat.question)
108109
# ask
109-
llm_service = LLMService(session_user, chat)
110+
llm_service = LLMService(session_user, mcp_chat)
110111
llm_service.init_record()
111112

112113
return StreamingResponse(llm_service.run_task(False), media_type="text/event-stream")

frontend/src/views/chat/component/charts/Bar.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,28 @@ export class Bar extends BaseG2Chart {
104104
return { name: y[0].name, value: `${data[y[0].value]}${_data.isPercent ? '%' : ''}` }
105105
}
106106
},
107-
labels: [
108-
{
109-
text: (data: any) => {
110-
const value = data[y[0].value]
111-
if (value === undefined || value === null) {
112-
return ''
113-
}
114-
return `${value}${_data.isPercent ? '%' : ''}`
115-
},
116-
position: (data: any) => {
117-
if (data[y[0].value] < 0) {
118-
return 'left'
119-
}
120-
return 'right'
121-
},
122-
transform: [
123-
{ type: 'contrastReverse' },
124-
{ type: 'exceedAdjust' },
125-
{ type: 'overlapHide' },
126-
],
127-
},
128-
],
107+
// labels: [
108+
// {
109+
// text: (data: any) => {
110+
// const value = data[y[0].value]
111+
// if (value === undefined || value === null) {
112+
// return ''
113+
// }
114+
// return `${value}${_data.isPercent ? '%' : ''}`
115+
// },
116+
// position: (data: any) => {
117+
// if (data[y[0].value] < 0) {
118+
// return 'left'
119+
// }
120+
// return 'right'
121+
// },
122+
// transform: [
123+
// { type: 'contrastReverse' },
124+
// { type: 'exceedAdjust' },
125+
// { type: 'overlapHide' },
126+
// ],
127+
// },
128+
// ],
129129
} as G2Spec
130130

131131
if (series.length > 0) {

frontend/src/views/chat/component/charts/Column.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,28 @@ export class Column extends BaseG2Chart {
9393
return { name: y[0].name, value: `${data[y[0].value]}${_data.isPercent ? '%' : ''}` }
9494
}
9595
},
96-
labels: [
97-
{
98-
text: (data: any) => {
99-
const value = data[y[0].value]
100-
if (value === undefined || value === null) {
101-
return ''
102-
}
103-
return `${value}${_data.isPercent ? '%' : ''}`
104-
},
105-
position: (data: any) => {
106-
if (data[y[0].value] < 0) {
107-
return 'bottom'
108-
}
109-
return 'top'
110-
},
111-
transform: [
112-
{ type: 'contrastReverse' },
113-
{ type: 'exceedAdjust' },
114-
{ type: 'overlapHide' },
115-
],
116-
},
117-
],
96+
// labels: [
97+
// {
98+
// text: (data: any) => {
99+
// const value = data[y[0].value]
100+
// if (value === undefined || value === null) {
101+
// return ''
102+
// }
103+
// return `${value}${_data.isPercent ? '%' : ''}`
104+
// },
105+
// position: (data: any) => {
106+
// if (data[y[0].value] < 0) {
107+
// return 'bottom'
108+
// }
109+
// return 'top'
110+
// },
111+
// transform: [
112+
// { type: 'contrastReverse' },
113+
// { type: 'exceedAdjust' },
114+
// { type: 'overlapHide' },
115+
// ],
116+
// },
117+
// ],
118118
} as G2Spec
119119

120120
if (series.length > 0) {

frontend/src/views/chat/component/charts/Line.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ export class Line extends BaseG2Chart {
5959
encode: {
6060
shape: 'smooth',
6161
},
62-
labels: [
63-
{
64-
text: (data: any) => {
65-
const value = data[y[0].value]
66-
if (value === undefined || value === null) {
67-
return ''
68-
}
69-
return `${value}${_data.isPercent ? '%' : ''}`
70-
},
71-
style: {
72-
dx: -10,
73-
dy: -12,
74-
},
75-
transform: [
76-
{ type: 'contrastReverse' },
77-
{ type: 'exceedAdjust' },
78-
{ type: 'overlapHide' },
79-
],
80-
},
81-
],
62+
// labels: [
63+
// {
64+
// text: (data: any) => {
65+
// const value = data[y[0].value]
66+
// if (value === undefined || value === null) {
67+
// return ''
68+
// }
69+
// return `${value}${_data.isPercent ? '%' : ''}`
70+
// },
71+
// style: {
72+
// dx: -10,
73+
// dy: -12,
74+
// },
75+
// transform: [
76+
// { type: 'contrastReverse' },
77+
// { type: 'exceedAdjust' },
78+
// { type: 'overlapHide' },
79+
// ],
80+
// },
81+
// ],
8282
tooltip: (data) => {
8383
if (series.length > 0) {
8484
return {
@@ -95,6 +95,9 @@ export class Line extends BaseG2Chart {
9595
style: {
9696
fill: 'white',
9797
},
98+
encode: {
99+
size: 1.5,
100+
},
98101
tooltip: false,
99102
},
100103
],

frontend/src/views/dashboard/canvas/CanvasCore.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ defineExpose({
12321232
<component
12331233
:is="findComponent(item.component)"
12341234
:ref="'shape_component_' + item.id"
1235-
class="sq-component slot-component dragHandle"
1235+
class="sq-component slot-component"
12361236
:class="{ 'sq-component-hidden': item.component !== 'SQTab' }"
12371237
:config-item="item"
12381238
:view-info="canvasViewInfo[item.id]"

frontend/src/views/dashboard/canvas/ComponentBar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const doDeleteComponent = (e: MouseEvent) => {
8080
right: 12px;
8181
top: 12px;
8282
display: flex;
83-
z-index: 1;
83+
z-index: 11;
8484
cursor: pointer !important;
8585
}
8686

frontend/src/views/dashboard/components/sq-tab/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ defineExpose({
237237
:component-data="tabItem.componentData"
238238
:canvas-view-info="canvasViewInfo"
239239
:base-matrix-count="tabBaseMatrixCount"
240+
:canvas-id="tabItem.name"
240241
></SQPreview>
241242
<DashboardEditor
242243
v-else

frontend/src/views/dashboard/editor/ChatChartSelection.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function selectChange(value: boolean, viewInfo: any) {
9797
}
9898
9999
const getData = (record: any) => {
100+
const recordData = record.data
100101
if (record?.predict_record_id !== undefined && record?.predict_record_id !== null) {
101102
let _list = []
102103
if (record?.predict_data && typeof record?.predict_data === 'string') {
@@ -121,13 +122,15 @@ const getData = (record: any) => {
121122
return _list
122123
}
123124
124-
if (record.data && record.data.length > 0) {
125-
return concat(record.data, _list)
125+
if (recordData.data && recordData.data.length > 0) {
126+
recordData.data = concat(recordData.data, _list)
127+
} else {
128+
recordData.data = _list
126129
}
127130
128-
return _list
131+
return recordData
129132
} else {
130-
return record.data
133+
return recordData
131134
}
132135
}
133136
@@ -142,7 +145,7 @@ function adaptorChartInfoList(chatInfo: ChatInfo) {
142145
(record?.sql || record?.chart)) ||
143146
(record?.predict_record_id !== undefined &&
144147
record?.predict_record_id !== null &&
145-
data.length > 0)
148+
data.data.length > 0)
146149
) {
147150
const recordeInfo = { id: chatInfo.id + '_' + record.id, data: data, chart: {} }
148151
const chartBaseInfo = JSON.parse(record.chart)

0 commit comments

Comments
 (0)