Skip to content

Commit d906be0

Browse files
fix: types
1 parent 6dbd97c commit d906be0

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/amrita_core/chatmanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def __init__(
401401
preset: ModelPreset | None = None,
402402
auto_create_session: bool = False,
403403
hook_args: tuple[Any, ...] = (),
404-
hook_kwargs: dict[str, Any] = {},
404+
hook_kwargs: dict[str, Any] | None = None,
405405
queue_size: int = 25,
406406
overflow_queue_size: int = 45,
407407
) -> None:
@@ -444,7 +444,7 @@ def __init__(
444444
)
445445
# Hook args
446446
self._hook_args = hook_args
447-
self._hook_kwargs = hook_kwargs
447+
self._hook_kwargs = hook_kwargs or {}
448448

449449
# Initialize async queue for streaming responses
450450
self._response_queue = asyncio.Queue(queue_size)

src/amrita_core/protocol.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def __init__(self, image: str | BytesIO | bytes):
106106
super().__init__("image")
107107
self.image: str | BytesIO | bytes = image
108108

109-
async def get_image(
110-
self, headers: dict[str, None] | None = None
111-
) -> BytesIO | bytes:
109+
async def get_image(self, headers: dict[str, Any] | None = None) -> BytesIO | bytes:
112110
if isinstance(self.image, str):
113111
self.image = await self.curl_image(headers)
114112
return self.image
@@ -123,7 +121,8 @@ async def curl_image(self, extra_headers: dict | None = None) -> bytes:
123121
async with session.get(self.image) as response:
124122
if response.status != 200:
125123
raise ValueError(f"Failed to download image from {self.image}")
126-
obj = await response.read()
124+
bt = await response.read()
125+
obj = base64.b64encode(bt)
127126
return obj
128127
raise ValueError("Image must be a URL to use this method")
129128

@@ -135,7 +134,7 @@ def get_content(self) -> str:
135134
image_type = get_image_format(self.image)
136135
if not image_type:
137136
return "[Unsupported image format]"
138-
return f"![](data:image/{image_type};base64,{base64.b64encode(self.image).decode()})"
137+
return f"![](data:image/{image_type};base64,{self.image.decode('utf-8')})"
139138

140139
async def save_to(self, path: Path, headers: dict | None = None):
141140
async with aiofiles.open(path, "wb") as f:

0 commit comments

Comments
 (0)