
    rh                        d Z ddlmZ ddlZddlmZmZmZ eZddZ	ddZ
 G d deeef   ej                  	      Z G d
 de      Zy)zLLMFnOutputRow.    )annotationsN)AnyIteratorMappingc                H    t        | d      r| j                  S t        |       S )N__name__)hasattrr   str)xs    /var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/notebook/lib/llmfn_output_row.py_get_name_of_typer      s    q*zzq6M    c           
         |t         k(  ry t        | |      s6t        dj                  t	        |      t	        t        |                         y )Nz2Value of last entry must be of type "{}", got "{}")r   
isinstance
ValueErrorformatr   type)valueresult_types     r   _validate_is_result_typer       sK    ce[)@GG!+.!$u+.
 	
 *r   c                      e Zd ZdZej
                  dd       Zej
                  d	d       Zej
                  d
d       Zej
                  dd       Z	ej
                  d	d       Z
y)LLMFnOutputRowViewz!Immutable view of LLMFnOutputRow.c                     y)z)For expressions like: x in this_instance.N selfks     r   __contains__zLLMFnOutputRowView.__contains__0       r   c                     y)z)For expressions like: str(this_instance).Nr   r   s    r   __str__zLLMFnOutputRowView.__str__4   r   r   c                     y)z.Returns the type enforced for the result cell.Nr   r!   s    r   r   zLLMFnOutputRowView.result_type9   r   r   c                     y)z!Get the value of the result cell.Nr   r!   s    r   result_valuezLLMFnOutputRowView.result_value=   r   r   c                     y)zGet the key of the result cell.Nr   r!   s    r   
result_keyzLLMFnOutputRowView.result_keyA   r   r   Nr   r
   returnboolr)   r
   r)   	type[Any]r)   r   )r   
__module____qualname____doc__abcabstractmethodr   r"   r   r%   r'   r   r   r   r   r   ,   s    + 	8 8 	8 8 	= = 	0 0 	. .r   r   )	metaclassc                  j    e Zd ZdZddZddZddZddZddZddZ	ddZ
dd	Zdd
ZdddZddZy)LLMFnOutputRowa  Container that represents a single row in a table of outputs.

    We represent outputs as a table. This class represents a single row in the
    table like a dictionary, where the key is the column name and the value is the
    cell value.

    A single cell is designated the "result". This contains the output of the LLM
    model after running any post-processing functions specified by the user.

    In addition to behaving like a dictionary, this class provides additional
    methods, including:
    - Getting the value of the "result" cell
    - Setting the value (and optionally the key) of the "result" cell.
    - Add a new non-result cell

    Notes: As an implementation detail, the result-cell is always kept as the
    rightmost cell.
    c                    t        |      | _        | j                  st        d      || _        t	        | j                  j                               d   }t        || j                         y)a*  Constructor.

        Args:
          data: The initial value of the row. The last entry will be treated as the
            result. Cannot be empty. The value of the last entry must be `str`.
          result_type: The type of the result cell. This will be enforced at
            runtime.
        zMust provide non-empty dataN)dict_datar   _result_typelistvaluesr   )r   datar   r%   s       r   __init__zLLMFnOutputRow.__init__Z   sV     15T

zz:;;'DJJ--/04 t/@/@Ar   c                6    | j                   j                         S N)r:   __iter__r!   s    r   rB   zLLMFnOutputRow.__iter__l   s    zz""$$r   c                6    | j                   j                         S rA   )r:   __len__r!   s    r   rD   zLLMFnOutputRow.__len__o   s    zz!!##r   c                8    | j                   j                  |      S rA   )r:   __getitem__r   s     r   rF   zLLMFnOutputRow.__getitem__r   s    zz%%a((r   c                8    | j                   j                  |      S rA   )r:   r   r   s     r   r   zLLMFnOutputRow.__contains__v   s    zz&&q))r   c                T    dj                  | j                  j                               S )NzLLMFnOutputRow: {})r   r:   r"   r!   s    r   r"   zLLMFnOutputRow.__str__y   s     #**4::+=+=+?@@r   c                    | j                   S rA   )r;   r!   s    r   r   zLLMFnOutputRow.result_type|   s       r   c                <    | j                   | j                            S rA   )r:   r'   r!   s    r   r%   zLLMFnOutputRow.result_value   s    zz$//+,,r   c                N    t        | j                  j                               d   S )Nr8   )r<   r:   keysr!   s    r   r'   zLLMFnOutputRow.result_key   s    DJJOO%&r**r   Nc                    t        || j                         | j                         }|||k(  r|| j                  |<   y| j                  |= || j                  |<   y)zSet the value of the result cell.

        Sets the value (and optionally the key) of the result cell.

        Args:
          value: The value to set the result cell today.
          key: Optionally change the key as well.
        N)r   r;   r'   r:   )r   r   keycurrent_keys       r   set_result_valuezLLMFnOutputRow.set_result_value   sV     	!(9(9:oo';#,&+DJJ{#JJ{#

3r   c                &   || j                   v r:d}|}|| j                   v r&dj                  ||      }|dz   }|| j                   v r&|}| j                         }| j                   j                  |      }|| j                   |<   || j                   |<   y)zAdd a non-result cell.

        Adds a new non-result cell. This does not affect the result cell.

        Args:
          key: The key of the new cell to add.
          value: The value of the new cell to add.
           z{}_{}N)r:   r   r'   pop)r   rN   r   idxcandidate_keyr'   r%   s          r   addzLLMFnOutputRow.add   s     $**CM4::- 'sC 8Ag  4::-  C __&
zz~~j1

3!-

:r   )r>   zMapping[str, _CELLVALUETYPE]r   r-   )r)   zIterator[str])r)   int)r   r
   r)   _CELLVALUETYPEr(   r+   r,   r.   rA   )r   r   rN   z
str | Noner)   None)rN   r
   r   rX   r)   rY   )r   r/   r0   r1   r?   rB   rD   rF   r   r"   r   r%   r'   rP   rV   r   r   r   r6   r6   F   s@    &B$%$)*A!-+
 &.r   r6   )r   r-   r)   r
   )r   r   r   r-   r)   rY   )r1   
__future__r   r2   typingr   r   r   rX   r   r   r
   ABCMetar   r6   r   r   r   <module>r]      sR     " 
 ) ) 	
.n!45 .4k.' k.r   