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
2 changes: 1 addition & 1 deletion apps/dataset/serializers/document_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def export(self, with_valid=True):
"rb")
content = file.read()
file.close()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/cxv',
return HttpResponse(content, status=200, headers={'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename="csv_template.csv"'})
elif self.data.get('type') == 'excel':
file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you've provided is essentially exporting data from an application. However, there's a small mistake in the HttpResponse header:

  1. Mistake in MIME Type:
    'Content-Type': 'text/csv'
    

This should be 'application/vnd.ms-excel' if you're exporting Excel files.

  1. Correcting the Header:

Here's the corrected version of your code:

def export(self, with_valid=True):
    if self.data.get('type') == 'csv':
        file = open(os.path.join(PROJECT_DIR, "apps", "dataset", 'template', 
                            f'template_{self.uuid}.csv'), 'rb')
        content = file.read()
        file.close()
        return HttpResponse(content, status=200, headers={
            'Content-Type': 'application/csv',
            'Content-Disposition': f'attachment; filename="template_{self.uuid}.csv"'
        })
    elif self.data.get('type') == 'excel':
        # Your existing code to handle Excel export

Optimizations Suggested:

  1. Error Handling:
    Add error handling to manage cases where the CSV/template files might not exist or cannot be read due to permissions.

  2. Data Validation:
    Ensure that the data['type'] field is validated and only allows recognized types (CSV/Excel) before proceeding with the export logic.

  3. Variable Naming:
    Consider using more descriptive variable names to improve readability.

  4. UUID Generation:
    Implement generation of unique identifiers (self.uuid) dynamically instead of hardcoding it.

These suggestions ensure robustness and maintainability of the code.

Expand Down
7 changes: 2 additions & 5 deletions apps/dataset/template/csv_template_en.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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?
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-answering 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 document upload、automatic crawling of online documents、automatic text splitting and vectorization、and good intelligent question-answering interactive experience;Seamless embedding: supports zero-coding and rapid embedding into third-party business systems;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"