mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 18:44:05 +02:00
# Description of Changes Adds the ability for the Edit agent to request the content of the document before it decides which parameters it needs. This makes it able to process requests like `Split the document after the page containing the "My Section" section`, allowing for document context-based requests for all[^1] tools. I had to make a few changes elsewhere to make this work, including: - Moving the requesting of content out of the Question Agent and into a common location - Added specific API docs for the Split param because the generic ones were not specific enough for the AI to be able to reliably perform the correct operation - Fixed an issue in the tool models generator which caused the Redact params to only be half-generated (causing Pydantic to crash when the AI tried to run Redact) - Added missing logging to a bunch of tools and hooked it up properly so it'll print to stderr - Made the limits for the max pages/chars to extract from PDFs configurable via env var [^1]: Many of the tools can't actually do anything useful with the context at this stage, but will just need the tool API to be extended with new features like page-specific operations to be automatically able to do smart operations without needing to change the Edit agent itself.
34 lines
957 B
Python
34 lines
957 B
Python
"""Shared logging utilities for the Stirling AI engine."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Pretty:
|
|
"""Lazy JSON formatter — only serialises when ``str()`` is called.
|
|
|
|
Designed for use with ``logging``'s ``%s`` formatting so that the
|
|
JSON serialisation is skipped entirely when the log message is
|
|
never emitted. Pydantic models (at the top level or nested) are
|
|
dumped via ``model_dump``; anything else falls back to ``str``.
|
|
"""
|
|
|
|
__slots__ = ("_obj",)
|
|
|
|
def __init__(self, obj: object) -> None:
|
|
self._obj = obj
|
|
|
|
def __str__(self) -> str:
|
|
if isinstance(self._obj, BaseModel):
|
|
return self._obj.model_dump_json(indent=2)
|
|
return json.dumps(self._obj, indent=2, default=_default, ensure_ascii=True)
|
|
|
|
|
|
def _default(value: object) -> object:
|
|
if isinstance(value, BaseModel):
|
|
return value.model_dump()
|
|
return str(value)
|