1- from io import BytesIO
2- from pathlib import Path
3-
4- from fastapi import UploadFile
5- from fastapi .datastructures import Headers
61from PIL import Image
72
83from askui .chat .api .files .service import FileService
138 MessageParam ,
149 ToolResultBlockParam ,
1510)
16- from askui .logger import logger
1711from askui .models .shared .agent_message_param import (
1812 Base64ImageSourceParam ,
1913 TextBlockParam ,
3125from askui .models .shared .agent_message_param import (
3226 ToolResultBlockParam as AnthropicToolResultBlockParam ,
3327)
34- from askui .utils .image_utils import base64_to_image , image_to_base64
28+ from askui .utils .image_utils import image_to_base64
3529
3630
3731class ImageBlockParamSourceTranslator :
@@ -44,26 +38,28 @@ async def from_anthropic(
4438 if source .type == "url" :
4539 return source
4640 if source .type == "base64" : # noqa: RET503
47- try :
48- image = base64_to_image (source .data )
49- bytes_io = BytesIO ()
50- image .save (bytes_io , format = "PNG" )
51- bytes_io .seek (0 )
52- file = await self ._file_service .upload_file (
53- file = UploadFile (
54- file = bytes_io ,
55- headers = Headers (
56- {
57- "Content-Type" : "image/png" ,
58- }
59- ),
60- )
61- )
62- except Exception as e : # noqa: BLE001
63- logger .warning (f"Failed to save image: { e } " , exc_info = True )
64- return source
65- else :
66- return FileImageSourceParam (id = file .id , type = "file" )
41+ # Readd translation to FileImageSourceParam as soon as we support it in frontend
42+ return source
43+ # try:
44+ # image = base64_to_image(source.data)
45+ # bytes_io = BytesIO()
46+ # image.save(bytes_io, format="PNG")
47+ # bytes_io.seek(0)
48+ # file = await self._file_service.upload_file(
49+ # file=UploadFile(
50+ # file=bytes_io,
51+ # headers=Headers(
52+ # {
53+ # "Content-Type": "image/png",
54+ # }
55+ # ),
56+ # )
57+ # )
58+ # except Exception as e: # noqa: BLE001
59+ # logger.warning(f"Failed to save image: {e}", exc_info=True)
60+ # return source
61+ # else:
62+ # return FileImageSourceParam(id=file.id, type="file")
6763
6864 async def to_anthropic (
6965 self ,
0 commit comments