ragbits-cli 0.3.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/.gitignore +1 -0
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/CHANGELOG.md +16 -0
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/PKG-INFO +7 -3
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/pyproject.toml +8 -2
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/src/ragbits/cli/__init__.py +19 -2
- ragbits_cli-0.5.0/src/ragbits/cli/app.py +76 -0
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/README.md +0 -0
- {ragbits_cli-0.3.0 → ragbits_cli-0.5.0}/py.typed +0 -0
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.5.0 (2024-12-05)
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Add global flag to specify output type: text or json (#232).
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- ragbits-core updated to version v0.5.0
|
|
14
|
+
|
|
15
|
+
## 0.4.0 (2024-11-27)
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- ragbits-core updated to version v0.4.0
|
|
20
|
+
|
|
5
21
|
## 0.3.0 (2024-11-06)
|
|
6
22
|
|
|
7
23
|
### Changed
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: ragbits-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A CLI application for ragbits - building blocks for rapid development of GenAI applications
|
|
5
|
+
Project-URL: Homepage, https://github.com/deepsense-ai/ragbits
|
|
6
|
+
Project-URL: Bug Reports, https://github.com/deepsense-ai/ragbits/issues
|
|
7
|
+
Project-URL: Documentation, https://ragbits.deepsense.ai/
|
|
8
|
+
Project-URL: Source, https://github.com/deepsense-ai/ragbits
|
|
5
9
|
Author-email: "deepsense.ai" <ragbits@deepsense.ai>
|
|
6
|
-
License
|
|
10
|
+
License: MIT
|
|
7
11
|
Keywords: GenAI,Generative AI,LLMs,Large Language Models,Prompt Management,RAG,Retrieval Augmented Generation
|
|
8
12
|
Classifier: Development Status :: 4 - Beta
|
|
9
13
|
Classifier: Environment :: Console
|
|
@@ -18,7 +22,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
18
22
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
23
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
24
|
Requires-Python: >=3.10
|
|
21
|
-
Requires-Dist: ragbits-core==0.
|
|
25
|
+
Requires-Dist: ragbits-core==0.5.0
|
|
22
26
|
Requires-Dist: typer>=0.12.5
|
|
23
27
|
Description-Content-Type: text/markdown
|
|
24
28
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ragbits-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
description = "A CLI application for ragbits - building blocks for rapid development of GenAI applications"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -31,7 +31,13 @@ classifiers = [
|
|
|
31
31
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
32
32
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
33
|
]
|
|
34
|
-
dependencies = ["typer>=0.12.5", "ragbits-core==0.
|
|
34
|
+
dependencies = ["typer>=0.12.5", "ragbits-core==0.5.0"]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
"Homepage" = "https://github.com/deepsense-ai/ragbits"
|
|
38
|
+
"Bug Reports" = "https://github.com/deepsense-ai/ragbits/issues"
|
|
39
|
+
"Documentation" = "https://ragbits.deepsense.ai/"
|
|
40
|
+
"Source" = "https://github.com/deepsense-ai/ragbits"
|
|
35
41
|
|
|
36
42
|
[project.scripts]
|
|
37
43
|
ragbits = "ragbits.cli:main"
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import importlib.util
|
|
2
2
|
import pkgutil
|
|
3
3
|
from pathlib import Path
|
|
4
|
+
from typing import Annotated
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import typer
|
|
6
7
|
|
|
7
8
|
import ragbits
|
|
8
9
|
|
|
9
|
-
app
|
|
10
|
+
from .app import CLI, OutputType
|
|
11
|
+
|
|
12
|
+
app = CLI(no_args_is_help=True)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.callback()
|
|
16
|
+
def output_type(
|
|
17
|
+
# `OutputType.text.value` used as a workaround for the issue with `typer.Option` not accepting Enum values
|
|
18
|
+
output: Annotated[
|
|
19
|
+
OutputType, typer.Option("--output", "-o", help="Set the output type (text or json)")
|
|
20
|
+
] = OutputType.text.value, # type: ignore
|
|
21
|
+
) -> None:
|
|
22
|
+
"""Sets an output type for the CLI
|
|
23
|
+
Args:
|
|
24
|
+
output: type of output to be set
|
|
25
|
+
"""
|
|
26
|
+
app.set_output_type(output_type=output)
|
|
10
27
|
|
|
11
28
|
|
|
12
29
|
def main() -> None:
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OutputType(Enum):
|
|
13
|
+
"""Indicates a type of CLI output formatting"""
|
|
14
|
+
|
|
15
|
+
text = "text"
|
|
16
|
+
json = "json"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass()
|
|
20
|
+
class CliState:
|
|
21
|
+
"""A dataclass describing CLI state"""
|
|
22
|
+
|
|
23
|
+
output_type: OutputType = OutputType.text
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CLI(typer.Typer):
|
|
27
|
+
"""A CLI class with output formatting"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, *args: Any, **kwargs: Any): # noqa: ANN401
|
|
30
|
+
super().__init__(*args, **kwargs)
|
|
31
|
+
self.state: CliState = CliState()
|
|
32
|
+
self.console: Console = Console()
|
|
33
|
+
|
|
34
|
+
def set_output_type(self, output_type: OutputType) -> None:
|
|
35
|
+
"""
|
|
36
|
+
Set the output type in the app state
|
|
37
|
+
Args:
|
|
38
|
+
output_type: OutputType
|
|
39
|
+
"""
|
|
40
|
+
self.state.output_type = output_type
|
|
41
|
+
|
|
42
|
+
def print_output(self, data: list[BaseModel] | BaseModel) -> None:
|
|
43
|
+
"""
|
|
44
|
+
Process and display output based on the current state's output type.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
data: list of ditionaries or list of pydantic models representing output of CLI function
|
|
48
|
+
"""
|
|
49
|
+
if isinstance(data, BaseModel):
|
|
50
|
+
data = [data]
|
|
51
|
+
if len(data) == 0:
|
|
52
|
+
self._print_empty_list()
|
|
53
|
+
return
|
|
54
|
+
first_el_instance = type(data[0])
|
|
55
|
+
if any(not isinstance(datapoint, first_el_instance) for datapoint in data):
|
|
56
|
+
raise ValueError("All the rows need to be of the same type")
|
|
57
|
+
data_dicts: list[dict] = [output.model_dump(mode="python") for output in data]
|
|
58
|
+
output_type = self.state.output_type
|
|
59
|
+
if output_type == OutputType.json:
|
|
60
|
+
print(json.dumps(data_dicts, indent=4))
|
|
61
|
+
elif output_type == OutputType.text:
|
|
62
|
+
table = Table(show_header=True, header_style="bold magenta")
|
|
63
|
+
properties = data[0].model_json_schema()["properties"]
|
|
64
|
+
for key in properties:
|
|
65
|
+
table.add_column(properties[key]["title"])
|
|
66
|
+
for row in data_dicts:
|
|
67
|
+
table.add_row(*[str(value) for value in row.values()])
|
|
68
|
+
self.console.print(table)
|
|
69
|
+
else:
|
|
70
|
+
raise ValueError(f"Output type: {output_type} not supported")
|
|
71
|
+
|
|
72
|
+
def _print_empty_list(self) -> None:
|
|
73
|
+
if self.state.output_type == OutputType.text:
|
|
74
|
+
print("Empty data list")
|
|
75
|
+
elif self.state.output_type == OutputType.json:
|
|
76
|
+
print(json.dumps([]))
|
|
File without changes
|
|
File without changes
|