
    OYhf<                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZmZmZmZmZ d dlZd dlZd dlZddlmZ ddlmZmZm Z  ddl!m"Z"m#Z# dd	l$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, erddl!m-Z- ddl.m/Z/  ed      Z0 ed      Z1 ed      Z2 ejf                  e4      Z5de6d<    G d dee1         Z7 G d de8      Z9ddZ:ddZ; G d d      Z<y)    )annotationsN)
TYPE_CHECKINGAnyUnionGenericTypeVarCallableIteratorAsyncIteratorcastoverload)	Awaitable	ParamSpecoverride
deprecated
get_origin   )NoneType)is_givenextract_type_argis_annotated_type)	BaseModelis_basemodel)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)FinalRequestOptions)
BaseClientPR_Tzlogging.Loggerlogc                     e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dZed$d       Zed%d       Z	ed&d       Z	ddd'dZ	ed(d       Z
ed)d       Zed*d       Zed+d       Zed,d       Zed-d       Zed,d       Zed,d       Zed.d       Zed/d        Zddd'd!Zed,d"       Zy)0LegacyAPIResponsea  This is a legacy class as it will be replaced by `APIResponse`
    and `AsyncAPIResponse` in the `_response.py` file in the next major
    release.

    For the sync client this will mostly be the same with the exception
    of `content` & `text` will be methods instead of properties. In the
    async client, all methods will be async.

    A migration script will be provided & the migration in general should
    be smooth.
    type[R]_cast_toBaseClient[Any, Any]_clientzdict[type[Any], Any]_parsed_by_typebool_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsr    _optionshttpx.Responsehttp_responsec               f    || _         || _        i | _        || _        || _        || _        || _        y N)r)   r+   r,   r.   r0   r1   r3   )selfrawcast_toclientstream
stream_clsoptionss          V/var/www/feuerwehr-webapp/venv/lib/python3.12/site-packages/openai/_legacy_response.py__init__zLegacyAPIResponse.__init__8   s8      !%     c                L    | j                   j                  j                  d      S )Nzx-request-id)r3   headersgetr6   s    r=   
request_idzLegacyAPIResponse.request_idJ   s    !!))--n==r?   c                    y r5    )r6   tos     r=   parsezLegacyAPIResponse.parseN       r?   c                     y r5   rF   rC   s    r=   rH   zLegacyAPIResponse.parseR   rI   r?   NrG   c                  ||n| j                   }| j                  j                  |      }||S | j                  |      }t	        | j
                  j                        r| j
                  j                  |      }|| j                  |<   |S )a  Returns the rich python representation of this response's data.

        NOTE: For the async client: this will become a coroutine in the next major version.

        For lower-level control, see `.read()`, `.json()`, `.iter_bytes()`.

        You can customise the type that the response is parsed into through
        the `to` argument, e.g.

        ```py
        from openai import BaseModel


        class MyModel(BaseModel):
            foo: str


        obj = response.parse(to=MyModel)
        print(obj.foo)
        ```

        We support parsing:
          - `BaseModel`
          - `dict`
          - `list`
          - `Union`
          - `str`
          - `int`
          - `float`
          - `httpx.Response`
        rK   )r)   r,   rB   _parser   r1   post_parser)r6   rG   	cache_keycachedparseds        r=   rH   zLegacyAPIResponse.parseV   s    @ .Bdmm	%%)))4M#DMM--.]]..v6F*0Y'r?   c                .    | j                   j                  S r5   )r3   rA   rC   s    r=   rA   zLegacyAPIResponse.headers       !!)))r?   c                .    | j                   j                  S r5   )r3   requestrC   s    r=   http_requestzLegacyAPIResponse.http_request   rS   r?   c                .    | j                   j                  S r5   )r3   status_coderC   s    r=   rX   zLegacyAPIResponse.status_code   s    !!---r?   c                .    | j                   j                  S r5   )r3   urlrC   s    r=   rZ   zLegacyAPIResponse.url   s    !!%%%r?   c                .    | j                   j                  S r5   )rV   methodrC   s    r=   r\   zLegacyAPIResponse.method   s      '''r?   c                .    | j                   j                  S )zReturn the binary response content.

        NOTE: this will be removed in favour of `.read()` in the
        next major version.
        )r3   contentrC   s    r=   r^   zLegacyAPIResponse.content   s     !!)))r?   c                .    | j                   j                  S )zyReturn the decoded response content.

        NOTE: this will be turned into a method in the next major version.
        )r3   textrC   s    r=   r`   zLegacyAPIResponse.text   s     !!&&&r?   c                .    | j                   j                  S r5   )r3   http_versionrC   s    r=   rb   zLegacyAPIResponse.http_version   s    !!...r?   c                .    | j                   j                  S r5   )r3   	is_closedrC   s    r=   rd   zLegacyAPIResponse.is_closed   s    !!+++r?   c                .    | j                   j                  S )zCThe time taken for the complete request/response cycle to complete.)r3   elapsedrC   s    r=   rf   zLegacyAPIResponse.elapsed   s     !!)))r?   c               t	   |rt        |      rt        |d      }| j                  r@|rjt        |      st	        dt
         dt               t        t         |t        |d      | j                  t        t        | j                                    S | j                  rWt        t        | j                  t        | j                        | j                  t        t        | j                                    S t        d| j                  j                        }|
t!               t        t         || j"                  | j                  t        t        | j                                    S ||n| j"                  }t        |      rt        |d      }|t$        u rt        t        d       S | j                  }|t&        k(  rt        t        |j(                        S |t*        k(  r#t        t        t+        |j(                              S |t,        k(  r#t        t        t-        |j(                              S t/        |      xs |}t1        j2                  |      r&t5        |t6              rt        t         ||            S |t8        k(  rt;        d      t1        j2                  |      rHt5        |t<        j>                        r.|t<        j>                  k7  rtA        d	      t        t        |      S t1        j2                  |      r5t5        |tB              s%t5        |tD        jB                        rt	        d
      |tF        urr|tH        urj|tJ        urb|tL        urZt5        |tB              sJt;        d| dtB         dtJ         dtH         dtL         dt$         dt&         dt<        j>                   d      |jN                  jQ                  dd      jS                  d      ^}}|dk7  rxtU        |      r/	 |jW                         }| j                  jY                  |||      S | j                  jb                  rte        |d| d|j(                        |j(                  S |jW                         }| j                  jY                  |||      S # tZ        $ r*}	t\        j_                  dta        |	      |	       Y d }	~	d }	~	ww xY w)Nr   z/Expected custom parse type to be a subclass of z or zUExpected custom stream type to be passed with a type argument, e.g. Stream[ChunkType])failure_message)r8   responser9   r/   z+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zVPydantic models must subclass our base model type, e.g. `from openai import BaseModel`zUnsupported type, expected z to be a subclass of z, .zcontent-type*;zapplication/json)datar8   ri   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)ri   messagebody)3r   r   r.   r   	TypeErrorr   r   r   r$   r   r3   r   r+   r0   r#   _default_stream_clsMissingStreamClassErrorr)   r   strr`   intfloatr   inspectisclass
issubclassHttpxBinaryResponseContentr'   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rA   rB   splitr   json_process_response_data	Exceptionr%   debugtype_strict_response_validationr   )
r6   rG   r;   r8   ri   origincontent_type_rm   excs
             r=   rM   zLegacyAPIResponse._parse   sY   #B'!"a(B<<+B/#&UV\U]]abman$opp 9 -D! "&!3!3#C6
 
 $$ 9$:J:J K!%!3!3#C6 %   QSWS_S_SsSstJ!-// MM!//T\\2  "DMM W%&w2Gh4= %%c>8==))c>3x}}-..e5/00G$/??6"z&:T'U78,--&&LMM??6"z&%..'I %..( #]__8$$??6":fi+HZX^`h`r`rMstuu 6!dNdNeOvy1-gY6KI;VXY]X^^`ae`ffhinhooqrzq{{}  B  ~C  CG  HM  HV  HV  GW  WX  Y  $++//DJJ3Oq--G$	#==?D  <<>>! '!) ?   ||770%klxky  zD  E!  == }}||22 3 
 	
/ ! gIIUW[\_W`beffgs   *R 	R7 R22R7c                j    d| j                    d| j                  j                   d| j                   dS )Nz<APIResponse [ z] type=>)rX   r3   reason_phraser)   rC   s    r=   __repr__zLegacyAPIResponse.__repr__8  s;     0 0143E3E3S3S2TT[\`\i\i[jjkllr?   )r7   r2   r8   r(   r9   r*   r:   r-   r;   r/   r<   r    returnNoner   z
str | None)rG   ztype[_T]r   r$   )r   r#   )rG   ztype[_T] | Noner   zR | _T)r   zhttpx.Headers)r   zhttpx.Request)r   rt   )r   z	httpx.URLr   rs   r   bytes)r   r-   )r   zdatetime.timedelta)__name__
__module____qualname____doc____annotations__r>   propertyrD   r   rH   rA   rV   rX   rZ   r\   r^   r`   rb   rd   rf   rM   r   r   rF   r?   r=   r'   r'   "   s   
 !!))MBB!!!!! ! 	!
 %! ! F! %! 
!$ > >     .2 *X * * * * . . & & ( ( * * ' ' / / , , * * /3 B
H m mr?   r'   c                        e Zd Zd fdZ xZS )rr   c                $    t         |   d       y )NzzThe `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openai._streaming` for reference)superr>   )r6   	__class__s    r=   r>   z MissingStreamClassError.__init__>  s     I	
r?   r   r   )r   r   r   r>   __classcell__)r   s   @r=   rr   rr   =  s    
 
r?   rr   c                D     t        j                         d fd       }|S )Higher order function that takes one of our bound API methods and wraps it
    to support returning the raw `APIResponse` object directly.
    c                     i t        t        |j                  d            xs i }d|t        <   ||d<   t        t        t
            | i |      S Nextra_headerstruer   r   rB   r   r'   r#   argskwargsr   funcs      r=   wrappedz(to_raw_response_wrapper.<locals>.wrappedI  sU    (ZDfjj6Q,R,XVX(Z-3)*"/%a($*?*?@@r?   r   zP.argsr   zP.kwargsr   zLegacyAPIResponse[R]	functoolswrapsr   r   s   ` r=   to_raw_response_wrapperr   D  s)    
 __TA A Nr?   c                D     t        j                         d fd       }|S )r   c                    K   i t        t        |j                  d            xs i }d|t        <   ||d<   t        t        t
            | i | d {         S 7 wr   r   r   s      r=   r   z.async_to_raw_response_wrapper.<locals>.wrappedZ  s_     (ZDfjj6Q,R,XVX(Z-3)*"/%a(d0Ef0E*EFF*Es   AAA
	Ar   r   r   s   ` r=   async_to_raw_response_wrapperr   U  s)    
 __TG G Nr?   c                  H   e Zd ZU ded<   ddZedd       Zedd       Zedd       Zedd       Z	ddZ
dd	Zd d!dZd d"dZd#dZd d!dZ	 	 	 	 d$dZ ed      d
d	 	 	 	 	 d%d       Zd&dZddZd d'dZd d(dZd)dZd d'dZ ed      d
d	 	 	 	 	 d%d       Zd&dZy
)*ry   r2   ri   c                    || _         y r5   )ri   )r6   ri   s     r=   r>   z#HttpxBinaryResponseContent.__init__i  s	     r?   c                .    | j                   j                  S r5   )ri   r^   rC   s    r=   r^   z"HttpxBinaryResponseContent.contentl  s    }}$$$r?   c                .    | j                   j                  S r5   )ri   r`   rC   s    r=   r`   zHttpxBinaryResponseContent.textp  s    }}!!!r?   c                .    | j                   j                  S r5   )ri   encodingrC   s    r=   r   z#HttpxBinaryResponseContent.encodingt  s    }}%%%r?   c                .    | j                   j                  S r5   )ri   charset_encodingrC   s    r=   r   z+HttpxBinaryResponseContent.charset_encodingx  s    }}---r?   c                :     | j                   j                  di |S )NrF   )ri   r   )r6   r   s     r=   r   zHttpxBinaryResponseContent.json|  s    !t}}!!+F++r?   c                6    | j                   j                         S r5   )ri   readrC   s    r=   r   zHttpxBinaryResponseContent.read  s    }}!!##r?   Nc                8    | j                   j                  |      S r5   )ri   
iter_bytesr6   
chunk_sizes     r=   r   z%HttpxBinaryResponseContent.iter_bytes  s    }}''
33r?   c                8    | j                   j                  |      S r5   )ri   	iter_textr   s     r=   r   z$HttpxBinaryResponseContent.iter_text  s    }}&&z22r?   c                6    | j                   j                         S r5   )ri   
iter_linesrC   s    r=   r   z%HttpxBinaryResponseContent.iter_lines  s    }}''))r?   c                8    | j                   j                  |      S r5   )ri   iter_rawr   s     r=   r   z#HttpxBinaryResponseContent.iter_raw  s    }}%%j11r?   c                    t        |d      5 }| j                  j                         D ]  }|j                  |        	 ddd       y# 1 sw Y   yxY w)av  Write the output to the given file.

        Accepts a filename or any path-like object, e.g. pathlib.Path

        Note: if you want to stream the data to the file instead of writing
        all at once then you should use `.with_streaming_response` when making
        the API request, e.g. `client.with_streaming_response.foo().stream_to_file('my_filename.txt')`
        wbmodeNopenri   r   write)r6   filefrm   s       r=   write_to_filez(HttpxBinaryResponseContent.write_to_file  sL     $T" 	a002 	 	 	s   1A		AzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead)r   c                   t        |d      5 }| j                  j                  |      D ]  }|j                  |        	 d d d        y # 1 sw Y   y xY wNr   r   r   )r6   r   r   r   rm   s        r=   stream_to_filez)HttpxBinaryResponseContent.stream_to_file  sN     $T" 	a00< 	 	 	s   2A

Ac                6    | j                   j                         S r5   )ri   closerC   s    r=   r   z HttpxBinaryResponseContent.close  s    }}""$$r?   c                R   K   | j                   j                          d {   S 7 wr5   )ri   areadrC   s    r=   r   z HttpxBinaryResponseContent.aread  s     ]]((****   '%'c                @   K   | j                   j                  |      S wr5   )ri   aiter_bytesr   s     r=   r   z&HttpxBinaryResponseContent.aiter_bytes  s     }}((44   c                @   K   | j                   j                  |      S wr5   )ri   
aiter_textr   s     r=   r   z%HttpxBinaryResponseContent.aiter_text  s     }}''
33r   c                >   K   | j                   j                         S wr5   )ri   aiter_linesrC   s    r=   r   z&HttpxBinaryResponseContent.aiter_lines  s     }}((**s   c                @   K   | j                   j                  |      S wr5   )ri   	aiter_rawr   s     r=   r   z$HttpxBinaryResponseContent.aiter_raw  s     }}&&z22r   c               V  K   t        j                  |      }|j                  d       d {   4 d {   }| j                  j	                  |      2 3 d {   }|j                  |       d {    #7 K7 D7 "7 6 d d d       d {  7   y # 1 d {  7  sw Y   y xY wwr   )anyioPathr   ri   r   r   )r6   r   r   pathr   rm   s         r=   astream_to_filez*HttpxBinaryResponseContent.astream_to_file  s      zz$-- 	$ 	$"mm77
C $ $dggdm## . 	$$# D	$ 	$ 	$ 	$ 	$s   +B)A9B)A;B)BBA=BB3A?4B9B);B)=B?BBB)BB)B&BB&"B)c                R   K   | j                   j                          d {   S 7 wr5   )ri   acloserC   s    r=   r   z!HttpxBinaryResponseContent.aclose  s     ]]))++++r   )ri   r2   r   r   r   r   r   )r   r   r   r   r5   )r   
int | Noner   zIterator[bytes])r   r   r   Iterator[str])r   r   )r   str | os.PathLike[str]r   r   )r   r   r   r   r   r   r   )r   r   r   zAsyncIterator[bytes])r   r   r   AsyncIterator[str])r   r   )r   r   r   r   r>   r   r^   r`   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r?   r=   ry   ry   f  s5   ! % % " " & & . .,$43*2$ 
   	M "&	$ 	
 
%+54+3  	M "&		$$	$ 		$
 
	$	$,r?   ry   )r   zCallable[P, R]r   z!Callable[P, LegacyAPIResponse[R]])r   zCallable[P, Awaitable[R]]r   z,Callable[P, Awaitable[LegacyAPIResponse[R]]])=
__future__r   osrv   loggingdatetimer   typingr   r   r   r   r   r	   r
   r   r   r   typing_extensionsr   r   r   r   r   r   r{   r~   _typesr   _utilsr   r   r   _modelsr   r   
_constantsr   
_streamingr   r   r   r   _exceptionsr   r    _base_clientr!   r"   r#   r$   	getLoggerr   r%   r   r'   rp   rr   r   r   ry   rF   r?   r=   <module>r     s    " 	     q q q T T     A A , + \ \ 3,( cNCLT]'g''1^ 1Xm
 Xmv
i 
""f, f,r?   