Skip to content

Commit

Permalink
Added changes for cli tool package
Browse files Browse the repository at this point in the history
  • Loading branch information
gr8nishan committed Feb 21, 2025
1 parent e161114 commit 036badc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
2 changes: 0 additions & 2 deletions pebblo/text_generation/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,13 @@ def _call_bedrock(
Returns:
Dict[str, Any]: Response from the Bedrock API.
"""
logger.info("In Bedrock")
response = completion(
model=f"{os.environ.get('MODEL_NAME')}",
messages=message,
temperature=0,
custom_llm_provider="bedrock",
aws_bedrock_client=bedrock_client,
)
logger.info("Out from Bedrock")
return response.json()

def generate(
Expand Down
11 changes: 9 additions & 2 deletions pebblo/tools/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

from pebblo.app.api.api import App
from pebblo.app.api.req_models import Framework, ReqDiscover, ReqLoaderDoc, Runtime
from pebblo.app.config.config import var_server_config_dict
from pebblo.log import get_logger

# Initialize logger
logger = get_logger(__name__)
config_details = var_server_config_dict.get()

router = APIRouter(prefix="/tools")
os.environ["OCR_AGENT"] = (
Expand Down Expand Up @@ -55,7 +57,10 @@ async def document_report(
app_name, load_id = parse_files(saved_files)

# Determine report path based on format
report_base = Path("/opt/.pebblo") / app_name
base_path = os.path.expanduser(
config_details.get("reports", {}).get("cacheDir", ".")
)
report_base = Path(base_path) / app_name
if output_format == "pdf":
return serve_report(report_base / "pebblo_report.pdf", app_name, "pdf")
return serve_report(report_base / "report.json", app_name, "json")
Expand All @@ -77,9 +82,11 @@ def serve_report(report_path: Path, app_name: str, format_type: str):
Returns:
JSONResponse | Response: JSON report or downloadable PDF report.
"""

if not report_path.exists():
return JSONResponse(
{"error": f"{format_type.upper()} report not found"}, status_code=404
{"error": f"{format_type.upper()} report not found in {report_path}"},
status_code=404,
)

with open(report_path, "rb" if format_type == "pdf" else "r") as file:
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ dependencies = [
"nltk==3.9.1",
"boto3==1.36.24",
"json-repair==0.39.0",
"litellm==1.61.11"
"litellm==1.61.11",
"python-multipart==0.0.17",
"opencv-python-headless==4.11.0.86",
"unstructured==0.16.20",
"python-magic==0.4.27",
"langchain==0.3.18",
"pdf2image==1.17.0",
"paddlepaddle==3.0.0b1",
"unstructured.paddleocr==2.8.1.0",
"unstructured[pdf]"
]

# List additional groups of dependencies here (e.g. development
Expand Down
33 changes: 33 additions & 0 deletions tools/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "pebblo-cli"
version = "0.1.2"
description = "CLI tool for Pebblo"
authors = [{ name = "Pebblo Authors", email = "[email protected]" }]
dependencies = ["requests"]
requires-python = ">=3.9"
license = {file = "LICENSE.txt"}

classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]

[project.scripts]
pebblo-report = "reporter.pebblo_report:main"

[project.urls]
Homepage = "https://github.com/daxa-ai/pebblo"
Bug-Tracker = "https://github.com/daxa-ai/pebblo/issues"
Funding = "https://donate.pypi.org"
Source = "https://github.com/daxa-ai/pebblo/"
34 changes: 19 additions & 15 deletions tools/reporter/pebblo-report → tools/reporter/pebblo_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import argparse
import sys
from reporter import analyze_files

from reporter.reporter import analyze_files


def main():
parser = argparse.ArgumentParser(
Expand All @@ -13,34 +15,35 @@ def main():
%(prog)s -f document1.pdf document2.pdf
%(prog)s -f *.pdf -o pdf
%(prog)s -f document.pdf -u http://localhost:8000/tools/document_report
"""
""",
)

parser.add_argument(
"-f", "--files",
required=True,
nargs="+",
help="One or more files to analyze"
"-f", "--files", required=True, nargs="+", help="One or more files to analyze"
)

parser.add_argument(
"-o", "--output-format",
"-o",
"--output-format",
choices=["json", "pdf"],
default="json",
help="Output format for the report (default: json)"
help="Output format for the report (default: json)",
)

parser.add_argument(
"-u", "--url",
"-u",
"--url",
default="http://localhost:8000/tools/document_report",
help="API endpoint URL (default: http://localhost:8000/tools/document_report)"
help="API endpoint URL (default: http://localhost:8000/tools/document_report)",
)

args = parser.parse_args()

# Validate URL
if not args.url.startswith(("http://", "https://")):
print(f"Error: Invalid URL '{args.url}'. URL must start with http:// or https://")
print(
f"Error: Invalid URL '{args.url}'. URL must start with http:// or https://"
)
sys.exit(1)

try:
Expand All @@ -52,5 +55,6 @@ def main():
print(f"Error: {str(e)}")
sys.exit(1)


if __name__ == "__main__":
main()
main()

0 comments on commit 036badc

Please sign in to comment.