Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure UTF-8 encoding when reading text files in ingestion helper #2144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akshayjalluri6
Copy link

@akshayjalluri6 akshayjalluri6 commented Jan 23, 2025

Description

This PR ensures that text files are read using UTF-8 encoding in the _load_file_to_documents method of the ingestion helper. Previously, the encoding was not explicitly specified, which could lead to issues when handling files with non-UTF-8 encodings.

Motivation:

  • Explicitly specifying UTF-8 encoding improves the robustness of file ingestion, ensuring consistent behavior across various environments and file types.
  • Prevents potential errors when handling text files with special characters or encodings that default to non-UTF-8.
  • This way PrivateGPT can process any language files.

Relevant Context:

  • This change affects how files are read when no specific file reader is found for a given file extension.
  • No dependencies were introduced for this change.

Type of Change

  • ✅ Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Code Inspection:

    • Verified that the change explicitly specifies UTF-8 encoding in the read_text method.
    • Ensured the updated method still adheres to the expected behavior for all file types.
  2. Unit Testing:

    • Ran existing unit tests to confirm no regressions were introduced.
    • Verified that files with UTF-8 encoding and special characters are read correctly without errors.
  3. Manual Testing:

    • Tested the ingestion of text files containing special characters (e.g., emojis, non-ASCII text) to confirm proper handling.
    • Confirmed no issues when processing files of other formats or extensions.

Test Configuration:

  • OS: Windows-11
  • Python Version: 3.11.9

Checklist

  • ✅ My code follows the style guidelines of this project.
  • ✅ I have performed a self-review of my code.
  • ✅ I have commented my code, particularly in hard-to-understand areas.
  • ✅ My changes generate no new warnings.
  • ✅ I have added tests that prove my fix is effective or that my feature works.
  • ✅ New and existing unit tests pass locally with my changes.
  • ✅ I ran make check; make test to ensure mypy and tests pass.

This structure clearly outlines the change, why it was made, and how it was tested. Let me know if you need further adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant