Ë
    ümxiT!  ã                  ó  — d Z ddlmZ ddl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 ddlmZ ddlZ G d„ d«      Zej&                   G d	„ d
«      «       Zdd„Z G d„ dee   «      Z G d„ dej.                  «      Z G d„ de«      Zy)zOutput of LLMFunction.é    )ÚannotationsN)ÚoverloadÚAnyÚCallableÚIterableÚIteratorÚMappingÚSequence)Úllmfn_output_row)Úmodelc                  ó(   — e Zd ZdZdZdZdZdZdZdZ	y)	ÚColumnNamesz3Names of columns that are used to represent output.z
Prompt Numz	Input Numz
Result NumÚPromptzPrompt varsÚtext_resultN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
PROMPT_NUMÚ	INPUT_NUMÚ
RESULT_NUMÚMODEL_INPUTÚPROMPT_VARSÚTEXT_RESULT© ó    úe/home/htdocs/ttos/venv/lib/python3.12/site-packages/google/generativeai/notebook/lib/llmfn_outputs.pyr   r   #   s%   „ Ù=à€JØ€IØ€Jð
 €KØ€KØ�Kr   r   c                  ód   — e Zd ZU dZded<   ded<   ded<   ded<   d	Zd
ed<   d	Zd
ed<   d	Zded<   y	)ÚLLMFnOutputEntryaê  The output of a single model input from LLMFunction.

    A model input is a prompt where the keyword placeholders have been
    substituted (by `prompt_vars`).

    E.g. If we have:
      prompt: "the opposite of {word} is"
      prompt_vars: {"word", "hot"}
    Then we will have the following model input:
      model_input: "the opposite of hot is"

    Note: The model may produce one-or-more results for a given model_input.
    This is represented by the sequence `output_rows`.
    ÚintÚ
prompt_numÚ	input_numzMapping[str, str]Úprompt_varsz)Sequence[llmfn_output_row.LLMFnOutputRow]Úoutput_rowsNz
str | NoneÚpromptÚmodel_inputzmodel_lib.ModelResults | NoneÚmodel_results)r   r   r   r   Ú__annotations__r%   r&   r'   r   r   r   r   r   2   s>   … ñð ƒOØƒNØ"Ó"Ø:Ó:à€FˆJÓØ"€K�Ó"Ø37€MÐ0Ô7r   r   c                ó.   — | D ]  }|j                   €Œ y y)NTF)r&   )ÚoutputsÚentrys     r   Ú_has_model_input_fieldr,   M   s%   € Øò ˆØ×ÑÑ(Ùðð r   c                  óz   — e Zd ZdZ	 d	 dd„Zdd„Zdd„Zedd„«       Zedd„«       Zdd„Zdd	„Z	dd
„Z
dd„Zdd„Zy)ÚLLMFnOutputsBasezÄParent class for LLMFnOutputs.

    This class exists mainly to avoid a circular dependency between LLMFnOutputs
    and LLMFnOutputsSink. Most users should use LLMFnOutputs directly instead.
    Nc                ó8   — |�t        |«      | _        yg | _        y)zcConstructor.

        Args:
          outputs: The contents of this LLMFnOutputs instance.
        N)ÚlistÚ_outputs©Úselfr*   s     r   Ú__init__zLLMFnOutputsBase.__init__[   s   € ð BIÐAT´°W³ˆ�ÐZ\ˆ�r   c                ó6   — | j                   j                  «       S ©N)r1   Ú__iter__©r3   s    r   r7   zLLMFnOutputsBase.__iter__g   s   € Ø�}‰}×%Ñ%Ó'Ð'r   c                ó6   — | j                   j                  «       S r6   )r1   Ú__len__r8   s    r   r:   zLLMFnOutputsBase.__len__k   s   € Ø�}‰}×$Ñ$Ó&Ð&r   c                 ó   — y r6   r   ©r3   Úxs     r   Ú__getitem__zLLMFnOutputsBase.__getitem__o   s   € Ø7:r   c                 ó   — y r6   r   r<   s     r   r>   zLLMFnOutputsBase.__getitem__r   s   € ØCFr   c                ó8   — | j                   j                  |«      S r6   )r1   r>   r<   s     r   r>   zLLMFnOutputsBase.__getitem__u   s   € Ø�}‰}×(Ñ(¨Ó+Ð+r   c                ó,   — t        | j                  «      S r6   )Úboolr1   r8   s    r   Ú__bool__zLLMFnOutputsBase.__bool__y   s   € Ü�D—M‘MÓ"Ð"r   c                ó>   — | j                  «       j                  «       S r6   )Úas_pandas_dataframeÚ__str__r8   s    r   rF   zLLMFnOutputsBase.__str__|   s   € Ø×'Ñ'Ó)×1Ñ1Ó3Ð3r   c                óŒ  — t         j                  g t         j                  g t         j                  g i}t	        | j
                  «      rg |t         j                  <   | j
                  s|S |j                  «       D �ci c]  }|d“Œ }}| j
                  D ]9  }|j                  D ](  }t        |j                  «       «      dd D ]  }d||<   Œ	 Œ* Œ; | j
                  D ]2  }|j                  D ]!  }d|t        |j                  «       «      d   <   Œ# Œ4 |D ]  }g ||<   Œ	 d}| j
                  D �]  }|j                  D ]ÿ  }|t         j                     j                  |j                  «       |t         j                     j                  |j                  «       t         j                  |v r,|t         j                     j                  |j                  «       |j                  «       D ]  \  }}||   j                  |«       Œ |j                  «       D ]"  }	t!        |	«      |k  sŒ|	j                  d«       Œ$ |dz  }�Œ �Œ |S c c}w )z'Formats returned results as dictionary.Néÿÿÿÿé   )r   r   r   r   r,   r1   r   Úkeysr$   r0   Úappendr!   r"   r&   ÚitemsÚvaluesÚlen)
r3   ÚdataÚkÚtotal_keys_setÚoutputÚresultÚkeyÚnext_num_rowsÚvalueÚcolumns
             r   Úas_dictzLLMFnOutputsBase.as_dict€   s7  € ô ×"Ñ" BÜ×!Ñ! 2ô ×"Ñ" Bð
ˆô " $§-¡-Ô0Ø,.ˆD”×(Ñ(Ñ)à�}Š}ØˆKð =A¿I¹I»KÖ*H°q¨1¨d©7Ð*HˆÐ*HØ—m‘mò 	/ˆFØ ×,Ñ,ò /�Ü §¡£Ó.¨s°Ð3ò /�CØ*.�N 3Ò'ñ/ñ/ð	/ð —m‘mò 	?ˆFØ ×,Ñ,ò ?�Ø:>�œt F§K¡K£MÓ2°2Ñ6Ò7ñ?ð	?ð "ò 	ˆCØˆD�ŠIð	ð ˆØ—m‘mó 	#ˆFØ ×,Ñ,ò #�Ø”[×+Ñ+Ñ,×3Ñ3°F×4EÑ4EÔFØ”[×*Ñ*Ñ+×2Ñ2°6×3CÑ3CÔDÜ×*Ñ*¨dÑ2Øœ×0Ñ0Ñ1×8Ñ8¸×9KÑ9KÔLà"(§,¡,£.ò ,‘J�C˜Ø˜‘I×$Ñ$ UÕ+ð,ð #Ÿk™k›mò ,�FÜ˜6“{ ]Ó2ØŸ™ dÕ+ð,ð  Ñ"’ò#ð	#ð" ˆùòA +Is   Á;
Ic                óH   — t        j                  | j                  «       «      S r6   )ÚpandasÚ	DataFramerX   r8   s    r   rE   z$LLMFnOutputsBase.as_pandas_dataframe¼   s   € Ü×Ñ §¡£Ó/Ð/r   r6   )r*   ú!Iterable[LLMFnOutputEntry] | None)ÚreturnzIterator[LLMFnOutputEntry])r]   r    )r=   r    r]   r   )r=   Úslicer]   zSequence[LLMFnOutputEntry])r=   zint | slicer]   z-LLMFnOutputEntry | Sequence[LLMFnOutputEntry])r]   rB   )r]   Ústr)r]   zMapping[str, Sequence[Any]])r]   zpandas.DataFrame)r   r   r   r   r4   r7   r:   r   r>   rC   rF   rX   rE   r   r   r   r.   r.   T   s]   „ ñð 6:ð	]à2ó	]ó(ó'ð Ú:ó Ø:àÚFó ØFó,ó#ó4ó:ôx0r   r.   c                  ó   — e Zd ZdZdd„Zy)ÚLLMFnOutputsSinkz¨Abstract class representing an exporter for the output of LLMFunction.

    This class could be extended to write to external documents, such as
    Google Sheets.
    c                 ó   — y)z%Writes `outputs` to some destination.Nr   r2   s     r   Úwrite_outputszLLMFnOutputsSink.write_outputsÇ   s   � r   N)r*   r.   r]   ÚNone)r   r   r   r   rc   r   r   r   ra   ra   À   s   „ ñô4r   ra   c                  ó>   ‡ — e Zd ZdZ	 	 d	 	 	 dˆ fd„Zd„ Zdd„Zˆ xZS )ÚLLMFnOutputsa  A sequence of LLMFnOutputEntry instances.

    Notes:
    - Each LLMFnOutputEntry represents the results of running one model
      input (see documentation for LLMFnOutputEntry for what "model input"
      means.)
    - A single model input may produce more-than-one text results.
    c                óh   •— t         ‰| �  |¬«       |r|| _        t        | dt	        | d«      «       yy)a  Constructor.

        Args:
          outputs: The contents of this LLMFnOutputs instance.
          ipython_display_fn: An optional function for pretty-printing this instance
            when it is the output of a cell in a notebook. If this argument is not
            None, the _ipython_display_ method will be defined which will in turn
            invoke this function.
        )r*   Ú_ipython_display_Ú_ipython_display_implN)Úsuperr4   Ú_ipython_display_fnÚsetattrÚgetattr)r3   r*   Úipython_display_fnÚ	__class__s      €r   r4   zLLMFnOutputs.__init__Õ   s@   ø€ ô 	‰Ñ ÐÔ)áØ'9ˆDÔ$ô
 ØØ#Ü˜Ð5Ó6õð r   c                ó&   — | j                  | «       y)z‰Actual implementation of _ipython_display_.

        This method should only be used invoked if self._ipython_display_fn is set.
        N)rk   r8   s    r   ri   z"LLMFnOutputs._ipython_display_implñ   s   € ð
 	× Ñ  Õ&r   c                ó&   — |j                  | «       y)zExport contents to `sink`.N)rc   )r3   Úsinks     r   ÚexportzLLMFnOutputs.exportø   s   € à×Ñ˜4Õ r   )NN)r*   r\   rn   z%Callable[[LLMFnOutputs], None] | None)rr   ra   r]   rd   )r   r   r   r   r4   ri   rs   Ú__classcell__)ro   s   @r   rf   rf   Ë   s2   ø„ ñð 6:ØDHðà2ðð Bõò8'÷!r   rf   )r*   zIterable[LLMFnOutputEntry])r   Ú
__future__r   ÚabcÚdataclassesÚtypingr   r   r   r   r   r	   r
   Ú google.generativeai.notebook.libr   r   Ú	model_librZ   r   Ú	dataclassr   r,   r.   ÚABCra   rf   r   r   r   ú<module>r}      s�   ðñ Ý "ã 
Û ÷÷ ñ õ >Ý ?Û ÷ ñ  ð ×Ñ÷8ð 8ó ð8ó4ôi0�xÐ 0Ñ1ô i0ôX4�s—w‘wô 4ô/!Ð#õ /!r   