mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
Redesign Python AI engine (#5991)
# Description of Changes Redesign the Python AI engine to be properly agentic and make use of `pydantic-ai` instead of `langchain` for correctness and ergonomics. This should be a good foundation for us to build our AI engine on going forwards.
This commit is contained in:
@@ -0,0 +1,439 @@
|
||||
# AUTO-GENERATED FILE. DO NOT EDIT.
|
||||
# Generated by scripts/generate_tool_models.py from frontend TypeScript sources.
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Any, Literal
|
||||
|
||||
from stirling.models.base import ApiModel
|
||||
|
||||
|
||||
class AddAttachmentsParams(ApiModel):
|
||||
attachments: list[dict[str, Any]] = []
|
||||
|
||||
|
||||
class AdjustContrastParams(ApiModel):
|
||||
blue: float = 100
|
||||
brightness: float = 100
|
||||
contrast: float = 100
|
||||
green: float = 100
|
||||
red: float = 100
|
||||
saturation: float = 100
|
||||
|
||||
|
||||
class AutoRenameParams(ApiModel):
|
||||
use_first_text_as_fallback: bool = False
|
||||
|
||||
|
||||
class AutomateParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class BookletImpositionParams(ApiModel):
|
||||
add_border: bool = False
|
||||
add_gutter: bool = False
|
||||
double_sided: bool = True
|
||||
duplex_pass: Literal["BOTH", "FIRST", "SECOND"] = "BOTH"
|
||||
flip_on_short_edge: bool = False
|
||||
gutter_size: float = 12
|
||||
pages_per_sheet: float = 2
|
||||
spine_location: Literal["LEFT", "RIGHT"] = "LEFT"
|
||||
|
||||
|
||||
class CertSignParams(ApiModel):
|
||||
cert_file: dict[str, Any] | None = None
|
||||
cert_type: Literal["", "PEM", "PKCS12", "PFX", "JKS"] = ""
|
||||
jks_file: dict[str, Any] | None = None
|
||||
location: str = ""
|
||||
name: str = ""
|
||||
p12_file: dict[str, Any] | None = None
|
||||
page_number: float = 1
|
||||
password: str = ""
|
||||
private_key_file: dict[str, Any] | None = None
|
||||
reason: str = ""
|
||||
show_logo: bool = True
|
||||
show_signature: bool = False
|
||||
sign_mode: Literal["MANUAL", "AUTO"] = "MANUAL"
|
||||
|
||||
|
||||
class ChangeMetadataParams(ApiModel):
|
||||
author: str = ""
|
||||
creation_date: str | None = None
|
||||
creator: str = ""
|
||||
custom_metadata: list[dict[str, str]] = []
|
||||
delete_all: bool = False
|
||||
keywords: str = ""
|
||||
modification_date: str | None = None
|
||||
producer: str = ""
|
||||
subject: str = ""
|
||||
title: str = ""
|
||||
trapped: Literal["True", "False", "Unknown"] | None = None
|
||||
|
||||
|
||||
class ChangePermissionsParams(ApiModel):
|
||||
prevent_assembly: bool = False
|
||||
prevent_extract_content: bool = False
|
||||
prevent_extract_for_accessibility: bool = False
|
||||
prevent_fill_in_form: bool = False
|
||||
prevent_modify: bool = False
|
||||
prevent_modify_annotations: bool = False
|
||||
prevent_printing: bool = False
|
||||
prevent_printing_faithful: bool = False
|
||||
|
||||
|
||||
class AddPasswordParams(ApiModel):
|
||||
key_length: float = 128
|
||||
owner_password: str = ""
|
||||
password: str = ""
|
||||
permissions: ChangePermissionsParams = ChangePermissionsParams.model_validate(
|
||||
{
|
||||
"preventAssembly": False,
|
||||
"preventExtractContent": False,
|
||||
"preventExtractForAccessibility": False,
|
||||
"preventFillInForm": False,
|
||||
"preventModify": False,
|
||||
"preventModifyAnnotations": False,
|
||||
"preventPrinting": False,
|
||||
"preventPrintingFaithful": False,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class CompressParams(ApiModel):
|
||||
compression_level: float = 5
|
||||
compression_method: Literal["quality", "filesize"] = "quality"
|
||||
expected_size: str = ""
|
||||
file_size_unit: Literal["KB", "MB"] = "MB"
|
||||
file_size_value: str = ""
|
||||
grayscale: bool = False
|
||||
|
||||
|
||||
class ConvertParams(ApiModel):
|
||||
cbz_options: dict[str, bool] = {"optimizeForEbook": False}
|
||||
cbz_output_options: dict[str, float] = {"dpi": 150}
|
||||
email_options: dict[str, Any] = {
|
||||
"includeAttachments": True,
|
||||
"maxAttachmentSizeMB": 10,
|
||||
"downloadHtml": False,
|
||||
"includeAllRecipients": False,
|
||||
}
|
||||
from_extension: str = ""
|
||||
html_options: dict[str, float] = {"zoomLevel": 1}
|
||||
image_options: dict[str, Any] = {
|
||||
"colorType": "color",
|
||||
"dpi": 300,
|
||||
"singleOrMultiple": "multiple",
|
||||
"fitOption": "maintainAspectRatio",
|
||||
"autoRotate": True,
|
||||
"combineImages": True,
|
||||
}
|
||||
is_smart_detection: bool = False
|
||||
pdfa_options: dict[str, str] = {"outputFormat": "pdfa-1"}
|
||||
smart_detection_type: Literal["mixed", "images", "web", "none"] = "none"
|
||||
to_extension: str = ""
|
||||
|
||||
|
||||
class CropParams(ApiModel):
|
||||
crop_area: dict[str, float] = {"x": 0, "y": 0, "width": 595, "height": 842}
|
||||
|
||||
|
||||
class EditTableOfContentsParams(ApiModel):
|
||||
bookmarks: list[dict[str, Any]] = []
|
||||
replace_existing: bool = True
|
||||
|
||||
|
||||
class ExtractImagesParams(ApiModel):
|
||||
allow_duplicates: bool = False
|
||||
format: Literal["png", "jpg", "gif"] = "png"
|
||||
|
||||
|
||||
class ExtractPagesParams(ApiModel):
|
||||
page_numbers: str = ""
|
||||
|
||||
|
||||
class FlattenParams(ApiModel):
|
||||
flatten_only_forms: bool = False
|
||||
|
||||
|
||||
class MergeParams(ApiModel):
|
||||
generate_table_of_contents: bool = False
|
||||
remove_digital_signature: bool = False
|
||||
|
||||
|
||||
class OcrParams(ApiModel):
|
||||
additional_options: list[str] = []
|
||||
languages: list[str] = []
|
||||
ocr_render_type: str = "hocr"
|
||||
ocr_type: str = "skip-text"
|
||||
|
||||
|
||||
class OverlayPdfsParams(ApiModel):
|
||||
counts: list[float] = []
|
||||
overlay_files: list[dict[str, Any]] = []
|
||||
overlay_mode: Literal["SequentialOverlay", "InterleavedOverlay", "FixedRepeatOverlay"] = "SequentialOverlay"
|
||||
overlay_position: Literal[0, 1] = 0
|
||||
|
||||
|
||||
class PageLayoutParams(ApiModel):
|
||||
add_border: bool = False
|
||||
pages_per_sheet: float = 4
|
||||
|
||||
|
||||
class PdfToSinglePageParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class RedactParams(ApiModel):
|
||||
convert_pdfto_image: bool = True
|
||||
custom_padding: float = 0.1
|
||||
mode: Literal["automatic", "manual"] = "automatic"
|
||||
redact_color: str = "#000000"
|
||||
use_regex: bool = False
|
||||
whole_word_search: bool = False
|
||||
words_to_redact: list[str] = []
|
||||
|
||||
|
||||
class RemoveAnnotationsParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class RemoveBlanksParams(ApiModel):
|
||||
include_blank_pages: bool = False
|
||||
threshold: float = 10
|
||||
white_percent: float = 99.9
|
||||
|
||||
|
||||
class RemoveCertSignParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class RemoveImageParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class RemovePagesParams(ApiModel):
|
||||
page_numbers: str = ""
|
||||
|
||||
|
||||
class RemovePasswordParams(ApiModel):
|
||||
password: str = ""
|
||||
|
||||
|
||||
class ReorganizePagesParams(ApiModel):
|
||||
custom_mode: str | None = None
|
||||
page_numbers: str | None = None
|
||||
|
||||
|
||||
class RepairParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class ReplaceColorParams(ApiModel):
|
||||
back_ground_color: str = "#ffffff"
|
||||
high_contrast_color_combination: Literal[
|
||||
"WHITE_TEXT_ON_BLACK", "BLACK_TEXT_ON_WHITE", "YELLOW_TEXT_ON_BLACK", "GREEN_TEXT_ON_BLACK"
|
||||
] = "WHITE_TEXT_ON_BLACK"
|
||||
replace_and_invert_option: Literal[
|
||||
"HIGH_CONTRAST_COLOR", "CUSTOM_COLOR", "FULL_INVERSION", "COLOR_SPACE_CONVERSION"
|
||||
] = "HIGH_CONTRAST_COLOR"
|
||||
text_color: str = "#000000"
|
||||
|
||||
|
||||
class RotateParams(ApiModel):
|
||||
angle: float = 0
|
||||
|
||||
|
||||
class SanitizeParams(ApiModel):
|
||||
remove_embedded_files: bool = True
|
||||
remove_fonts: bool = False
|
||||
remove_java_script: bool = True
|
||||
remove_links: bool = False
|
||||
remove_metadata: bool = False
|
||||
remove_xmpmetadata: bool = False
|
||||
|
||||
|
||||
class ScalePagesParams(ApiModel):
|
||||
page_size: Literal["KEEP", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "LETTER", "LEGAL"] | None = None
|
||||
scale_factor: float = 1
|
||||
|
||||
|
||||
class ScannerImageSplitParams(ApiModel):
|
||||
angle_threshold: float = 10
|
||||
border_size: float = 1
|
||||
min_area: float = 10000
|
||||
min_contour_area: float = 500
|
||||
tolerance: float = 30
|
||||
|
||||
|
||||
class SignParams(ApiModel):
|
||||
font_family: str = "Helvetica"
|
||||
font_size: float = 16
|
||||
location: str = "Digital"
|
||||
reason: str = "Document signing"
|
||||
signature_data: str | None = None
|
||||
signature_position: dict[str, float] | None = None
|
||||
signature_type: Literal["text", "image", "canvas"] = "canvas"
|
||||
signer_name: str = ""
|
||||
text_color: str = "#000000"
|
||||
|
||||
|
||||
class SplitParams(ApiModel):
|
||||
allow_duplicates: bool = False
|
||||
bookmark_level: str = "1"
|
||||
duplex_mode: bool = False
|
||||
h_div: str = "2"
|
||||
include_metadata: bool = False
|
||||
merge: bool = False
|
||||
method: Literal[
|
||||
"", "byPages", "bySections", "bySize", "byPageCount", "byDocCount", "byChapters", "byPageDivider"
|
||||
] = ""
|
||||
pages: str = ""
|
||||
split_value: str = ""
|
||||
v_div: str = "2"
|
||||
|
||||
|
||||
class UnlockPdfformsParams(ApiModel):
|
||||
pass
|
||||
|
||||
|
||||
class WatermarkParams(ApiModel):
|
||||
alphabet: str = "roman"
|
||||
convert_pdfto_image: bool = False
|
||||
custom_color: str = "#d3d3d3"
|
||||
font_size: float = 12
|
||||
height_spacer: float = 50
|
||||
opacity: float = 50
|
||||
rotation: float = 0
|
||||
watermark_image: dict[str, Any] | None = None
|
||||
watermark_text: str = ""
|
||||
watermark_type: Literal["text", "image"] | None = None
|
||||
width_spacer: float = 50
|
||||
|
||||
|
||||
type ParamToolModel = (
|
||||
AddAttachmentsParams
|
||||
| AddPasswordParams
|
||||
| AdjustContrastParams
|
||||
| AutoRenameParams
|
||||
| AutomateParams
|
||||
| BookletImpositionParams
|
||||
| CertSignParams
|
||||
| ChangeMetadataParams
|
||||
| ChangePermissionsParams
|
||||
| CompressParams
|
||||
| ConvertParams
|
||||
| CropParams
|
||||
| EditTableOfContentsParams
|
||||
| ExtractImagesParams
|
||||
| ExtractPagesParams
|
||||
| FlattenParams
|
||||
| MergeParams
|
||||
| OcrParams
|
||||
| OverlayPdfsParams
|
||||
| PageLayoutParams
|
||||
| PdfToSinglePageParams
|
||||
| RedactParams
|
||||
| RemoveAnnotationsParams
|
||||
| RemoveBlanksParams
|
||||
| RemoveCertSignParams
|
||||
| RemoveImageParams
|
||||
| RemovePagesParams
|
||||
| RemovePasswordParams
|
||||
| ReorganizePagesParams
|
||||
| RepairParams
|
||||
| ReplaceColorParams
|
||||
| RotateParams
|
||||
| SanitizeParams
|
||||
| ScalePagesParams
|
||||
| ScannerImageSplitParams
|
||||
| SignParams
|
||||
| SplitParams
|
||||
| UnlockPdfformsParams
|
||||
| WatermarkParams
|
||||
)
|
||||
type ParamToolModelType = type[ParamToolModel]
|
||||
|
||||
|
||||
class OperationId(StrEnum):
|
||||
ADD_ATTACHMENTS = "addAttachments"
|
||||
ADD_PASSWORD = "addPassword"
|
||||
ADJUST_CONTRAST = "adjustContrast"
|
||||
AUTO_RENAME = "autoRename"
|
||||
AUTOMATE = "automate"
|
||||
BOOKLET_IMPOSITION = "bookletImposition"
|
||||
CERT_SIGN = "certSign"
|
||||
CHANGE_METADATA = "changeMetadata"
|
||||
CHANGE_PERMISSIONS = "changePermissions"
|
||||
COMPRESS = "compress"
|
||||
CONVERT = "convert"
|
||||
CROP = "crop"
|
||||
EDIT_TABLE_OF_CONTENTS = "editTableOfContents"
|
||||
EXTRACT_IMAGES = "extractImages"
|
||||
EXTRACT_PAGES = "extractPages"
|
||||
FLATTEN = "flatten"
|
||||
MERGE = "merge"
|
||||
OCR = "ocr"
|
||||
OVERLAY_PDFS = "overlayPdfs"
|
||||
PAGE_LAYOUT = "pageLayout"
|
||||
PDF_TO_SINGLE_PAGE = "pdfToSinglePage"
|
||||
REDACT = "redact"
|
||||
REMOVE_ANNOTATIONS = "removeAnnotations"
|
||||
REMOVE_BLANKS = "removeBlanks"
|
||||
REMOVE_CERT_SIGN = "removeCertSign"
|
||||
REMOVE_IMAGE = "removeImage"
|
||||
REMOVE_PAGES = "removePages"
|
||||
REMOVE_PASSWORD = "removePassword"
|
||||
REORGANIZE_PAGES = "reorganizePages"
|
||||
REPAIR = "repair"
|
||||
REPLACE_COLOR = "replaceColor"
|
||||
ROTATE = "rotate"
|
||||
SANITIZE = "sanitize"
|
||||
SCALE_PAGES = "scalePages"
|
||||
SCANNER_IMAGE_SPLIT = "scannerImageSplit"
|
||||
SIGN = "sign"
|
||||
SPLIT = "split"
|
||||
UNLOCK_PDFFORMS = "unlockPDFForms"
|
||||
WATERMARK = "watermark"
|
||||
|
||||
|
||||
OPERATIONS: dict[OperationId, ParamToolModelType] = {
|
||||
OperationId.ADD_ATTACHMENTS: AddAttachmentsParams,
|
||||
OperationId.ADD_PASSWORD: AddPasswordParams,
|
||||
OperationId.ADJUST_CONTRAST: AdjustContrastParams,
|
||||
OperationId.AUTO_RENAME: AutoRenameParams,
|
||||
OperationId.AUTOMATE: AutomateParams,
|
||||
OperationId.BOOKLET_IMPOSITION: BookletImpositionParams,
|
||||
OperationId.CERT_SIGN: CertSignParams,
|
||||
OperationId.CHANGE_METADATA: ChangeMetadataParams,
|
||||
OperationId.CHANGE_PERMISSIONS: ChangePermissionsParams,
|
||||
OperationId.COMPRESS: CompressParams,
|
||||
OperationId.CONVERT: ConvertParams,
|
||||
OperationId.CROP: CropParams,
|
||||
OperationId.EDIT_TABLE_OF_CONTENTS: EditTableOfContentsParams,
|
||||
OperationId.EXTRACT_IMAGES: ExtractImagesParams,
|
||||
OperationId.EXTRACT_PAGES: ExtractPagesParams,
|
||||
OperationId.FLATTEN: FlattenParams,
|
||||
OperationId.MERGE: MergeParams,
|
||||
OperationId.OCR: OcrParams,
|
||||
OperationId.OVERLAY_PDFS: OverlayPdfsParams,
|
||||
OperationId.PAGE_LAYOUT: PageLayoutParams,
|
||||
OperationId.PDF_TO_SINGLE_PAGE: PdfToSinglePageParams,
|
||||
OperationId.REDACT: RedactParams,
|
||||
OperationId.REMOVE_ANNOTATIONS: RemoveAnnotationsParams,
|
||||
OperationId.REMOVE_BLANKS: RemoveBlanksParams,
|
||||
OperationId.REMOVE_CERT_SIGN: RemoveCertSignParams,
|
||||
OperationId.REMOVE_IMAGE: RemoveImageParams,
|
||||
OperationId.REMOVE_PAGES: RemovePagesParams,
|
||||
OperationId.REMOVE_PASSWORD: RemovePasswordParams,
|
||||
OperationId.REORGANIZE_PAGES: ReorganizePagesParams,
|
||||
OperationId.REPAIR: RepairParams,
|
||||
OperationId.REPLACE_COLOR: ReplaceColorParams,
|
||||
OperationId.ROTATE: RotateParams,
|
||||
OperationId.SANITIZE: SanitizeParams,
|
||||
OperationId.SCALE_PAGES: ScalePagesParams,
|
||||
OperationId.SCANNER_IMAGE_SPLIT: ScannerImageSplitParams,
|
||||
OperationId.SIGN: SignParams,
|
||||
OperationId.SPLIT: SplitParams,
|
||||
OperationId.UNLOCK_PDFFORMS: UnlockPdfformsParams,
|
||||
OperationId.WATERMARK: WatermarkParams,
|
||||
}
|
||||
Reference in New Issue
Block a user