
    ]jM                         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  e j&                  e j(                  d      Z G d d      Z G d d      Zy)    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)construct_type)
Prediction.c                   $   e Zd ZdefdZdddddej                  e   dej                  e   dej                  e   de	ej                  e      fd	Zeeeedd
dej                  e   dej                  ej                  ej                   eej"                  f         dej                  e   dej                  e   dej                  e   de	e   fdZdddedej                  e   de	e   fdZdddedej                  e   de	d   fdZeeeedd
dedej                  e   dej                  ej                  ej                   eej"                  f         dej                  e   dej                  e   dej                  e   de	e   fdZy)RawPredictionsClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     Q/root/env/lib/python3.12/site-packages/label_studio_sdk/predictions/raw_client.py__init__zRawPredictionsClient.__init__   
    -    Nprojecttaskrequest_optionsr   r   r   returnc                R   | j                   j                  j                  dd||d|      }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a  
        List all predictions and their IDs.

        Parameters
        ----------
        project : typing.Optional[int]
            Filter predictions by project ID

        task : typing.Optional[int]
            Filter predictions by task ID

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

        Returns
        -------
        HttpResponse[typing.List[Prediction]]
            Predictions list
        api/predictions/GETr   r   methodparamsr      ,  type_object_responsedatastatus_codeheadersbody)r   httpx_clientrequestr0   typingcastListr   r   jsonr	   r   r   dictr1   textr   r   r   r   	_response_data_response_jsons          r   listzRawPredictionsClient.list   s   4 ((55==" , > 
		ti++1c1KK
+"$kk*5 ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   A=C' ,C' '?D&model_versionresultscorer   r   rA   rB   rC   c          	      "   | j                   j                  j                  dd||||dddi|t              }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                         	            }t        ||
      S |j                         }t        |j                  t        |j                        |      # t        $ r6 t        |j                  t        |j                        |j                        w xY w)a  
        Create a prediction for a specific task.

        Parameters
        ----------
        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

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

        Returns
        -------
        HttpResponse[Prediction]
            Created prediction
        r!   POSTrA   rB   rC   r   content-typeapplication/jsonr%   r8   r1   r   omitr'   r(   r)   r,   r/   )r   r3   r4   OMITr0   r5   r6   r   r   r8   r	   r   r   r9   r1   r:   	r   rA   rB   rC   r   r   r<   r=   r>   s	            r   createzRawPredictionsClient.createH   s	   D ((55==!. 	  2 , > 
		ti++1c1"( ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AC C ?Dr   idc                    | j                   j                  j                  dt        |       dd|      }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                                     }t        ||      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a^  
        Get details about a specific prediction by its ID.

        Parameters
        ----------
        id : int
            Prediction ID

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

        Returns
        -------
        HttpResponse[Prediction]
            Prediction details
        r!   /r"   r%   r   r'   r(   r)   r,   r/   )r   r3   r4   r
   r0   r5   r6   r   r   r8   r	   r   r   r9   r1   r:   r   rO   r   r<   r=   r>   s         r   getzRawPredictionsClient.get   s    " ((55==/34A6+ > 
	
	ti++1c1"( ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AC C ?Dc                   | j                   j                  j                  dt        |       dd|      }	 d|j                  cxk  rdk  rn nt        |d      S |j                         }t        |j                  t        |j                        |	      # t        $ r6 t        |j                  t        |j                        |j                  	      w xY w)
a,  
        Delete a prediction by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

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

        Returns
        -------
        HttpResponse[None]
        r!   rQ   DELETErR   r'   r(   Nr,   r/   )r   r3   r4   r
   r0   r	   r8   r   r   r9   r1   r:   r   rO   r   r<   r>   s        r   deletezRawPredictionsClient.delete   s      ((55==/34A6+ > 
	
	ti++1c1#YTBB&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   $B B ?Cc          	      <   | j                   j                  j                  dt        |       dd||||dddi|t              }	 d|j
                  cxk  rd	k  rGn nDt        j                  t        t        t        |j                         
            }t        ||      S |j                         }	t        |j
                  t        |j                        |	      # t        $ r6 t        |j
                  t        |j                        |j                         w xY w)a:  
        Update prediction data by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

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

        Returns
        -------
        HttpResponse[Prediction]
            Updated prediction
        r!   rQ   PATCHrF   rG   rH   rI   r'   r(   r)   r,   r/   )r   r3   r4   r
   rK   r0   r5   r6   r   r   r8   r	   r   r   r9   r1   r:   
r   rO   rA   rB   rC   r   r   r<   r=   r>   s
             r   updatezRawPredictionsClient.update   s   L ((55==/34A6!. 	  2 , > 
		ti++1c1"( ) 0 $YUCC&^^-N 9#8#8$yGXGXBY`noo  	ty'<'<d9K\K\F]dmdrdrss	ts   AC !C ?D)__name__
__module____qualname__r   r   r5   Optionalintr   r	   r7   r   r?   rK   strSequenceDictAnyfloatrM   rT   rX   r\    r   r   r   r      s>   .*; . )-%);?0p %0p ooc"	0p
  80p 
fkk*-	.0pj /3QU(,%);?>p s+>p CO0L MN	>p
 u%>p ooc">p  8>p 
j	!>p@ RV #pc #pv~/N #pZfgqZr #pJ UY p p&//.2Q p]ijn]o pB /3QU(,%);?BpBp s+	Bp
 CO0L MNBp u%Bp ooc"Bp  8Bp 
j	!Bpr   r   c                   $   e Zd ZdefdZdddddej                  e   dej                  e   dej                  e   de	ej                  e      fd	Zeeeedd
dej                  e   dej                  ej                  ej                   eej"                  f         dej                  e   dej                  e   dej                  e   de	e   fdZdddedej                  e   de	e   fdZdddedej                  e   de	d   fdZeeeedd
dedej                  e   dej                  ej                  ej                   eej"                  f         dej                  e   dej                  e   dej                  e   de	e   fdZy)AsyncRawPredictionsClientr   c                    || _         y r   r   r   s     r   r   z"AsyncRawPredictionsClient.__init__  r   r   Nr   r   r   r   r   c                n  K   | j                   j                  j                  dd||d|       d{   }	 d|j                  cxk  rdk  rin nft	        j
                  t        j                  t           t        t        j                  t           |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)a  
        List all predictions and their IDs.

        Parameters
        ----------
        project : typing.Optional[int]
            Filter predictions by project ID

        task : typing.Optional[int]
            Filter predictions by task ID

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

        Returns
        -------
        AsyncHttpResponse[typing.List[Prediction]]
            Predictions list
        r!   r"   r#   r$   Nr'   r(   r)   r,   r/   )r   r3   r4   r0   r5   r6   r7   r   r   r8   r   r   r   r9   r1   r:   r;   s          r   r?   zAsyncRawPredictionsClient.list  s    4 ..;;CC" , D 
 
		ti++1c1KK
+"$kk*5 ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo-
(  	ty'<'<d9K\K\F]dmdrdrss	ts3   0D5C1D5A=C3 5D56C3 ,D53?D22D5r@   rA   rB   rC   c          	      >  K   | j                   j                  j                  dd||||dddi|t               d{   }	 d|j                  cxk  rd	k  rGn nDt        j                  t        t        t        |j                         
            }t        ||      S |j                         }t        |j                  t        |j                        |      7 # t        $ r6 t        |j                  t        |j                        |j                        w xY ww)a  
        Create a prediction for a specific task.

        Parameters
        ----------
        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

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

        Returns
        -------
        AsyncHttpResponse[Prediction]
            Created prediction
        r!   rE   rF   rG   rH   rI   Nr'   r(   r)   r,   r/   )r   r3   r4   rK   r0   r5   r6   r   r   r8   r   r   r   r9   r1   r:   rL   s	            r   rM   z AsyncRawPredictionsClient.createE  s    D ..;;CC!. 	  2 , D 
 
		ti++1c1"( ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo9
4  	ty'<'<d9K\K\F]dmdrdrss	ts4   :DCDAC DC .,D?DDrN   rO   c                <  K   | j                   j                  j                  dt        |       dd|       d{   }	 d|j                  cxk  rdk  rGn nDt        j                  t        t        t        |j                                     }t        ||	      S |j                         }t        |j                  t        |j                        |
      7 # t        $ r6 t        |j                  t        |j                        |j                  
      w xY ww)ac  
        Get details about a specific prediction by its ID.

        Parameters
        ----------
        id : int
            Prediction ID

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

        Returns
        -------
        AsyncHttpResponse[Prediction]
            Prediction details
        r!   rQ   r"   rR   Nr'   r(   r)   r,   r/   )r   r3   r4   r
   r0   r5   r6   r   r   r8   r   r   r   r9   r1   r:   rS   s         r   rT   zAsyncRawPredictionsClient.get  s    & ..;;CC/34A6+ D 
 
	
	ti++1c1"( ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo%
   	ty'<'<d9K\K\F]dmdrdrss	ts4   9DCDAC DC -,D?DDc                  K   | j                   j                  j                  dt        |       dd|       d{   }	 d|j                  cxk  rdk  rn nt        |d      S |j                         }t        |j                  t        |j                        |	      7 e# t        $ r6 t        |j                  t        |j                        |j                  	      w xY ww)
a1  
        Delete a prediction by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

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

        Returns
        -------
        AsyncHttpResponse[None]
        r!   rQ   rV   rR   Nr'   r(   r,   r/   )r   r3   r4   r
   r0   r   r8   r   r   r9   r1   r:   rW   s        r   rX   z AsyncRawPredictionsClient.delete  s     $ ..;;CC/34A6+ D 
 
	
	ti++1c1()$GG&^^-N 9#8#8$yGXGXBY`noo
  	ty'<'<d9K\K\F]dmdrdrss	ts3   9C%B!C%$B# %C%&B# 6,C%#?C""C%c          	      X  K   | j                   j                  j                  dt        |       dd||||dddi|t               d{   }	 d	|j
                  cxk  rd
k  rGn nDt        j                  t        t        t        |j                                     }t        ||      S |j                         }	t        |j
                  t        |j                        |	      7 # t        $ r6 t        |j
                  t        |j                        |j                         w xY ww)a?  
        Update prediction data by prediction ID.

        Parameters
        ----------
        id : int
            Prediction ID

        model_version : typing.Optional[str]
            Model version - tag for predictions that can be used to filter tasks in Data Manager, as well as select specific model version for showing preannotations in the labeling interface

        result : typing.Optional[typing.Sequence[typing.Dict[str, typing.Any]]]
            Prediction result in JSON format. Read more about the format in [the Label Studio documentation.](https://labelstud.io/guide/predictions)

        score : typing.Optional[float]
            Prediction score. Can be used in Data Manager to sort task by model confidence. Task with the lowest score will be shown first.

        task : typing.Optional[int]
            Task ID for which the prediction is created

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

        Returns
        -------
        AsyncHttpResponse[Prediction]
            Updated prediction
        r!   rQ   rZ   rF   rG   rH   rI   Nr'   r(   r)   r,   r/   )r   r3   r4   r
   rK   r0   r5   r6   r   r   r8   r   r   r   r9   r1   r:   r[   s
             r   r\   z AsyncRawPredictionsClient.update  s'    L ..;;CC/34A6!. 	  2 , D 
 
		ti++1c1"( ) 0 ))%HH&^^-N 9#8#8$yGXGXBY`noo9
4  	ty'<'<d9K\K\F]dmdrdrss	ts7   AD*	C&
D*AC( *D*+C( ;,D*(?D''D*)r]   r^   r_   r   r   r5   r`   ra   r   r   r7   r   r?   rK   rb   rc   rd   re   rf   rM   rT   rX   r\   rg   r   r   ri   ri     s@   .*< . )-%);?0p %0p ooc"	0p
  80p 
6;;z2	30pj /3QU(,%);?>p s+>p CO0L MN	>p
 u%>p ooc">p  8>p 
:	&>pB NR%p%p+1??>+J%p	:	&%pP NRpp+1??>+Jp	4	 pF /3QU(,%);?BpBp s+	Bp
 CO0L MNBp u%Bp ooc"Bp  8Bp 
:	&Bpr   ri   )r5   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.jsonable_encoderr
   core.request_optionsr   core.unchecked_base_modelr   types.predictionr   r6   re   rK   r   ri   rg   r   r   <module>rx      sW     ( % G @ 4 1 6 ) v{{6::s#zp zpz~p ~pr   