o
    h                     @  s  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	ddl
mZmZmZmZmZmZmZ ddlmZmZmZ d1ddZd2ddZddd3ddZed4ddZed5ddZd6ddZd7d#d$Zd8d'd(Zed4d)d*Zed5d+d*Zd6d,d*Zd7d-d.Zd8d/d0ZdS )9    )annotationsN)overload)	TypeGuard   )	FileTypesFileContentRequestFilesHttpxFileTypesBase64FileInputHttpxFileContentHttpxRequestFiles)
is_tuple_tis_mapping_tis_sequence_tobjobjectreturnTypeGuard[Base64FileInput]c                 C  s   t | tjpt | tjS N)
isinstanceioIOBaseosPathLiker    r   _/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/groq/_files.pyis_base64_file_input   s   r   TypeGuard[FileContent]c                 C  s,   t | tpt | tpt | tjpt | tjS r   )r   bytestupler   r   r   r   r   r   r   r   is_file_content   s   *r!   )keyr"   
str | NoneNonec                C  sF   t | s!|d urd| dnd| d}t| dt|  dd d S )NzExpected entry at ``zExpected file input `zF to be bytes, an io.IOBase instance, PathLike or a tuple but received zH instead. See https://github.com/groq/groq-python/tree/main#file-uploads)r!   RuntimeErrortype)r   r"   prefixr   r   r   assert_is_file_content!   s    r)   filesc                 C     d S r   r   r*   r   r   r   to_httpx_files)      r-   r   r   c                 C  r+   r   r   r,   r   r   r   r-   -   r.   RequestFiles | NoneHttpxRequestFiles | Nonec                 C  sX   | d u rd S t | rdd |  D } | S t| r"dd | D } | S tdt|  d)Nc                 S  s   i | ]	\}}|t |qS r   _transform_file.0r"   filer   r   r   
<dictcomp>6   s    z"to_httpx_files.<locals>.<dictcomp>c                 S  s   g | ]
\}}|t |fqS r   r1   r3   r   r   r   
<listcomp>8   s    z"to_httpx_files.<locals>.<listcomp>zUnexpected file type input z, expected mapping or sequence)r   itemsr   	TypeErrorr'   r,   r   r   r   r-   1   s   r5   r   r	   c                 C  sb   t | rt| tjrt| }|j| fS | S t| r-| d t	| d g| dd  R S t
dNr   r      zCExpected file types input to be a FileContent type or to be a tuple)r!   r   r   r   pathlibPathname
read_bytesr   _read_file_contentr9   r5   pathr   r   r   r2   ?   s   
"r2   r   r   c                 C  s   t | tjrt|  S | S r   )r   r   r   r<   r=   r?   r5   r   r   r   r@   M   s   r@   c                      d S r   r   r,   r   r   r   async_to_httpx_filesS      rE   c                   rD   r   r   r,   r   r   r   rE   W   rF   c                   sZ   | d u rd S t | rdd |  D I d H } | S t| r)dd | D I d H } | S td)Nc                   s"   i | ]\}}|t |I d H qS r   _async_transform_filer3   r   r   r   r6   `   s     z(async_to_httpx_files.<locals>.<dictcomp>c                   s$   g | ]\}}|t |I d H fqS r   rG   r3   r   r   r   r7   b   s   " z(async_to_httpx_files.<locals>.<listcomp>zFUnexpected file type input {type(files)}, expected mapping or sequence)r   r8   r   r9   r,   r   r   r   rE   [   s   c                   sp   t | rt| tjrt| }|j| I d H fS | S t| r4| d t	| d I d H g| dd  R S t
dr:   )r!   r   r   r   anyior=   r>   r?   r   _async_read_file_contentr9   rA   r   r   r   rH   i   s   
(rH   c                   s&   t | tjrt|  I d H S | S r   )r   r   r   rI   r=   r?   rC   r   r   r   rJ   w   s   rJ   )r   r   r   r   )r   r   r   r   )r   r   r"   r#   r   r$   )r*   r$   r   r$   )r*   r   r   r   )r*   r/   r   r0   )r5   r   r   r	   )r5   r   r   r   )
__future__r   r   r   r<   typingr   typing_extensionsr   rI   _typesr   r   r   r	   r
   r   r   _utilsr   r   r   r   r!   r)   r-   r2   r@   rE   rH   rJ   r   r   r   r   <module>   s4    $	






