o
    bÆi™  ã                   @  sz   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 e	j
Zeeee f Zeee	jf Zdd	d
„Zddd„Zddd„ZdS )z'Utilities for handling input variables.é    )Úannotations)ÚAnyÚMappingÚSequenceÚUnion)Úllmfn_inputs_sourceÚinputsr   ÚreturnÚboolc                 C  sJ   t | tƒsdS |  ¡ D ]}t |tƒs dS t |tƒst |tƒr" dS qdS )a*  See if inputs is of the form: {"key1": ["val1", "val2", ...]}.

    This is similar to the format produced by:
      pandas.DataFrame.to_dict(orient="list")

    Args:
      inputs: The inputs passed into an LLMFunction.

    Returns:
      Whether `inputs` is a column-ordered list of values.
    FT)Ú
isinstancer   Úvaluesr   ÚstrÚbytes)r   Úx© r   úl/home/kim/smarthome/.venv/lib/python3.10/site-packages/google/generativeai/notebook/lib/llmfn_input_utils.pyÚ_is_column_order_values_list   s   

ÿr   Ú_ColumnOrderValuesListÚ_NormalizedInputsListc                 C  s^   g }t |  ¡ ƒ}|r-|d }tt| | ƒƒD ]}i }| |¡ |D ]
}| | | ||< q!q|S )z5Transforms prompt inputs into a list of dictionaries.r   )ÚlistÚkeysÚrangeÚlenÚappend)r   Zreturn_listr   Z	first_keyZrow_numZrow_dictÚkeyr   r   r   Ú#_normalize_column_order_values_list8   s   
ÿr   ÚLLMFunctionInputsc                 C  sJ   g }t | tjƒr| |  ¡ ¡ |S t| ƒr| t| ƒ¡ |S td | ¡ƒ‚)zFHandles the different types of `inputs` and returns a normalized form.zUnsupported input type {!r})	r   r   ÚLLMFnInputsSourceÚextendÚto_normalized_inputsr   r   Ú
ValueErrorÚformat)r   Znormalized_inputsr   r   r   r   H   s   üÿr   N)r   r   r	   r
   )r   r   r	   r   )r   r   r	   r   )Ú__doc__Ú
__future__r   Útypingr   r   r   r   Z google.generativeai.notebook.libr   ZNormalizedInputsListr   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   

