Skip to content

Commit

Permalink
Instrumented more code with TimeTrace decorators. (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexaryn authored Jun 18, 2024
1 parent 36162a6 commit b0e3eca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/sycamore/sycamore/functions/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from sycamore.data import Document, Element
from sycamore.utils.image_utils import try_draw_boxes
from sycamore.utils.time_trace import timetrace
from PIL import Image as PImage, ImageDraw


@timetrace("Pdf2Imgs")
def split_and_convert_to_image(doc: Document) -> list[Document]:
"""Split a document into individual pages as images and convert them into Document objects.
Expand Down
3 changes: 3 additions & 0 deletions lib/sycamore/sycamore/transforms/extract_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from sycamore.plan_nodes import Node
from sycamore.transforms.map import Map
from sycamore.utils.extract_json import extract_json
from sycamore.utils.time_trace import timetrace


def element_list_formatter(elements: list[Element]) -> str:
Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(
self._prompt_formatter = prompt_formatter
self._max_num_properties = max_num_properties

@timetrace("ExtrSchema")
def extract_schema(self, document: Document) -> Document:
entities = self._handle_zero_shot_prompting(document)

Expand Down Expand Up @@ -142,6 +144,7 @@ def __init__(
self._num_of_elements = num_of_elements
self._prompt_formatter = prompt_formatter

@timetrace("ExtrProps")
def extract_properties(self, document: Document) -> Document:
entities = self._handle_zero_shot_prompting(document)

Expand Down
2 changes: 2 additions & 0 deletions lib/sycamore/sycamore/transforms/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sycamore.llms import LLM
from sycamore.llms.prompts import TextSummarizerGuidancePrompt
from sycamore.transforms.map import Map
from sycamore.utils.time_trace import timetrace


class Summarizer(ABC):
Expand Down Expand Up @@ -55,6 +56,7 @@ def summarize(self, document: Document) -> Document:
document.elements = elements
return document

@timetrace("SummText")
def _summarize_text_element(self, element: Element) -> Element:
prompt = TextSummarizerGuidancePrompt()

Expand Down
2 changes: 2 additions & 0 deletions lib/sycamore/sycamore/transforms/summarize_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sycamore.transforms.map import Map
from sycamore.utils.image_utils import base64_data_url
from sycamore.utils.extract_json import extract_json
from sycamore.utils.time_trace import timetrace


class OpenAIImageSummarizer:
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__(
self.prompt = prompt
self.include_context = include_context

@timetrace("SummImg")
def summarize_image(
self, image: Image.Image, preceding_context: Optional[str] = None, following_context: Optional[str] = None
):
Expand Down

0 comments on commit b0e3eca

Please sign in to comment.