Skip to content

Commit 50185ca

Browse files
authored
Cache Image.format for better throughput (#8842)
* cache adapter methods for better throuput * cache image type * revert base adapter change
1 parent b33fd0b commit 50185ca

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

dspy/adapters/types/image.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import mimetypes
44
import os
55
import warnings
6+
from functools import lru_cache
67
from typing import Any, Union
78
from urllib.parse import urlparse
89

@@ -65,6 +66,7 @@ def __init__(self, url: Any = None, *, download: bool = False, **data):
6566
# Delegate the rest of initialization to pydantic's BaseModel.
6667
super().__init__(**data)
6768

69+
@lru_cache(maxsize=32)
6870
def format(self) -> list[dict[str, Any]] | str:
6971
try:
7072
image_url = encode_image(self.url)

0 commit comments

Comments
 (0)