o
    i3                     @   s   d dl Z d dlmZ ddlmZ ddlmZmZ ddlm	Z	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lmZ ddlmZ ddlmZ ddlmZ e e j dZ!G dd dZ"G dd dZ#dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)RequestOptions)'convert_and_respect_annotation_metadata)construct_type)BadRequestError)ReadV1RequestParams)ReadV1Response   ) TextAnalyzeRequestCallbackMethod)"TextAnalyzeRequestCustomIntentMode)!TextAnalyzeRequestCustomTopicMode)TextAnalyzeRequestSummarize.c                    @      e Zd ZdefddZdddddddddddddddedeje deje	 d	eje
 d
eje dejejeeje f  deje
 dejejeeje f  deje deje
 dejejeeje f  deje deje deje dee fddZdS )RawTextClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   T/home/ubuntu/.local/lib/python3.10/site-packages/deepgram/read/v1/text/raw_client.py__init__      
zRawTextClient.__init__Ncallbackcallback_method	sentiment	summarizetagtopicscustom_topiccustom_topic_modeintentscustom_intentcustom_intent_modelanguagerequest_optionsrequestr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   returnc                C   s  | j jjd| j  jd||||||||	|
|||dt|tddddi|td}z@d	|j  kr3d
k rHn nt	
ttt| d}t||dW S |jdkrbtt|jt	
t	jtt	j| dd| }W n tyz   t|jt|j|jdw t|jt|j|d)aI
  
        Analyze text content using Deepgrams text analysis API

        Parameters
        ----------
        request : ReadV1RequestParams

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[TextAnalyzeRequestCallbackMethod]
            HTTP method by which the callback request will be made

        sentiment : typing.Optional[bool]
            Recognizes the sentiment throughout a transcript or text

        summarize : typing.Optional[TextAnalyzeRequestSummarize]
            Summarize content. For Listen API, supports string version option. For Read API, accepts boolean only.

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        topics : typing.Optional[bool]
            Detect topics throughout a transcript or text

        custom_topic : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Custom topics you want the model to detect within your input audio or text if present Submit up to `100`.

        custom_topic_mode : typing.Optional[TextAnalyzeRequestCustomTopicMode]
            Sets how the model will interpret strings submitted to the `custom_topic` param. When `strict`, the model will only return topics submitted using the `custom_topic` param. When `extended`, the model will return its own detected topics in addition to those submitted using the `custom_topic` param

        intents : typing.Optional[bool]
            Recognizes speaker intent throughout a transcript or text

        custom_intent : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Custom intents you want the model to detect within your input audio if present

        custom_intent_mode : typing.Optional[TextAnalyzeRequestCustomIntentMode]
            Sets how the model will interpret intents submitted to the `custom_intent` param. When `strict`, the model will only return intents submitted using the `custom_intent` param. When `extended`, the model will return its own detected intents in the `custom_intent` param.

        language : typing.Optional[str]
            The [BCP-47 language tag](https://tools.ietf.org/html/bcp47) that hints at the primary spoken language. Depending on the Model and API endpoint you choose only certain languages are available

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ReadV1Response]
            Successful text analysis
        v1/readPOSTr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   writeobject_
annotation	directioncontent-typeapplication/jsonbase_urlmethodparamsjsonheadersr.   omit   ,  type_r6   responsedata  r@   bodystatus_coder@   rK   )r   httpx_clientr/   get_environmentbaser
   r   OMITrM   typingcastr   r   r?   r   r   dictr@   Anyr   r   textr   r/   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   	_response_data_response_jsonr   r   r   analyze   sf   E


zRawTextClient.analyze)__name__
__module____qualname__r   r   r   rR   Optionalstrr   boolr   UnionSequencer   r   r	   r   r   r[   r   r   r   r   r      \    	
r   c                    @   r   )AsyncRawTextClientr   c                C   r   r   r   r   r   r   r   r      r    zAsyncRawTextClient.__init__Nr!   r/   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   c                   s  | j jjd| j  jd||||||||	|
|||dt|tddddi|tdI d	H }z@d
|j  kr7dk rLn nt	
ttt| d}t||dW S |jdkrftt|jt	
t	jtt	j| dd| }W n ty~   t|jt|j|jdw t|jt|j|d)aN
  
        Analyze text content using Deepgrams text analysis API

        Parameters
        ----------
        request : ReadV1RequestParams

        callback : typing.Optional[str]
            URL to which we'll make the callback request

        callback_method : typing.Optional[TextAnalyzeRequestCallbackMethod]
            HTTP method by which the callback request will be made

        sentiment : typing.Optional[bool]
            Recognizes the sentiment throughout a transcript or text

        summarize : typing.Optional[TextAnalyzeRequestSummarize]
            Summarize content. For Listen API, supports string version option. For Read API, accepts boolean only.

        tag : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Label your requests for the purpose of identification during usage reporting

        topics : typing.Optional[bool]
            Detect topics throughout a transcript or text

        custom_topic : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Custom topics you want the model to detect within your input audio or text if present Submit up to `100`.

        custom_topic_mode : typing.Optional[TextAnalyzeRequestCustomTopicMode]
            Sets how the model will interpret strings submitted to the `custom_topic` param. When `strict`, the model will only return topics submitted using the `custom_topic` param. When `extended`, the model will return its own detected topics in addition to those submitted using the `custom_topic` param

        intents : typing.Optional[bool]
            Recognizes speaker intent throughout a transcript or text

        custom_intent : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Custom intents you want the model to detect within your input audio if present

        custom_intent_mode : typing.Optional[TextAnalyzeRequestCustomIntentMode]
            Sets how the model will interpret intents submitted to the `custom_intent` param. When `strict`, the model will only return intents submitted using the `custom_intent` param. When `extended`, the model will return its own detected intents in the `custom_intent` param.

        language : typing.Optional[str]
            The [BCP-47 language tag](https://tools.ietf.org/html/bcp47) that hints at the primary spoken language. Depending on the Model and API endpoint you choose only certain languages are available

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ReadV1Response]
            Successful text analysis
        r1   r2   r3   r4   r5   r9   r:   r;   NrB   rC   rD   rF   rI   rJ   rL   )r   rN   r/   rO   rP   r
   r   rQ   rM   rR   rS   r   r   r?   r   r   rT   r@   rU   r   r   rV   rW   r   r   r   r[      sh   E


zAsyncRawTextClient.analyze)r\   r]   r^   r   r   r   rR   r_   r`   r   ra   r   rb   rc   r   r   r	   r   r   r[   r   r   r   r   re      rd   re   )$rR   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.request_optionsr	   core.serializationr
   core.unchecked_base_modelr   errors.bad_request_errorr   requests.read_v1requestr   types.read_v1responser   *types.text_analyze_request_callback_methodr   -types.text_analyze_request_custom_intent_moder   ,types.text_analyze_request_custom_topic_moder   $types.text_analyze_request_summarizer   rS   rU   rQ   r   re   r   r   r   r   <module>   s$   