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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitLoader #2851

Merged
merged 5 commits into from Apr 14, 2023
Merged

Add GitLoader #2851

merged 5 commits into from Apr 14, 2023

Conversation

ecneladis
Copy link
Contributor

No description provided.

Comment on lines 66 to 72
def is_text_content(content: bytes) -> bool:
"""Determines if the content is text based on the content bytes."""
try:
content.decode("utf-8")
return True
except UnicodeDecodeError:
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe return the content.decode("utf-8") so that we don't have to decode twice

Copy link
Contributor Author

@ecneladis ecneladis Apr 13, 2023

Choose a reason for hiding this comment

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

fixed in 3a16d35


def load(self) -> List[Document]:
try:
from git import Blob, Repo
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add this to the deps file instead of this try/catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This common pattern in this project, what makes sense given number of dependencies that are not required for every use case.

@cktang88
Copy link
Contributor

Can you time how long it takes for large repos like https://github.com/openjdk/jdk ? (67k files)

Comment on lines 34 to 35
repo = Repo(self.path)
repo.git.checkout(self.branch)
Copy link
Contributor

@cktang88 cktang88 Apr 13, 2023

Choose a reason for hiding this comment

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

We should check if the repo exists already, if it does, we should do git pull instead of git clone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in f43370d

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two alternative ways to load repo:

loader = GitLoader(
    clone_url="https://github.com/hwchase17/langchain",
    repo_path="./example_data/test_repo2/",
    branch="master",
)
loader = GitLoader(repo_path="./example_data/test_repo1/", branch=branch)

Copy link

Choose a reason for hiding this comment

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

We should check if the repo exists already, if it does, we should do git pull instead of git checkout.

do we actually want the loader forcing a pull by default instead of using what's on disk? I don't think I would want the loader to cause a local repo to update from a remote unless I explicitly stated to

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agreed, I like having loading from local repo to be default without updating.

@ecneladis
Copy link
Contributor Author

Can you time how long it takes for large repos like https://github.com/openjdk/jdk ? (67k files)

~6 seconds on Apple M1 Max

image

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

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

this is awesome - thanks!

@hwchase17 hwchase17 merged commit 016738e into langchain-ai:master Apr 14, 2023
9 checks passed
hwchase17 pushed a commit that referenced this pull request Apr 14, 2023
Supplemental to #2851.
Updates one notebook cell that I forgot to commit before.
@ecneladis ecneladis deleted the git_loader branch April 14, 2023 06:53
hwchase17 pushed a commit that referenced this pull request Apr 14, 2023
Allows users to specify what files should be loaded instead of
indiscriminately loading the entire repo.

extends #2851 

NOTE: for reviewers, `hide whitespace` option recommended since I
changed the indentation of an if-block to use `continue` instead so it
looks less like a Christmas tree :)
dev2049 pushed a commit that referenced this pull request Apr 14, 2023
wertycn pushed a commit to wertycn/langchain-zh that referenced this pull request Apr 26, 2023
Supplemental to langchain-ai/langchain#2851.
Updates one notebook cell that I forgot to commit before.
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
Supplemental to langchain-ai#2851.
Updates one notebook cell that I forgot to commit before.
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
Allows users to specify what files should be loaded instead of
indiscriminately loading the entire repo.

extends langchain-ai#2851 

NOTE: for reviewers, `hide whitespace` option recommended since I
changed the indentation of an if-block to use `continue` instead so it
looks less like a Christmas tree :)
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
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.

None yet

4 participants