Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add basic cli setup with package discovery #22

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ragbits-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ragbits CLI
53 changes: 53 additions & 0 deletions packages/ragbits-cli/pyproject.toml
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"
31 changes: 31 additions & 0 deletions packages/ragbits-cli/src/ragbits/cli/__init__.py
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()
19 changes: 19 additions & 0 deletions packages/ragbits-core/src/ragbits/core/cli.py
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")
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ requires-python = ">=3.10"
dependencies = [
"ragbits[litellm,local]",
"ragbits-dev-kit",
"ragbits-document-search"
"ragbits-document-search",
"ragbits-cli"
]

[tool.uv]
Expand All @@ -23,12 +24,14 @@ dev-dependencies = [
ragbits = { workspace = true }
ragbits-dev-kit = { workspace = true }
ragbits-document-search = { workspace = true }
ragbits-cli = { workspace = true }

[tool.uv.workspace]
members = [
"packages/ragbits-core",
"packages/ragbits-dev-kit",
"packages/ragbits-document-search"
"packages/ragbits-document-search",
"packages/ragbits-cli"
]

[tool.isort]
Expand Down Expand Up @@ -119,6 +122,7 @@ mypy_path = [
'packages/ragbits-core/src',
'packages/ragbits-dev-kit/src',
'packages/ragbits-document-search/src',
'packages/ragbits-cli/src',
]

[[tool.mypy.overrides]]
Expand Down
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading