
    rhT!                       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     /var/www/html/ai-insurance-compliance-backend/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""::FJ"K"37M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)LLMFnOutputsBasezParent 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    DMM""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IIK*Hq1d7*H*Hmm 	/F ,, /.s3 /C*.N3'//	/ mm 	?F ,, ?:>tFKKM2267?	? " 	CDI	 mm 	#F ,, #[++,33F4E4EF[**+2263C3CD**d2001889K9KL"(,,. ,JCI$$U+, #kkm ,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)LLMFnOutputsSinkzAbstract 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@     	)'9D$
 #56 r   c                &    | j                  |        y)zActual 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 84i0x 01 i0X4sww 4/!# /!r   