
    ; i"                       d dl mZ d dlmZmZmZ d dlmc mZ	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ 	 	 	 	 d%d&dZ	 	 	 	 d%d'dZ	 	 d(d)dZ	 	 d(d*dZ	 	 	 d+d,dZ	 	 	 d+d-dZddddd.d"Zddddd/d$ZdS )0    )annotations)AsyncIterableIterableOptionalN)protos)get_default_retriever_client)"get_default_retriever_async_client)helper_types)idecode_time)retriever_typesname
str | Nonedisplay_nameclient!glm.RetrieverServiceClient | Nonerequest_options&helper_types.RequestOptionsType | Nonereturnretriever_types.Corpusc                   |i }|t                      }| t          j        |          }nit          j        |           rt          j        d|  |          }n;t          t          j                            t          |           |                     t          j	        |          } |j
        |fi |}t          |                              |          }t          |d           t          |d           t          j        d	i |}|S )
a  Calls the API to create a new `Corpus` by specifying either a corpus resource name as an ID or a display name, and returns the created `Corpus`.

    Args:
        name: The corpus resource name (ID). The name must be alphanumeric and fewer
            than 40 characters.
        display_name: The human readable display name. The display name must be fewer
            than 128 characters. All characters, including alphanumeric, spaces, and
            dashes are supported.
        request_options: Options for the request.

    Return:
        `retriever_types.Corpus` object with specified name or display name.

    Raises:
        ValueError: When the name is not specified or formatted incorrectly.
    Nr   corpora/r   r   lengthr   corpuscreate_timeupdate_time )r   r   Corpusr   
valid_name
ValueErrorNAME_ERROR_MSGformatlenCreateCorpusRequestcreate_corpustypeto_dictr   r   r   r   r   r   requestresponses          u/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/retriever.pyr(   r(      s   , ~-//|L999		#D	)	) ]$5t$5$5LQQQ7>>c$iiVZ>[[\\\(777G#v#G????HH~~%%h//H=)))=)))%1111HO    &glm.RetrieverServiceAsyncClient | Nonec                ,  K   |i }|t                      }| t          j        |          }nit          j        |           rt          j        d|  |          }n;t          t          j                            t          |           |                     t          j	        |          } |j
        |fi | d{V }t          |                              |          }t          |d           t          |d           t          j        d	i |}|S )
z7This is the async version of `retriever.create_corpus`.Nr   r   r   r   r   r   r   r    )r	   r   r!   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   r+   s          r.   create_corpus_asyncr2   J   s-      ~355|L999		#D	)	) ]$5t$5$5LQQQ7>>c$iiVZ>[[\\\(777G)V)'EE_EEEEEEEEHH~~%%h//H=)))=)))%1111HOr/   strc                ,   |i }|t                      }d| vrd| z   } t          j        |           } |j        |fi |}t	          |                              |          }t          |d           t          |d           t          j        di |}|S )zCalls the API to fetch a `Corpus` by name and returns the `Corpus`.

    Args:
        name: The `Corpus` name.
        request_options: Options for the request.

    Return:
        a `retriever_types.Corpus` of interest.
    N/r   r   r   r   r    )	r   r   GetCorpusRequest
get_corpusr)   r*   r   r   r!   r   r   r   r,   r-   s        r.   r8   r8   g   s     ~-//
$D %4000G v <<O<<HH~~%%h//H=)))=)))%1111HOr/   c                <  K   |i }|t                      }d| vrd| z   } t          j        |           } |j        |fi | d{V }t	          |                              |          }t          |d           t          |d           t          j        di |}|S )z4This is the async version of `retriever.get_corpus`.Nr5   r   r6   r   r   r    )	r	   r   r7   r8   r)   r*   r   r   r!   r9   s        r.   get_corpus_asyncr;      s       ~355
$D %4000G&V&wBB/BBBBBBBBHH~~%%h//H=)))=)))%1111HOr/   Fforceboolc                    |i }|t                      }d| vrd| z   } t          j        | |          } |j        |fi | dS )ab  Calls the API to remove a `Corpus` from the service, optionally deleting associated `Document`s and objects if the `force` parameter is set to true.

    Args:
        name: The `Corpus` name.
        force: If set to true, any `Document`s and objects related to this `Corpus` will also be deleted.
        request_options: Options for the request.

    Nr5   r   r   r<   )r   r   DeleteCorpusRequestdelete_corpusr   r<   r   r   r,   s        r.   rA   rA      sh     ~-//
$D (d%@@@GF44O44444r/   c                   K   |i }|t                      }d| vrd| z   } t          j        | |          } |j        |fi | d{V  dS )z7This is the async version of `retriever.delete_corpus`.Nr5   r   r?   )r	   r   r@   rA   rB   s        r.   delete_corpus_asyncrD      s~       ~355
$D (d%@@@G
&
w
:
:/
:
::::::::::r/   )	page_sizer   r   rE   Optional[int] Iterable[retriever_types.Corpus]c              #  (  K   |i }|t                      }t          j        |           } |j        |fi |D ]W}t	          |                              |          }t          |d           t          |d           t          j        di |V  XdS )aY  Calls the API to list all `Corpora` in the service and returns a list of paginated `Corpora`.

    Args:
        page_size: Maximum number of `Corpora` to request.
        page_token: A page token, received from a previous ListCorpora call.
        request_options: Options for the request.

    Return:
        Paginated list of `Corpora`.
    NrE   r   r   r    )	r   r   ListCorporaRequestlist_corporar)   r*   r   r   r!   rE   r   r   r,   r   s        r.   rK   rK      s        ~-//')<<<G%&%gAAAA / /f%%f--V]+++V]+++$..v......	/ /r/   %AsyncIterable[retriever_types.Corpus]c               B  K   |i }|t                      }t          j        |           } |j        |fi | d{V 2 3 d{V }t	          |                              |          }t          |d           t          |d           t          j        di |W V  ^6 dS )z6This is the async version of `retriever.list_corpora`.NrI   r   r   r    )	r	   r   rJ   rK   r)   r*   r   r   r!   rL   s        r.   list_corpora_asyncrO      s       ~355')<<<G1f1'MM_MMMMMMMM / / / / / / /ff%%f--V]+++V]+++$..v.......	 NMMs    B)NNNN)
r   r   r   r   r   r   r   r   r   r   )
r   r   r   r   r   r0   r   r   r   r   )NN)r   r3   r   r   r   r   r   r   )r   r3   r   r0   r   r   r   r   )FNN)r   r3   r<   r=   r   r   r   r   )r   r3   r<   r=   r   r0   r   r   )rE   rF   r   r   r   r   r   rG   )rE   rF   r   r   r   r   r   rM   )
__future__r   typingr   r   r   google.ai.generativelanguageaigenerativelanguageglmgoogle.generativeair   google.generativeai.clientr   r	   google.generativeai.typesr
   %google.generativeai.types.model_typesr   r   r(   r2   r8   r;   rA   rD   rK   rO   r    r/   r.   <module>rZ      s   # " " " " " 5 4 4 4 4 4 4 4 4 4 * * * * * * * * * & & & & & & C C C C C C I I I I I I 2 2 2 2 2 2 > > > > > > 5 5 5 5 5 5 #04>B	) ) ) ) )Z #59>B	    > 15>B    D 6:>B    6 04>B	5 5 5 5 5: 59>B	; ; ; ; ;,  $04>B	/ / / / / /@  $04>B	/ / / / / / / /r/   