Skip to main content

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: mdcrawler and jsonsplitter

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

  1. 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
  1. 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:

  1. Fork the repository and create a branch for your feature or bug fix.
  2. Write clear, concise code and include comments where necessary.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aidkits-0.2.0.tar.gz (122.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aidkits-0.2.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

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

Hashes for aidkits-0.2.0.tar.gz
Algorithm Hash digest
SHA256 02db5cfea3abdfff4859558859736d613864a8ffda958b0f5bfbba58811d4f8d
MD5 099beaf389cecf5274fcd86ebcdaa40f
BLAKE2b-256 53bc42705b7915ca20fd82e60f508e87140c1d1e59660d5b20618d757fa68155

See more details on using hashes here.

Provenance

The following attestation bundles were made for aidkits-0.2.0.tar.gz:

Publisher: python-publish.yml on aagumin/aidkits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for aidkits-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ccdbb15980346a96e92baa1ce3879f4c133e416ff84941e9cbc0f1ef6fd6367
MD5 8476cbcaf322e39ce861d9820016e95c
BLAKE2b-256 c0c646e41b3975d6335ce0db3d94c2954dce301290aeaff6a08bb20e567b77e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for aidkits-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on aagumin/aidkits

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page