Skip to content

Commit

Permalink
Added API documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
souradipp76 committed Nov 24, 2024
1 parent 020df2e commit 60b372c
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 136 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/deploy_mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
Expand Down Expand Up @@ -40,4 +46,4 @@ jobs:
# Build the MkDocs site
- name: Build and Publish MkDocs site
run: mkdocs gh-deploy
run: mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Changelog
=========


(unreleased)
Release Version 1.1.3
------------
- Updated Makefile. [Souradip Pal]
- Fixed device settings. [Souradip Pal]
Expand Down
18 changes: 18 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,21 @@ query.generate_readme(repo_config, user_config, readme_config)
```

Run the sample script in the `examples/example.py` to see a typical code usage.

## Contributing

ReadmeReady is an open-source project that is supported by a community who will gratefully and humbly accept any contributions you might make to the project.

If you are interested in contributing, read the [CONTRIBUTING.md](https://github.com/souradipp76/ReadMeReady/blob/main/CONTRIBUTING.md) file.

- Submit a bug report or feature request on [GitHub Issues](https://github.com/souradipp76/ReadMeReady/issues).
- Add to the documentation or help with our website.
- Write unit or integration tests for our project under the `tests` directory.
- Answer questions on our issues, mailing list, Stack Overflow, and elsewhere.
- Write a blog post, tweet, or share our project with others.

As you can see, there are lots of ways to get involved, and we would be very happy for you to join us!

## License

Read the [LICENSE](https://github.com/souradipp76/ReadMeReady/blob/main/LICENSE) file.
28 changes: 18 additions & 10 deletions docs/reference.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
# API Reference

::: readme_ready.index.index
- ::: readme_ready.index.index
handler: python
options:
members:
- index
show_root_heading: true
show_source: false
separate_signature: true

::: readme_ready.index.create_vector_store
- ::: readme_ready.index.convert_json_to_markdown
handler: python
options:
show_root_heading: true
show_source: false
separate_signature: true

- ::: readme_ready.index.create_vector_store
handler: python
options:
members:
- create_vector_store
show_root_heading: true
show_source: false
separate_signature: true

::: readme_ready.index.process_repository
- ::: readme_ready.index.process_repository
handler: python
options:
members:
- process_repository
show_root_heading: true
show_source: false
separate_signature: true

::: readme_ready.query.query
- ::: readme_ready.query.query
handler: python
options:
members:
- query
- generate_readme
show_root_heading: true
show_source: false
separate_signature: true

::: readme_ready.query.create_chat_chain
- ::: readme_ready.query.create_chat_chain
handler: python
options:
members:
- make_qa_chain
- make_readme_chain
show_root_heading: true
show_source: false
show_source: false
separate_signature: true
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ site_name: ReadmeReady
theme: readthedocs
plugins:
- search
- autorefs
- mkdocstrings
15 changes: 13 additions & 2 deletions readme_ready/index/convert_json_to_markdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Convert Json to Markdown
Utility to Convert Summary JSON to Markdown
"""

import json
Expand All @@ -17,7 +17,18 @@


def convert_json_to_markdown(config: AutodocRepoConfig):
"""Convert Json to Markdown"""
"""
Convert JSON summary to Markdown documents
Traverses the root directory, finds the summary JSON for each file
and directory and converts them into Markdown format.
Args:
config: An AutodocRepoConfig instance containing configuration
settings for indexing, including output paths, repository
details, and processing options.
"""
project_name = config.name
input_root = Path(config.root)
output_root = Path(config.output)
Expand Down
66 changes: 48 additions & 18 deletions readme_ready/index/create_vector_store.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Create Vector Store
Utilities to Create Vector Store
"""

import fnmatch
Expand All @@ -19,9 +19,21 @@ def should_ignore(file_name: str, ignore: List[str]):
return any(fnmatch.fnmatch(file_name, pattern) for pattern in ignore)


def process_file(file_path: str, ignore: List[str]):
def process_file(file_path: str, ignore: List[str]) -> Document | None:
"""
Process File
Processes a file
Processes a specified file and converts the content
of the file into Document format. Ignores any file matching
the patterns provided in the ignore list.
Args:
file_path: The file to be processed.
ignore: A list of file patterns to ignore during processing.
Returns:
doc: A Document with file contents and metatdata
"""

def read_file(path):
Expand All @@ -45,7 +57,20 @@ def process_directory(
directory_path: str, ignore: List[str]
) -> List[Document]:
"""
Process Directory
Processes a directory
Processes a specified directory, and converts all the content
of the files in the directory into Document format. Ignores
files matching the patterns provided in the ignore list.
Args:
directory_path: The root directory containing the files to be
processed.
ignore: A list of file patterns to ignore during processing.
Returns:
docs: List of Documents with file contents and metatdata
"""
docs = []
try:
Expand Down Expand Up @@ -73,7 +98,16 @@ def process_directory(

class RepoLoader(BaseLoader):
"""
RepoLoader
Class to load and process a repository
A loader class which loads and processes a repsitory given
the root directory path and list of file patterns to ignore.
Typical usage example:
loader = RepoLoader(path, ignore)
docs = loader.load()
"""

def __init__(self, file_path: str, ignore: List[str]):
Expand All @@ -93,27 +127,23 @@ def create_vector_store(
device: str,
) -> None:
"""
Creates a vector store from Markdown documents.
Loads documents from the specified root directory, splits the text into chunks,
creates a vector store using the selected LLM model, and saves the vector store
to the output path. Ignores files matching the patterns provided in the ignore list.
Creates a vector store from Markdown documents
Loads documents from the specified root directory, splits the text into
chunks, creates a vector store using the selected LLM, and saves the
vector store to the output path. Ignores files matching the patterns
provided in the ignore list.
Args:
root: The root directory containing the documents to be processed.
output: The directory where the vector store will be saved.
ignore: A list of file patterns to ignore during document loading.
llms: A list of LLMModels to use for generating embeddings.
device: The device to use for embedding generation (e.g., 'cpu' or 'cuda').
device: The device to use for embedding generation
(e.g., 'cpu' or 'auto').
Returns:
None.
Raises:
IOError: If an error occurs accessing the filesystem.
Exception: If an error occurs during document loading, splitting, or vector store creation.
"""

llm = llms[1] if len(llms) > 1 else llms[0]
loader = RepoLoader(root, ignore)
raw_docs = loader.load()
Expand Down
17 changes: 8 additions & 9 deletions readme_ready/index/index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Index
Utility to Index a Repository and store them into a Vector Store
"""

from pathlib import Path
Expand All @@ -13,18 +13,17 @@

def index(config: AutodocRepoConfig) -> None:
"""
Indexes a repository to generate documentation and vector store files.
Indexes a repository to generate documentation and vector store files
Processes the repository specified in the config to create JSON files, converts them to Markdown format,
and builds a vector store from the Markdown documents. Creates the necessary directories for JSON,
Processes the repository specified in the config to create JSON files,
converts them to Markdown format, and builds a vector store from the
Markdown documents. Creates the necessary directories for JSON,
Markdown, and data outputs as specified in the configuration.
Args:
config: An AutodocRepoConfig instance containing configuration settings for indexing, including
output paths, repository details, and processing options.
Returns:
None.
config: An AutodocRepoConfig instance containing configuration
settings for indexing, including output paths, repository
details, and processing options.
"""
json_path = Path(config.output) / "docs" / "json"
Expand Down
33 changes: 14 additions & 19 deletions readme_ready/index/process_repository.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Process Repository
Utilities to Process Repository and Summarize File Contents
"""

import hashlib
Expand Down Expand Up @@ -34,29 +34,24 @@
from .select_model import select_model


def process_repository(config: AutodocRepoConfig, dry_run=False) -> None:
def process_repository(
config: AutodocRepoConfig, dry_run: bool = False
) -> None:
"""
Creates a vector store from Markdown documents.
Process a repository to generate JSON summary using LLMs
Loads documents from the specified root directory, splits the text into chunks,
creates a vector store using the selected LLM model, and saves the vector store
to the output path. Ignores files matching the patterns provided in the ignore list.
Traverses through the repository and summarizes the contents of
each file and directory using an LLM via. a summarization prompt and
saves them into JSON files.
Args:
root: The root directory containing the documents to be processed.
output: The directory where the vector store will be saved.
ignore: A list of file patterns to ignore during document loading.
llms: A list of LLMModels to use for generating embeddings.
device: The device to use for embedding generation (e.g., 'cpu' or 'cuda').
Returns:
None.
Raises:
IOError: If an error occurs accessing the filesystem.
Exception: If an error occurs during document loading, splitting, or vector store creation.
"""
config: An AutodocRepoConfig instance containing configuration
settings for indexing, including output paths, repository
details, and processing options.
dry_run: Flag to enable dry run mode where the process runs over the
directory without actual indexing the documents
"""

def read_file(path):
with open(path, "r", encoding="utf-8") as file:
Expand Down
Loading

0 comments on commit 60b372c

Please sign in to comment.