langchain/tests/unit_tests/document_loaders
Cristóbal Carnero Liñán e494b0a09f
feat (documents): add a source code loader based on AST manipulation (#6486)
#### Summary

A new approach to loading source code is implemented:

Each top-level function and class in the code is loaded into separate
documents. Then, an additional document is created with the top-level
code, but without the already loaded functions and classes.

This could improve the accuracy of QA chains over source code.

For instance, having this script:

```
class MyClass:
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f"Hello, {self.name}!")

def main():
    name = input("Enter your name: ")
    obj = MyClass(name)
    obj.greet()

if __name__ == '__main__':
    main()
```

The loader will create three documents with this content:

First document:
```
class MyClass:
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f"Hello, {self.name}!")
```

Second document:
```
def main():
    name = input("Enter your name: ")
    obj = MyClass(name)
    obj.greet()
```

Third document:
```
# Code for: class MyClass:

# Code for: def main():

if __name__ == '__main__':
    main()
```

A threshold parameter is added to control whether small scripts are
split in this way or not.

At this moment, only Python and JavaScript are supported. The
appropriate parser is determined by examining the file extension.

#### Tests

This PR adds:

- Unit tests
- Integration tests

#### Dependencies

Only one dependency was added as optional (needed for the JavaScript
parser).

#### Documentation

A notebook is added showing how the loader can be used.

#### Who can review?

@eyurtsev @hwchase17

---------

Co-authored-by: rlm <pexpresss31@gmail.com>
2023-06-27 15:58:47 -07:00
..
blob_loaders YoutubeAudioLoader and updates to OpenAIWhisperParser (#5772) 2023-06-06 15:15:08 -07:00
loaders fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
parsers feat (documents): add a source code loader based on AST manipulation (#6486) 2023-06-27 15:58:47 -07:00
sample_documents Bibtex integration for document loader and retriever (#5137) 2023-05-25 00:21:31 -07:00
test_docs Allow readthedoc loader to pass custom html tag (#5175) 2023-05-24 10:40:27 -07:00
__init__.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_base.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_bibtex.py Bibtex integration for document loader and retriever (#5137) 2023-05-25 00:21:31 -07:00
test_bshtml.py Add html parsers (#4874) 2023-05-17 22:39:11 -04:00
test_confluence.py Add Confluence Loader unit tests (#3333) 2023-05-16 15:17:07 -07:00
test_csv_loader.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_detect_encoding.py feat #4479: TextLoader auto detect encoding and improved exceptions (#4927) 2023-05-18 09:55:14 -04:00
test_directory.py Add path validation to DirectoryLoader (#5327) 2023-05-28 15:31:23 -04:00
test_evernote_loader.py feature/4493 Improve Evernote Document Loader (#4577) 2023-05-19 14:28:17 -07:00
test_generic_loader.py Add a generic document loader (#4875) 2023-05-17 22:38:55 -04:00
test_github.py DocumentLoader for GitHub (#5408) 2023-05-29 20:11:21 -07:00
test_json_loader.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_mhtml.py Added a MHTML document loader (#6311) 2023-06-25 13:12:08 -07:00
test_psychic.py Harrison/psychic (#5063) 2023-05-21 09:13:20 -07:00
test_readthedoc.py Allow readthedoc loader to pass custom html tag (#5175) 2023-05-24 10:40:27 -07:00
test_telegram.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_trello.py New Trello document loader (#4767) 2023-05-29 19:47:56 -07:00
test_web_base.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00
test_youtube.py fix(document_loaders/telegram): fix pandas calls + add tests (#4806) 2023-05-16 14:35:25 -07:00