Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions backend/apps/chat/api/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
delete_chat, get_chat_chart_data, get_chat_predict_data, get_chat_with_records_with_data, get_chat_record_by_id
from apps.chat.models.chat_model import CreateChat, ChatRecord, RenameChat, ChatQuestion, ExcelData
from apps.chat.task.llm import LLMService
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser, Trans

router = APIRouter(tags=["Data Q&A"], prefix="/chat")

Expand Down Expand Up @@ -106,7 +106,7 @@ async def start_chat(session: SessionDep, current_user: CurrentUser):
async def recommend_questions(session: SessionDep, current_user: CurrentUser, chat_record_id: int,
current_assistant: CurrentAssistant):
def _return_empty():
yield 'data:' + orjson.dumps( {'content': '[]', 'type': 'recommended_question'}).decode() + '\n\n'
yield 'data:' + orjson.dumps({'content': '[]', 'type': 'recommended_question'}).decode() + '\n\n'

try:
record = get_chat_record_by_id(session, chat_record_id)
Expand Down Expand Up @@ -201,10 +201,16 @@ def _err(_e: Exception):


@router.post("/excel/export")
async def export_excel(excel_data: ExcelData):
async def export_excel(excel_data: ExcelData, trans: Trans):
def inner():
_fields_list = []
data = []
if not excel_data.data:
raise HTTPException(
status_code=500,
detail=trans("i18n_excel_export.data_is_empty")
)

for _data in excel_data.data:
_row = []
for field in excel_data.axis:
Expand Down
3 changes: 3 additions & 0 deletions backend/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"datasource_cannot_be_none": "Datasource cannot be none",
"data_training_not_exists": "Example does not exists",
"exists_in_db": "Question exists"
},
"i18n_excel_export": {
"data_is_empty": "The form data is empty, cannot export data"
}
}
3 changes: 3 additions & 0 deletions backend/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"datasource_cannot_be_none": "数据源不能为空",
"data_training_not_exists": "该示例不存在",
"exists_in_db": "该问题已存在"
},
"i18n_excel_export": {
"data_is_empty": "表单数据为空,无法导出数据"
}
}
6 changes: 5 additions & 1 deletion frontend/src/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,9 @@ export const chatApi = {
return request.fetchStream(`/chat/recommend_questions/${record_id}`, {}, controller)
},
checkLLMModel: () => request.get('/system/aimodel/default', { requestOptions: { silent: true } }),
export2Excel: (data: any) => request.post('/chat/excel/export', data, { responseType: 'blob' }),
export2Excel: (data: any) =>
request.post('/chat/excel/export', data, {
responseType: 'blob',
requestOptions: { customError: true },
}),
}
25 changes: 25 additions & 0 deletions frontend/src/views/chat/chat-block/ChartBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,31 @@ function exportToExcel() {
link.click()
document.body.removeChild(link)
})
.catch(async (error) => {
if (error.response) {
try {
let text = await error.response.data.text()
try {
text = JSON.parse(text)
} finally {
ElMessage({
message: text,
type: 'error',
showClose: true,
})
}
} catch (e) {
console.error('Error processing error response:', e)
}
} else {
console.error('Other error:', error)
ElMessage({
message: error,
type: 'error',
showClose: true,
})
}
})
.finally(() => {
loading.value = false
})
Expand Down