
    ; i                        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dS )zLLMFnOutputRow.    )annotationsN)AnyIteratorMappingx	type[Any]returnstrc                N    t          | d          r| j        S t          |           S )N__name__)hasattrr   r
   )r   s    /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/notebook/lib/llmfn_output_row.py_get_name_of_typer      s'    q* zq66M    valuer   result_typeNonec           
         |t           k    rd S t          | |          sJt          d                    t	          |          t	          t          |                                         d S )Nz2Value of last entry must be of type "{}", got "{}")r   
isinstance
ValueErrorformatr   type)r   r   s     r   _validate_is_result_typer       so    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
dS )LLMFnOutputRowViewz!Immutable view of LLMFnOutputRow.kr
   r	   boolc                    dS )z)For expressions like: x in this_instance.N selfr   s     r   __contains__zLLMFnOutputRowView.__contains__0         r   c                    dS )z)For expressions like: str(this_instance).Nr   r!   s    r   __str__zLLMFnOutputRowView.__str__4   r#   r   r   c                    dS )z.Returns the type enforced for the result cell.Nr   r%   s    r   r   zLLMFnOutputRowView.result_type9   r#   r   r   c                    dS )z!Get the value of the result cell.Nr   r%   s    r   result_valuezLLMFnOutputRowView.result_value=   r#   r   c                    dS )zGet the key of the result cell.Nr   r%   s    r   
result_keyzLLMFnOutputRowView.result_keyA   r#   r   Nr   r
   r	   r   r	   r
   r	   r   r	   r   )r   
__module____qualname____doc__abcabstractmethodr"   r&   r   r)   r+   r   r   r   r   r   ,   s        ++ 	8 8 8 8 	8 8 8 8 	= = = = 	0 0 0 0 	. . . . . .r   r   )	metaclassc                  l    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dS ))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.
    dataMapping[str, _CELLVALUETYPE]r   r   c                    t          |          | _        | j        st          d          || _        t	          | j                                                  d         }t          || j                   dS )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!   r8   r   r)   s       r   __init__zLLMFnOutputRow.__init__Z   sk     15T


z 	<:;;;'DJ--//004 t/@AAAAAr   r	   Iterator[str]c                4    | j                                         S N)r=   __iter__r%   s    r   rE   zLLMFnOutputRow.__iter__l   s    z""$$$r   intc                4    | j                                         S rD   )r=   __len__r%   s    r   rH   zLLMFnOutputRow.__len__o   s    z!!###r   r   r
   _CELLVALUETYPEc                6    | j                             |          S rD   )r=   __getitem__r    s     r   rK   zLLMFnOutputRow.__getitem__r   s    z%%a(((r   r   c                6    | j                             |          S rD   )r=   r"   r    s     r   r"   zLLMFnOutputRow.__contains__v   s    z&&q)))r   c                Z    d                     | j                                                  S )NzLLMFnOutputRow: {})r   r=   r&   r%   s    r   r&   zLLMFnOutputRow.__str__y   s$    #**4:+=+=+?+?@@@r   c                    | j         S rD   )r>   r%   s    r   r   zLLMFnOutputRow.result_type|   s      r   r   c                @    | j         |                                          S rD   )r=   r+   r%   s    r   r)   zLLMFnOutputRow.result_value   s    z$//++,,r   c                Z    t          | j                                                  d         S )Nr;   )r?   r=   keysr%   s    r   r+   zLLMFnOutputRow.result_key   s!    DJOO%%&&r**r   Nr   key
str | Noner   c                    t          || j                   |                                 }|||k    r|| j        |<   dS | j        |= || j        |<   dS )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   rR   current_keys       r   set_result_valuezLLMFnOutputRow.set_result_value   s_     	!(9:::oo'';#,,&+DJ{#FJ{#
3r   c                   || j         v r3d}|}|| j         v r$d                    ||          }|dz   }|| j         v $|}|                                 }| j                             |          }|| j         |<   || j         |<   dS )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!   rR   r   idxcandidate_keyr+   r)   s          r   addzLLMFnOutputRow.add   s     $*CM4:-- 'sC 8 8Ag  4:--  C __&&
z~~j11
3!-
:r   )r8   r9   r   r   )r	   rB   )r	   rF   )r   r
   r	   rI   r,   r-   r.   r/   rD   )r   r   rR   rS   r	   r   )rR   r
   r   rI   r	   r   )r   r0   r1   r2   rA   rE   rH   rK   r"   r&   r   r)   r+   rV   r\   r   r   r   r7   r7   F   s        &B B B B$% % % %$ $ $ $) ) ) )* * * *A A A A! ! ! !- - - -+ + + +
         &. . . . . .r   r7   )r   r   r	   r
   )r   r   r   r   r	   r   )r2   
__future__r   r3   typingr   r   r   rI   r   r   r
   ABCMetar   r7   r   r   r   <module>r`      s      " " " " " " 



 ) ) ) ) ) ) ) ) ) )    	
 	
 	
 	
. . . . .n!45 . . . .4k. k. k. k. k.' k. k. k. k. k.r   