U
    “öh&  ã                   @  sŒ   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œdd	„Zd
ddœdd„Zdddœdd„ZdS )z'Utilities for handling input variables.é    )Úannotations)ÚAnyÚMappingÚSequenceÚUnion)Úllmfn_inputs_sourcer   Úbool)ÚinputsÚreturnc                 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   úV/tmp/pip-unpacked-wheel-doshhd5e/google/generativeai/notebook/lib/llmfn_input_utils.pyÚ_is_column_order_values_list!   s    

r   Ú_ColumnOrderValuesListÚ_NormalizedInputsListc                 C  s^   g }t |  ¡ ƒ}|rZ|d }tt| | ƒƒD ],}i }| |¡ |D ]}| | | ||< qBq,|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_list;   s    
r   ÚLLMFunctionInputsc                 C  sJ   g }t | tjƒr | |  ¡ ¡ n&t| ƒr8| t| ƒ¡ ntd | ¡ƒ‚|S )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   K   s    r   N)Ú__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   ÿÿ