Skip to content

Commit

Permalink
add dashboard command for debugging ragulate (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
epinzur authored Jul 22, 2024
1 parent 592ecb5 commit 1012c3e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions libs/ragulate/ragstack_ragulate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main() -> None:
cli_commands.setup_query(subparsers=subparsers)
cli_commands.setup_compare(subparsers=subparsers)
cli_commands.setup_run(subparsers=subparsers)
cli_commands.setup_dashboard(subparsers=subparsers)

# Parse the command-line arguments
args = parser.parse_args()
Expand Down
2 changes: 2 additions & 0 deletions libs/ragulate/ragstack_ragulate/cli_commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .compare import setup_compare
from .dashboard import setup_dashboard
from .download import setup_download
from .ingest import setup_ingest
from .query import setup_query
from .run import setup_run

__all__ = [
"setup_compare",
"setup_dashboard",
"setup_download",
"setup_ingest",
"setup_query",
Expand Down
9 changes: 2 additions & 7 deletions libs/ragulate/ragstack_ragulate/cli_commands/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from ragstack_ragulate.analysis import Analysis

from .utils import remove_sqlite_extension


def setup_compare(subparsers):
"""Setup the compare command."""
Expand All @@ -26,13 +28,6 @@ def setup_compare(subparsers):
compare_parser.set_defaults(func=lambda args: call_compare(**vars(args)))


def remove_sqlite_extension(s):
"""Remove the .sqlite extension from a string."""
if s.endswith(".sqlite"):
return s[:-7]
return s


def call_compare(
recipe: List[str],
output: Optional[str] = "box-plots",
Expand Down
36 changes: 36 additions & 0 deletions libs/ragulate/ragstack_ragulate/cli_commands/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from ragstack_ragulate.dashboard import run_dashboard

from .utils import remove_sqlite_extension


def setup_dashboard(subparsers):
"""Setup the dashboard command."""
dashboard_parser = subparsers.add_parser(
"dashboard",
help="Show the tru-lens dashboard for a recipe. Can be helpful for debugging.",
)
dashboard_parser.add_argument(
"-r",
"--recipe",
type=str,
help="A recipe to see the dashboard for.",
required=True,
)
dashboard_parser.add_argument(
"-p",
"--port",
type=int,
help="Port to show the dashboard on, default 8501",
default=8501,
)
dashboard_parser.set_defaults(func=lambda args: call_dashboard(**vars(args)))


def call_dashboard(
recipe: str,
port: int,
**_,
):
"""Runs the TruLens dashboard."""
recipe_name = remove_sqlite_extension(recipe)
run_dashboard(recipe_name=recipe_name, port=port)
5 changes: 5 additions & 0 deletions libs/ragulate/ragstack_ragulate/cli_commands/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def remove_sqlite_extension(s):
"""Remove the .sqlite extension from a string."""
if s.endswith(".sqlite"):
return s[:-7]
return s
9 changes: 9 additions & 0 deletions libs/ragulate/ragstack_ragulate/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Optional

from .utils import get_tru


def run_dashboard(recipe_name: str, port: Optional[int] = 8501):
"""Runs the TruLens dashboard."""
tru = get_tru(recipe_name=recipe_name)
tru.run_dashboard(port=port)

0 comments on commit 1012c3e

Please sign in to comment.