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

JSON loader #4067

Merged
merged 16 commits into from
May 5, 2023
Merged

JSON loader #4067

merged 16 commits into from
May 5, 2023

Conversation

avsolatorio
Copy link
Contributor

This implements a loader of text passages in JSON format. The jq syntax is used to define a schema for accessing the relevant contents from the JSON file. This requires dependency on the jq package: https://pypi.org/project/jq/.

Copy link
Contributor

@dev2049 dev2049 left a comment

Choose a reason for hiding this comment

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

nice, thanks @avsolatorio for adding! could we add a brief demo notebook (see docs/modules/indexes/document_loaders/examples) and integration test (tests/integration_tests/document_loaders)?


for i, text in enumerate(body_text, 1):
metadata = dict(
source=self.file_path.as_posix(),
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's as posix, how would that impact systems running on Windows? Any reason to choose that vs. str(self.file_path)?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vowelparrot good point! Will update the PR. Thanks!

Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
@avsolatorio
Copy link
Contributor Author

nice, thanks @avsolatorio for adding! could we add a brief demo notebook (see docs/modules/indexes/document_loaders/examples) and integration test (tests/integration_tests/document_loaders)?

Hi, @dev2049 , I have added these in the current version of the PR.

I also implemented a few functionalities allowing the user a more expressive and explicit way to add metadata from the JSON file.

Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
# and prevent the user from getting a cryptic error later on.
if self._content_key is not None:
sample = data.first()
assert isinstance(sample, dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit-picky point, but convention in package so far has been to more explicitly validate and raise errors (usually ValueErrors). so something like

if not isinstance(sample, dict):
  raise ValueError(f'expected foo bar but received baz: {sample}')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL. Updated!

Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
Copy link
Contributor

@dev2049 dev2049 left a comment

Choose a reason for hiding this comment

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

one nit but otherwise lgtm, thanks @avsolatorio!!

import jq # noqa:F401
except ImportError:
raise ValueError(
"jq package not found, please install it with " "`pipenv install jq`"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: combine strings and would just do pip (instead of pipenv, which is bit less universal)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right! I also had to fix some linting issues so I just included this change in the latest commit. Thanks!

Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
@dev2049 dev2049 merged commit 6567b73 into langchain-ai:master May 5, 2023
9 checks passed
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