Skip to content

Commit 79e8632

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 507c4de + a3b91bd commit 79e8632

File tree

10 files changed

+251
-168
lines changed

10 files changed

+251
-168
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ docker compose up -d
4444

4545
如你有更多问题,可以加入我们的技术交流群与我们交流。
4646

47-
TBD: 交流群二维码
47+
<img width="396" height="396" alt="contact_me_qr" src="https://github.com/user-attachments/assets/2594ff29-5426-4457-b051-279855610030" />
48+
4849

4950
## UI 展示
5051

backend/apps/chat/curd/chat.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import datetime
2-
import sqlparse
32
from typing import List
43

54
import orjson
6-
from sqlalchemy import and_
7-
from sqlalchemy.orm import load_only
5+
import sqlparse
6+
from sqlalchemy import and_, select
87

98
from apps.chat.models.chat_model import Chat, ChatRecord, CreateChat, ChatInfo, RenameChat, ChatQuestion
109
from apps.datasource.models.datasource import CoreDatasource
@@ -47,26 +46,29 @@ def delete_chat(session, chart_id) -> str:
4746

4847

4948
def get_chat_chart_data(session: SessionDep, chart_record_id: int):
50-
res = session.query(ChatRecord).options(load_only(ChatRecord.data)).get(chart_record_id)
51-
if res:
49+
stmt = select(ChatRecord.data).where(and_(ChatRecord.id == chart_record_id))
50+
res = session.execute(stmt)
51+
for row in res:
5252
try:
53-
return orjson.loads(res.data)
53+
return orjson.loads(row.data)
5454
except Exception:
5555
pass
5656
return {}
5757

5858

5959
def get_chat_predict_data(session: SessionDep, chart_record_id: int):
60-
res = session.query(ChatRecord).options(load_only(ChatRecord.predict_data)).get(chart_record_id)
61-
if res:
60+
stmt = select(ChatRecord.predict_data).where(and_(ChatRecord.id == chart_record_id))
61+
res = session.execute(stmt)
62+
for row in res:
6263
try:
63-
return orjson.loads(res.predict_data)
64+
return orjson.loads(row.predict_data)
6465
except Exception:
6566
pass
66-
return ''
67+
return {}
6768

6869

69-
def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser, current_assistant: CurrentAssistant) -> ChatInfo:
70+
def get_chat_with_records(session: SessionDep, chart_id: int, current_user: CurrentUser,
71+
current_assistant: CurrentAssistant) -> ChatInfo:
7072
chat = session.get(Chat, chart_id)
7173
if not chat:
7274
raise Exception(f"Chat with id {chart_id} not found")
@@ -78,7 +80,7 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
7880
ds = out_ds_instance.get_ds(chat.datasource)
7981
else:
8082
ds = session.get(CoreDatasource, chat.datasource) if chat.datasource else None
81-
83+
8284
if not ds:
8385
chat_info.datasource_exists = False
8486
chat_info.datasource_name = 'Datasource not exist'
@@ -87,14 +89,25 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
8789
chat_info.datasource_name = ds.name
8890
chat_info.ds_type = ds.type
8991

90-
record_list = session.query(ChatRecord).options(
91-
load_only(ChatRecord.id, ChatRecord.chat_id, ChatRecord.create_time, ChatRecord.finish_time,
92-
ChatRecord.question, ChatRecord.sql_answer, ChatRecord.sql, ChatRecord.data,
92+
stmt = select(ChatRecord.id, ChatRecord.chat_id, ChatRecord.create_time, ChatRecord.finish_time,
93+
ChatRecord.question, ChatRecord.sql_answer, ChatRecord.sql,
9394
ChatRecord.chart_answer, ChatRecord.chart, ChatRecord.analysis, ChatRecord.predict,
9495
ChatRecord.datasource_select_answer, ChatRecord.analysis_record_id, ChatRecord.predict_record_id,
9596
ChatRecord.recommended_question, ChatRecord.first_chat,
96-
ChatRecord.predict_data, ChatRecord.finish, ChatRecord.error)).filter(
97-
and_(Chat.create_by == current_user.id, ChatRecord.chat_id == chart_id)).order_by(ChatRecord.create_time).all()
97+
ChatRecord.finish, ChatRecord.error).where(
98+
and_(ChatRecord.create_by == current_user.id, ChatRecord.chat_id == chart_id)).order_by(ChatRecord.create_time)
99+
result = session.execute(stmt).all()
100+
record_list: list[ChatRecord] = []
101+
for row in result:
102+
record_list.append(
103+
ChatRecord(id=row.id, chat_id=row.chat_id, create_time=row.create_time, finish_time=row.finish_time,
104+
question=row.question, sql_answer=row.sql_answer, sql=row.sql,
105+
chart_answer=row.chart_answer, chart=row.chart,
106+
analysis=row.analysis, predict=row.predict,
107+
datasource_select_answer=row.datasource_select_answer,
108+
analysis_record_id=row.analysis_record_id, predict_record_id=row.predict_record_id,
109+
recommended_question=row.recommended_question, first_chat=row.first_chat,
110+
finish=row.finish, error=row.error))
98111

99112
result = list(map(format_record, record_list))
100113

backend/apps/chat/task/llm.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,21 @@ def check_sql(self, res: str) -> tuple[any]:
655655
if json_str is None:
656656
raise SingleMessageError(orjson.dumps({'message': 'Cannot parse sql from answer',
657657
'traceback': "Cannot parse sql from answer:\n" + res}).decode())
658-
data: dict = orjson.loads(json_str)
659-
sql = ''
660-
message = ''
661-
if data['success']:
662-
sql = data['sql']
663-
else:
664-
message = data['message']
665-
raise SingleMessageError(message)
658+
sql: str
659+
data: dict
660+
try:
661+
data = orjson.loads(json_str)
662+
663+
if data['success']:
664+
sql = data['sql']
665+
else:
666+
message = data['message']
667+
raise SingleMessageError(message)
668+
except SingleMessageError as e:
669+
raise e
670+
except Exception:
671+
raise SingleMessageError(orjson.dumps({'message': 'Cannot parse sql from answer',
672+
'traceback': "Cannot parse sql from answer:\n" + res}).decode())
666673

667674
if sql.strip() == '':
668675
raise SingleMessageError("SQL query is empty")
@@ -682,31 +689,36 @@ def check_save_chart(self, res: str) -> Dict[str, Any]:
682689
if json_str is None:
683690
raise SingleMessageError(orjson.dumps({'message': 'Cannot parse chart config from answer',
684691
'traceback': "Cannot parse chart config from answer:\n" + res}).decode())
685-
data = orjson.loads(json_str)
692+
data: dict
686693

687694
chart: Dict[str, Any] = {}
688695
message = ''
689696
error = False
690697

691-
if data['type'] and data['type'] != 'error':
692-
# todo type check
693-
chart = data
694-
if chart.get('columns'):
695-
for v in chart.get('columns'):
696-
v['value'] = v.get('value').lower()
697-
if chart.get('axis'):
698-
if chart.get('axis').get('x'):
699-
chart.get('axis').get('x')['value'] = chart.get('axis').get('x').get('value').lower()
700-
if chart.get('axis').get('y'):
701-
chart.get('axis').get('y')['value'] = chart.get('axis').get('y').get('value').lower()
702-
if chart.get('axis').get('series'):
703-
chart.get('axis').get('series')['value'] = chart.get('axis').get('series').get('value').lower()
704-
elif data['type'] == 'error':
705-
message = data['reason']
706-
error = True
707-
else:
708-
message = 'Chart is empty'
698+
try:
699+
data = orjson.loads(json_str)
700+
if data['type'] and data['type'] != 'error':
701+
# todo type check
702+
chart = data
703+
if chart.get('columns'):
704+
for v in chart.get('columns'):
705+
v['value'] = v.get('value').lower()
706+
if chart.get('axis'):
707+
if chart.get('axis').get('x'):
708+
chart.get('axis').get('x')['value'] = chart.get('axis').get('x').get('value').lower()
709+
if chart.get('axis').get('y'):
710+
chart.get('axis').get('y')['value'] = chart.get('axis').get('y').get('value').lower()
711+
if chart.get('axis').get('series'):
712+
chart.get('axis').get('series')['value'] = chart.get('axis').get('series').get('value').lower()
713+
elif data['type'] == 'error':
714+
message = data['reason']
715+
error = True
716+
else:
717+
raise Exception('Chart is empty')
718+
except Exception:
709719
error = True
720+
message = orjson.dumps({'message': 'Cannot parse chart config from answer',
721+
'traceback': "Cannot parse chart config from answer:\n" + res}).decode()
710722

711723
if error:
712724
raise SingleMessageError(message)

frontend/src/entity/supplier.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export const supplierList: Array<{
4545
{ name: 'qwen-long' },
4646
{ name: 'qwen-long-latest' },
4747
{ name: 'qwen-omni-turbo' },
48-
{ name: 'qwen-omni-turbo-realtime' },
49-
{ name: 'qwen-omni-turbo-realtime-latest' },
48+
/* { name: 'qwen-omni-turbo-realtime' },
49+
{ name: 'qwen-omni-turbo-realtime-latest' }, */
5050
{ name: 'qvq-max' },
5151
{ name: 'qvq-max-latest' },
5252
{ name: 'qvq-plus' },

0 commit comments

Comments
 (0)