Skip to content

Commit a97d113

Browse files
authored
feat: migrate CLI from experimental to main package (#2183)
## Key Changes - Migrated CLI from `ragas.experimental.cli` to `ragas.cli` with updated imports - Added main `ragas` CLI command entry point, removed deprecated `ragas-experimental` command - Added Rich console to main utils and organized CLI dependencies in pyproject.toml
1 parent f166767 commit a97d113

File tree

7 files changed

+63
-18
lines changed

7 files changed

+63
-18
lines changed

CLAUDE.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
77
Ragas is an evaluation toolkit for Large Language Model (LLM) applications. It provides objective metrics for evaluating LLM applications, test data generation capabilities, and integrations with popular LLM frameworks.
88

99
The repository contains:
10+
1011
1. **Ragas Library** - The main evaluation toolkit including experimental features (in `/ragas` directory)
11-
- Core evaluation metrics and test generation
12+
- Core evaluation metrics and test generation
1213
- Experimental features available at `ragas.experimental`
1314

1415
## Development Environment Setup
@@ -139,6 +140,7 @@ The repository has the following structure:
139140
The Ragas core library provides metrics, test data generation and evaluation functionality for LLM applications:
140141

141142
1. **Metrics** - Various metrics for evaluating LLM applications including:
143+
142144
- AspectCritic
143145
- AnswerCorrectness
144146
- ContextPrecision
@@ -156,10 +158,11 @@ The experimental features are now integrated into the main ragas package:
156158

157159
1. **Experimental features** are available at `ragas.experimental`
158160
2. **Dataset and Experiment management** - Enhanced data handling for experiments
159-
3. **Advanced metrics** - Extended metric capabilities
161+
3. **Advanced metrics** - Extended metric capabilities
160162
4. **Backend support** - Multiple storage backends (CSV, JSONL, Google Drive, in-memory)
161163

162164
To use experimental features:
165+
163166
```python
164167
from ragas.experimental import Dataset
165168
from ragas import experiment
@@ -191,5 +194,5 @@ analytics_logger.addHandler(console_handler)
191194

192195
## Memories
193196

194-
- whenever you create such docs put in in /_experiments because that is gitignored and you can use it as a scratchpad or tmp directory for storing these
197+
- whenever you create such docs put in in /\_experiments because that is gitignored and you can use it as a scratchpad or tmp directory for storing these
195198
- always use uv to run python and python related commandline tools like isort, ruff, pyright ect. This is because we are using uv to manage the .venv and dependencies.

ragas/pyproject.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ dependencies = [
1717
"langchain-community",
1818
"langchain_openai",
1919

20+
# CLI dependencies
21+
"typer",
22+
"rich",
23+
2024
# LLM providers
2125
"openai>=1.0.0",
2226

23-
# CLI and experimental features
27+
# Experimental features
2428
"tqdm",
2529
"instructor",
2630
"gitpython",
27-
"typer",
28-
"rich",
2931
"pillow>=10.4.0",
3032
]
3133
dynamic = ["version", "readme"]
@@ -63,7 +65,7 @@ test = []
6365
"gdrive" = "ragas.backends.gdrive_backend:GDriveBackend"
6466

6567
[project.scripts]
66-
ragas-experimental = "ragas.experimental.cli:app"
68+
ragas = "ragas.cli:app"
6769

6870
[tool.setuptools]
6971
package-dir = {"" = "src"}

ragas/src/ragas/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1+
from ragas import backends
12
from ragas.cache import CacheInterface, DiskCacheBackend, cacher
23
from ragas.dataset_schema import EvaluationDataset, MultiTurnSample, SingleTurnSample
34
from ragas.evaluation import evaluate
45
from ragas.experiment import Experiment, experiment, version_experiment
56
from ragas.run_config import RunConfig
67

7-
# Backend imports
8-
from ragas import backends
9-
10-
# Backend imports
11-
128
try:
139
from ._version import version as __version__
1410
except ImportError:

ragas/src/ragas/experimental/cli.py renamed to ragas/src/ragas/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from rich.spinner import Spinner
1717
from rich.live import Live
1818

19-
# from .project.core import Project # TODO: Project module not implemented yet
20-
from .utils import console
19+
# from ragas.experimental.project.core import Project # TODO: Project module not implemented yet
20+
from ragas.utils import console
2121

2222

2323
app = typer.Typer(help="Ragas CLI for running LLM evaluations")

ragas/src/ragas/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy as np
1515
import tiktoken
1616
from datasets import Dataset
17+
from rich.console import Console
1718

1819
if t.TYPE_CHECKING:
1920
from ragas.metrics.base import Metric
@@ -308,6 +309,9 @@ def utc_converter(timestamp):
308309

309310
base_logger = set_logging_level()
310311

312+
# Rich console instance for CLI and other formatting needs
313+
console = Console()
314+
311315

312316
class MemorableNames:
313317
"""Generator for memorable, unique names for experiments and datasets."""

ragas/tests/unit/test_cli.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Tests for the Ragas CLI module."""
2+
3+
from typer.testing import CliRunner
4+
from ragas.cli import app
5+
6+
7+
def test_cli_help():
8+
"""Test that the CLI help command works."""
9+
runner = CliRunner()
10+
result = runner.invoke(app, ["--help"])
11+
assert result.exit_code == 0
12+
assert "Ragas CLI for running LLM evaluations" in result.stdout
13+
14+
15+
def test_hello_world_help():
16+
"""Test that the hello-world help command works."""
17+
runner = CliRunner()
18+
result = runner.invoke(app, ["hello-world", "--help"])
19+
assert result.exit_code == 0
20+
assert "Directory to run the hello world example in" in result.stdout
21+
22+
23+
def test_evals_help():
24+
"""Test that the evals help command works."""
25+
runner = CliRunner()
26+
result = runner.invoke(app, ["evals", "--help"])
27+
assert result.exit_code == 0
28+
assert "Run evaluations on a dataset" in result.stdout
29+
30+
31+
if __name__ == "__main__":
32+
print("Running CLI tests...")
33+
test_cli_help()
34+
print("✓ CLI help test passed")
35+
test_hello_world_help()
36+
print("✓ Hello world help test passed")
37+
test_evals_help()
38+
print("✓ Evals help test passed")
39+
print("All CLI tests passed!")

ragas/tests/unit/test_langgraph.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import List, Union
2+
from typing import List, Union, cast
33

44
import pytest
55
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
@@ -111,9 +111,10 @@ def test_unsupported_message_type():
111111
class CustomMessage:
112112
content = "test"
113113

114-
messages: List[Union[HumanMessage, SystemMessage, AIMessage, ToolMessage]] = [
115-
CustomMessage()
116-
] # type: ignore
114+
messages = cast(
115+
List[Union[HumanMessage, SystemMessage, AIMessage, ToolMessage]],
116+
[CustomMessage()],
117+
)
117118

118119
with pytest.raises(ValueError) as exc_info:
119120
convert_to_ragas_messages(messages)

0 commit comments

Comments
 (0)