
    g                     @    d dl mZ d dlZd dlmZ  G d de      Zd Zy)    )UnionN)BaseLLMExceptionc                   J     e Zd Zdededeeej                  f   f fdZ	 xZ
S )OllamaErrorstatus_codemessageheadersc                 *    t         |   |||       y )N)r   r   r	   )super__init__)selfr   r   r	   	__class__s       U/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/ollama/common_utils.pyr   zOllamaError.__init__	   s     	['7S    )__name__
__module____qualname__intstrr   dicthttpxHeadersr   __classcell__)r   s   @r   r   r      s8    TT),T7<T5===P7QT Tr   r   c                 "   ddl }ddl}	 ddlm} | }| j                  d      r| j                  d      d   } 	 |j                  |j                  |j                  |                   }|j                  dv r| S 	 |j                         }|j                  d	      j                  |d
       |j                  d       |j                  |j                               j!                  d      S # t        $ r t	        d      w xY w# t        $ r |cY S w xY w)z
    Convert image to base64 encoded image if not already in base64 format

    If image is already in base64 format AND is a jpeg/png, return it

    If image is not JPEG/PNG, convert it to JPEG base64 format
    r   N)Imagez>ollama image conversion failed please run `pip install Pillow`zdata:,)JPEGPNGRGBr   zutf-8)base64ioPILr   	Exception
startswithsplitopenBytesIO	b64decodeformatconvertsaveseek	b64encodegetvaluedecode)imager!   r"   r   orig
image_data
jpeg_images          r   _convert_imager5      s    
 D C $ZZ

6+;+;E+B CD
/L 0 Ju"":v6OOAJ//1299'BB#  
L
 	

  s   C( >D  (C= DD)typingr   r   )litellm.llms.base_llm.chat.transformationr   r   r5    r   r   <module>r9      s#      FT" TCr   