Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

seofield
Copy link
Contributor

@seofield seofield commented Jan 1, 2025

[Title] TXT Loader
[Version] initial
[Language] ENG
[Package] langchain, langchain_community

LangChain TextLoader Tutorial

  • Implemented text file loading using TextLoader.
  • Demonstrated metadata extraction and content preview for individual text files.
  • Showcased automatic encoding detection and error handling with DirectoryLoader.

@suhyun0115
Copy link
Contributor

suhyun0115 commented Jan 1, 2025

[Review]

Review OS(Windows/Mac/Linux): Windows
Template Rule 가이드를 준수 하였는가(YES/NO): YES(overview 3문장 이상 권장이므로 한 문장만 추가해주시면 좋을 것 같습니다.)
Table of Contents 의 링크가 원활하게 동작하는지 확인하였는가?(YES/NO): YES
이미지가 포함되어 있다면, 이미지의 파일명이 가이드를 준수하였는가?(YES/NO): YES
import 구문이 예전 legacy 방식이 아닌 최신 버전을 따르는가?(YES/NO): YES
모든 코드가 동작에 오류 없이 동작하는가? (만약, warning 발생시 코멘트에 적어주세요): No
기타의견:

loader = TextLoader("data/appendix-keywords.txt")
부분에서 에러가 납니다.

UnicodeDecodeError Traceback (most recent call last)
File ~\AppData\Local\pypoetry\Cache\virtualenvs\langchain-opentutorial-KA-VgDpL-py3.11\Lib\site-packages\langchain_community\document_loaders\text.py:43, in TextLoader.lazy_load(self)
42 with open(self.file_path, encoding=self.encoding) as f:
---> 43 text = f.read()
44 except UnicodeDecodeError as e:

UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 147: illegal multibyte sequence

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)
Cell In[3], line 7
4 loader = TextLoader("data/appendix-keywords.txt")
6 # Load the document
----> 7 docs = loader.load()
8 print(f"Number of documents: {len(docs)}\n")
9 print("[Metadata]\n")

File ~\AppData\Local\pypoetry\Cache\virtualenvs\langchain-opentutorial-KA-VgDpL-py3.11\Lib\site-packages\langchain_core\document_loaders\base.py:31, in BaseLoader.load(self)
29 def load(self) -> list[Document]:
30 """Load data into Document objects."""
---> 31 return list(self.lazy_load())

File ~\AppData\Local\pypoetry\Cache\virtualenvs\langchain-opentutorial-KA-VgDpL-py3.11\Lib\site-packages\langchain_community\document_loaders\text.py:56, in TextLoader.lazy_load(self)
54 continue
55 else:
---> 56 raise RuntimeError(f"Error loading {self.file_path}") from e
57 except Exception as e:
58 raise RuntimeError(f"Error loading {self.file_path}") from e

RuntimeError: Error loading data/appendix-keywords.txt

loader = TextLoader("data/appendix-keywords.txt", encoding="utf-8")
로 수정하시면 될 것 같습니다.
그 외에는 모두 잘 작동합니다! 고생하셨습니다. 새해 복 많이 받으세요!

Copy link
Contributor

@HarryKane11 HarryKane11 left a comment

Choose a reason for hiding this comment

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

[Review]

Review OS(Windows/Mac/Linux): Windows
Template Rule 가이드를 준수 하였는가(YES/NO): YES
Table of Contents 의 링크가 원활하게 동작하는지 확인하였는가?(YES/NO): NO
이미지가 포함되어 있다면, 이미지의 파일명이 가이드를 준수하였는가?(YES/NO): YES
import 구문이 예전 legacy 방식이 아닌 최신 버전을 따르는가?(YES/NO): YES
모든 코드가 동작에 오류 없이 동작하는가? (만약, warning 발생시 코멘트에 적어주세요): No

기타의견:

  1. Table of Content 링크에서 Text Loader 링크가 상위 섹션 앵커로 적용된 것 같습니다. 하위 섹션과 다른 이름으로 하시면 될 것 같아요!
  2. 수현님과 똑같이 로컬에서 코드 실행했을 때, 첫번쨰 코드 셀이 오류가 나네요
    encoding='utf-8' 을 추가했을 때 오류가 안나더라구요.
    밑 셀에서 auto-detecting하는 로직을 더하셨기 때문에 첫 셀이 오류가 나도록 의도하신거라면 approve하겠습니다!
    image

Copy link
Contributor

@HarryKane11 HarryKane11 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~

Copy link
Contributor

@suhyun0115 suhyun0115 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!!

@BAEM1N BAEM1N merged commit d5fef8d into LangChain-OpenTutorial:main Jan 2, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants