-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Ragbits CLI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[project] | ||
name = "ragbits-cli" | ||
version = "0.1.0" | ||
description = "A CLI application for ragbits - building blocks for rapid development of GenAI applications" | ||
readme = "README.md" | ||
requires-python = ">=3.10" | ||
license = "MIT" | ||
authors = [ | ||
{ name = "deepsense.ai", email = "[email protected]"} | ||
] | ||
keywords = [ | ||
"Retrieval Augmented Generation", | ||
"RAG", | ||
"Large Language Models", | ||
"LLMs", | ||
"Generative AI", | ||
"GenAI", | ||
"Prompt Management" | ||
] | ||
classifiers = [ | ||
"Development Status :: 1 - Planning", | ||
"Environment :: Console", | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: MIT License", | ||
"Natural Language :: English", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
"Private :: Do Not Upload" | ||
] | ||
dependencies = [ | ||
"typer>=0.12.5", | ||
] | ||
|
||
[project.scripts] | ||
ragbits = "ragbits.cli:main" | ||
rbts = "ragbits.cli:main" | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/ragbits"] | ||
|
||
[tool.pytest.ini_options] | ||
asyncio_mode = "auto" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import importlib.util | ||
import pkgutil | ||
|
||
from typer import Typer | ||
|
||
import ragbits | ||
|
||
app = Typer() | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Main entry point for the CLI. | ||
This function registers all the CLI modules in the ragbits packages: | ||
- iterates over every package in the ragbits.* namespace | ||
- it looks for `cli` package / module | ||
- if found it imports the `register` function from the `cli` module and calls it with the `app` object | ||
- register function should add the CLI commands to the `app` object | ||
""" | ||
|
||
cli_enabled_modules = [ | ||
module | ||
for module in pkgutil.iter_modules(ragbits.__path__) | ||
if module.ispkg and module.name != "cli" and importlib.util.find_spec(f"ragbits.{module.name}.cli") | ||
] | ||
for module in cli_enabled_modules: | ||
register_func = importlib.import_module(f"ragbits.{module.name}.cli").register | ||
register_func(app) | ||
|
||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typer import Typer | ||
|
||
prompts_app = Typer() | ||
|
||
|
||
@prompts_app.command() | ||
def placeholder() -> None: | ||
"""Placeholder command""" | ||
print("foo") | ||
|
||
|
||
def register(app: Typer) -> None: | ||
""" | ||
Register the CLI commands for the ragbits-core package. | ||
Args: | ||
app: The Typer object to register the commands with. | ||
""" | ||
app.add_typer(prompts_app, name="prompts") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# /// script | ||
# requires-python = ">=3.10" | ||
# dependencies = [ | ||
# "tomlkit", | ||
# "inquirer", | ||
# ] | ||
# /// | ||
# To run this script and create a new package, run the following command: | ||
# | ||
# uv run scripts/create_ragbits_package.py | ||
# | ||
|
||
from pathlib import Path | ||
|
||
import tomlkit | ||
from inquirer.shortcuts import text | ||
|
||
PACKAGES_DIR = Path(__file__).parent.parent / "packages" | ||
|
||
|
||
def run() -> None: | ||
""" | ||
Create a new Ragbits package. | ||
""" | ||
package_name: str = text("Enter the package name", default="ragbits-") | ||
|
||
package_dir = PACKAGES_DIR / package_name | ||
|
||
if package_dir.exists(): | ||
print(f"Package {package_name} already exists at {package_dir}") | ||
return | ||
|
||
package_dir.mkdir(exist_ok=True, parents=True) | ||
|
||
src_dir = package_dir / "src" / "ragbits" / package_name.removeprefix("ragbits-").replace("-", "_") | ||
src_dir.mkdir(exist_ok=True, parents=True) | ||
(src_dir / "__init__.py").touch() | ||
|
||
examples_dir = package_dir / "examples" | ||
examples_dir.mkdir(exist_ok=True) | ||
|
||
tests_dir = package_dir / "tests" | ||
tests_dir.mkdir(exist_ok=True) | ||
|
||
pkg_pyproject = tomlkit.parse((PACKAGES_DIR / "ragbits-core" / "pyproject.toml").read_text()) | ||
|
||
pkg_pyproject["project"]["name"] = package_name | ||
pkg_pyproject["project"]["dependencies"] = [] | ||
pkg_pyproject["project"]["optional-dependencies"] = {} | ||
|
||
(package_dir / "pyproject.toml").write_text(tomlkit.dumps(pkg_pyproject)) | ||
|
||
print(f"Package {package_name} created at {package_dir}") | ||
|
||
workspace_pyproject_path = PACKAGES_DIR.parent / "pyproject.toml" | ||
workspace_pyproject = tomlkit.parse(workspace_pyproject_path.read_text()) | ||
|
||
workspace_pyproject["project"]["dependencies"].append(package_name) | ||
|
||
workspace_info = tomlkit.inline_table() | ||
workspace_info.update({"workspace": True}) | ||
|
||
workspace_pyproject["tool"]["uv"]["sources"][package_name] = workspace_info | ||
|
||
workspace_pyproject["tool"]["uv"]["workspace"]["members"].append(f"packages/{package_name}") | ||
workspace_pyproject["tool"]["mypy"]["mypy_path"].append(f"packages/{package_name}/src") | ||
|
||
workspace_pyproject_path.write_text(tomlkit.dumps(workspace_pyproject), encoding="utf-8") | ||
|
||
print(f"Package {package_name} added to the workspace") | ||
|
||
|
||
if __name__ == "__main__": | ||
run() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.