Skip to content

Commit

Permalink
fix: Download template error
Browse files Browse the repository at this point in the history
--bug=1051908 --user=王孝刚 【知识库】导出的文档打开后里面为错误日志,无文档内容,导出的压缩包不能解压 https://www.tapd.cn/57709429/s/1650087
  • Loading branch information
wxg0103 committed Jan 23, 2025
1 parent 5ebcad7 commit c1dd4ad
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 8 deletions.
19 changes: 11 additions & 8 deletions apps/dataset/serializers/document_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from django.db.models import QuerySet, Count
from django.db.models.functions import Substr, Reverse
from django.http import HttpResponse
from django.utils.translation import gettext_lazy as _, gettext
from drf_yasg import openapi
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
from rest_framework import serializers
Expand Down Expand Up @@ -65,6 +64,8 @@
embedding_by_document_list
from setting.models import Model
from smartdoc.conf import PROJECT_DIR
from django.utils.translation import gettext_lazy as _, gettext, to_locale
from django.utils.translation import get_language

parse_qa_handle_list = [XlsParseQAHandle(), CsvParseQAHandle(), XlsxParseQAHandle(), ZipParseQAHandle()]
parse_table_handle_list = [CsvSplitTableHandle(), XlsSplitTableHandle(), XlsxSplitTableHandle()]
Expand Down Expand Up @@ -240,15 +241,15 @@ def get_request_params_api():
def export(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)

language = get_language()
if self.data.get('type') == 'csv':
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', 'csv_template.csv'), "rb")
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', f'csv_template_{to_locale(language)}.csv'), "rb")
content = file.read()
file.close()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/cxv',
'Content-Disposition': 'attachment; filename="csv_template.csv"'})
elif self.data.get('type') == 'excel':
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', 'excel_template.xlsx'), "rb")
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', f'csv_template_{to_locale(language)}.xlsx'), "rb")
content = file.read()
file.close()
return HttpResponse(content, status=200, headers={'Content-Type': 'application/vnd.ms-excel',
Expand All @@ -257,16 +258,18 @@ def export(self, with_valid=True):
def table_export(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)

language = get_language()
if self.data.get('type') == 'csv':
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', _('MaxKB table template.csv')),
"rb")
file = open(
os.path.join(PROJECT_DIR, "apps", "dataset", 'template', f'table_template_{to_locale(language)}.csv'),
"rb")
content = file.read()
file.close()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/cxv',
'Content-Disposition': 'attachment; filename="csv_template.csv"'})
elif self.data.get('type') == 'excel':
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', _('MaxKB table template.xlsx')),
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template',
f'table_template_{to_locale(language)}.xlsx'),
"rb")
content = file.read()
file.close()
Expand Down
8 changes: 8 additions & 0 deletions apps/dataset/template/csv_template_en.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Section title (optional), section content (required, question answer, no more than 4096 characters)), question (optional, one per line in the cell)
MaxKB product introduction, "MaxKB is a knowledge base question and answer system based on the LLM large language model. MaxKB = Max Knowledge Base aims to become the most powerful brain of the enterprise.
Out-of-the-box: supports direct uploading of documents, automatic crawling of online documents, automatic text splitting and vectorization, and a good intelligent Q&A interactive experience;
Seamless embedding: supports rapid embedding into third-party business systems with zero coding;
Multi-model support: Supports docking with mainstream large models, including Ollama local private large models (such as Llama 2, Llama 3, qwen), Tongyi Qianwen, OpenAI, Azure OpenAI, Kimi, Zhipu AI, iFlytek Spark and Baidu Qianfan Large models etc. ","What is MaxKB?
MaxKB product introduction
Large language model supported by MaxKB
MaxKB advantages"
File renamed without changes.
8 changes: 8 additions & 0 deletions apps/dataset/template/csv_template_zh_Hant.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
分段標題(選填),分段內容(必填,問題答案,最長不超過4096個字元)),問題(選填,單元格內一行一個)
MaxKB產品介紹,"MaxKB 是一款基於 LLM 大語言模型的知識庫問答系統。MaxKB = Max Knowledge Base,旨在成為企業的最強大大腦。
開箱即用:支援直接上傳文檔、自動爬取線上文檔,支援文字自動分割、向量化,智慧問答互動體驗好;
無縫嵌入:支援零編碼快速嵌入到第三方業務系統;
多模型支援:支持對接主流的大模型,包括Ollama 本地私有大模型(如Llama 2、Llama 3、qwen)、通義千問、OpenAI、Azure OpenAI、Kimi、智譜AI、訊飛星火和百度千帆大模型等。 ","MaxKB是什麼?
MaxKB產品介紹
MaxKB支援的大語言模型
MaxKB優勢"
Binary file added apps/dataset/template/excel_template_en.xlsx
Binary file not shown.
File renamed without changes.
Binary file added apps/dataset/template/excel_template_zh_Hant.xlsx
Binary file not shown.
13 changes: 13 additions & 0 deletions apps/dataset/template/table_template_en.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Position, reimbursement type, first-tier city reimbursement standard (yuan), second-tier city reimbursement standard (yuan), third-tier city reimbursement standard (yuan)
Ordinary employees, accommodation expenses, 500, 400, 300
Department head, accommodation fee, 600, 500, 400
Department director, accommodation fee, 700, 600, 500
Regional general manager, accommodation fee, 800, 700, 600
Ordinary employees, food expenses, 50, 40, 30
Department head, food expenses, 50, 40, 30
Department director, food expenses, 50, 40, 30
Regional general manager, food expenses, 50, 40, 30
Ordinary employees, transportation expenses, 50, 40, 30
Department head, transportation expenses, 50, 40, 30
Department director, transportation expenses, 50, 40, 30
Regional general manager, transportation expenses, 50, 40, 30
Binary file added apps/dataset/template/table_template_en.xlsx
Binary file not shown.
File renamed without changes.
13 changes: 13 additions & 0 deletions apps/dataset/template/table_template_zh_Hant.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
職務,報銷類型,一線城市報銷標準(元),二線城市報銷標準(元),三線城市報銷標準(元)
普通員工,住宿費,500,400,300
部門主管,住宿費,600,500,400
部門總監,住宿費,700,600,500
區域總經理,住宿費,800,700,600
普通員工,伙食費,50,40,30
部門主管,伙食費,50,40,30
部門總監,伙食費,50,40,30
區域總經理,伙食費,50,40,30
普通員工,交通費,50,40,30
部門主管,交通費,50,40,30
部門總監,交通費,50,40,30
區域總經理,交通費,50,40,30
Binary file added apps/dataset/template/table_template_zh_Hant.xlsx
Binary file not shown.

0 comments on commit c1dd4ad

Please sign in to comment.