Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
feat: add pdf_downloader tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubmrx committed Mar 17, 2024
1 parent 8ff56e4 commit 40ebf96
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM hyko-sdk:latest

COPY . .

CMD ["uvicorn", "--host", "0.0.0.0", "--port", "3000", "main:func"]
14 changes: 14 additions & 0 deletions hyko_toolkit/functions/web/web_scraping/pdf_downloader/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
from hyko_sdk.io import PDF
from hyko_sdk.models import CoreModel, Ext
from metadata import Inputs, Outputs, func


@func.on_execute
async def main(inputs: Inputs, params: CoreModel) -> Outputs:
# Send a GET request to the url
response = requests.get(inputs.url)
response.raise_for_status()
# If the GET request is successful, add the content to the list
data = response.content
return Outputs(pdf=PDF(val=data, obj_ext=Ext.PDF))
23 changes: 23 additions & 0 deletions hyko_toolkit/functions/web/web_scraping/pdf_downloader/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from hyko_sdk.definitions import ToolkitFunction
from hyko_sdk.io import PDF
from hyko_sdk.models import CoreModel
from pydantic import Field

func = ToolkitFunction(
name="pdf_downloader",
task="web_scraping",
description="This function downloads content from a URL and returns it as a PDF object.",
)


@func.set_input
class Inputs(CoreModel):
url: str = Field(
...,
description="Your Target PDF URL.",
)


@func.set_output
class Outputs(CoreModel):
pdf: PDF = Field(..., description="The Downloaded PDF.")

0 comments on commit 40ebf96

Please sign in to comment.