A tool buildg AI docs assistans. Parsing Git repositories and markdown files. Work with vector db
Project description
AI (Documentation) Kit
AIDkit is a Python tools collection designed to help create AI documentation assistants. It includes utilities for parsing Git repositories or local directories containing Markdown files, extracting content, organizing it into structured JSON, and saving the output. These tools are particularly useful for processing documentation repositories for AI-powered assistance. aidkit
Features
- Clone remote Git repositories or work with local directories
- Extract and split Markdown content into chunks based on headers (
#,##,###) - Save parsed Markdown data in JSON format
- Index and retrieve chunks using OpenSearch
- Split large JSON files into multiple smaller files based on a grouping field
- Modular and extensible design
- Available as command-line utilities:
mdcrawlerandjsonsplitter
Installation
Make sure you are using Python 3.9 or newer and have pip installed.
pip install aidkit
Once installed, the command-line utility giga_crawler will be available.
Usage
The tool works by taking a Git repository URL (or a local directory) and outputs a JSON file containing structured data extracted from Markdown files.
Command-line Arguments
| Argument | Type | Description |
|---|---|---|
--uri |
String | URL of a remote Git repository to be cloned, or path to a local directory with Markdown files. |
--output_path |
String | Path to save the output JSON file. (Default: output.json) |
--directory |
String | Optional. Path with docs source if used remote repo with clone. |
--multy_process |
Boolean | Spawn multiple processes to speed up the process. (Default: False) |
Examples
- Clone a remote repository and parse Markdown files:
aidkit parse --uri https://github.com/example/repo.git
or
from aidkits import MarkdownCrawler
MarkdownCrawler("repo/path").work()
This will:
- Clone the repository into a temporary directory
- Parse all Markdown files in the repository
- Save the JSON output to
output.json
- Parse a local directory and save output to a custom JSON file:
aidkit parse --uri ./local_directory --output_path result.json
This will:
- Use the specified local directory
./local_directory - Parse all Markdown files in the directory
- Save the JSON output to
result.json
JSON Output Format
The JSON file saves structured data with the following format:
[
{
"title": "example.md",
"chunks": [
{
"title": "Header 1",
"content": "Content under Header 1",
"length": 120,
"chunk_num": 1,
"chunk_amount": 2
},
{
"title": "Header 2",
"content": "Content under Header 2",
"length": 240,
"chunk_num": 2,
"chunk_amount": 2
}
]
}
]
Advanced Usage
OpenSearchRetriever
The OpenSearchRetriever class provides advanced vector search capabilities using OpenSearch. It allows you to:
- Search for documents based on semantic similarity
- Create and manage collections in OpenSearch
- Upload documents and libraries to OpenSearch
Example Usage
from opensearchpy import OpenSearch
from sentence_transformers import SentenceTransformer
from aidkits.storage.opensearch_retriever import OpenSearchRetriever
from aidkits.models import LibrarySource
# Initialize the OpenSearch client
client = OpenSearch(
hosts=[{"host": "localhost", "port": 9200}],
http_auth=("admin", "admin"),
use_ssl=False,
verify_certs=False,
)
# Initialize the encoder
encoder = SentenceTransformer("all-MiniLM-L6-v2")
# Create the retriever
retriever = OpenSearchRetriever(client, encoder)
# Create a collection
retriever.create_collection("documentation")
# Upload a library
library = LibrarySource.from_json("path/to/library.json")
retriever.upload_library(library)
# Search for documents
results = retriever.search(
question="How do I use the API?",
collection_name="documentation",
top_k=5
)
# Print the results
for result in results:
print(result.markdown)
DocumentationTool
The DocumentationTool class provides a high-level interface for answering questions using documentation stored in
OpenSearch. It uses the OpenSearchRetriever to find relevant documentation and a language model to generate answers.
Example Usage
from langchain_core.language_models import ChatOpenAI
from aidkits.documentation_tool import DocumentationTool
from aidkits.storage.opensearch_retriever import OpenSearchRetriever
# Initialize the language model
llm = ChatOpenAI(model="gpt-3.5-turbo")
# Initialize the retriever (as shown above)
# ...
# Create the documentation tool
doc_tool = DocumentationTool(
llm=llm,
retriever=retriever,
collection_name="documentation",
top_k=5
)
# Answer a question
answer = doc_tool.invoke({"question": "How do I use the API?"})
print(answer)
JsonSplitter
The JsonSplitter class provides functionality for splitting a large JSON file into multiple smaller files based on a
grouping field. It can be used to organize JSON data by a common field, making it easier to work with large datasets.
Example Usage
from aidkits.json_splitter import JsonSplitter
# Create a JsonSplitter instance
splitter = JsonSplitter(output_dir="output_directory")
# Split a JSON file
grouped_data = splitter.split_json_file(
input_file="large_file.json",
group_by_field="title",
encoding="utf-8"
)
# Print information about the created files
print(f"Total files created: {len(grouped_data)}")
# You can also split JSON data directly
data = [
{"title": "Document 1", "content": "Content 1"},
{"title": "Document 2", "content": "Content 2"},
{"title": "Document 1", "content": "More content for Document 1"}
]
grouped_data = splitter.split_json_data(
data=data,
group_by_field="title"
)
# This will create two files:
# - output_directory/Document_1.json (containing 2 items)
# - output_directory/Document_2.json (containing 1 item)
Contributing
We welcome contributions! Here's how you can help:
- Fork the repository and create a branch for your feature or bug fix.
- Write clear, concise code and include comments where necessary.
- Submit a pull request with a detailed explanation of your changes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aidkits-0.2.0.tar.gz.
File metadata
- Download URL: aidkits-0.2.0.tar.gz
- Upload date:
- Size: 122.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02db5cfea3abdfff4859558859736d613864a8ffda958b0f5bfbba58811d4f8d
|
|
| MD5 |
099beaf389cecf5274fcd86ebcdaa40f
|
|
| BLAKE2b-256 |
53bc42705b7915ca20fd82e60f508e87140c1d1e59660d5b20618d757fa68155
|
Provenance
The following attestation bundles were made for aidkits-0.2.0.tar.gz:
Publisher:
python-publish.yml on aagumin/aidkits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aidkits-0.2.0.tar.gz -
Subject digest:
02db5cfea3abdfff4859558859736d613864a8ffda958b0f5bfbba58811d4f8d - Sigstore transparency entry: 216296715
- Sigstore integration time:
-
Permalink:
aagumin/aidkits@1996234b08f54b8ca730c068fe4095a0cc93c1f3 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/aagumin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1996234b08f54b8ca730c068fe4095a0cc93c1f3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aidkits-0.2.0-py3-none-any.whl.
File metadata
- Download URL: aidkits-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ccdbb15980346a96e92baa1ce3879f4c133e416ff84941e9cbc0f1ef6fd6367
|
|
| MD5 |
8476cbcaf322e39ce861d9820016e95c
|
|
| BLAKE2b-256 |
c0c646e41b3975d6335ce0db3d94c2954dce301290aeaff6a08bb20e567b77e4
|
Provenance
The following attestation bundles were made for aidkits-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on aagumin/aidkits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aidkits-0.2.0-py3-none-any.whl -
Subject digest:
3ccdbb15980346a96e92baa1ce3879f4c133e416ff84941e9cbc0f1ef6fd6367 - Sigstore transparency entry: 216296719
- Sigstore integration time:
-
Permalink:
aagumin/aidkits@1996234b08f54b8ca730c068fe4095a0cc93c1f3 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/aagumin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1996234b08f54b8ca730c068fe4095a0cc93c1f3 -
Trigger Event:
release
-
Statement type: