
    hn?                       % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJr  S SKJrJrJrJrJr  S SKrS SKrS SKrSSKJr  SSKJrJrJ r J!r!  SSK"J#r#J$r$J%r%  SS	K&J'r'  SS
K(J)r)J*r*J+r+J,r,  SSK-J.r.  \(       a  SSK"J/r/  SSK0J1r1  \" S5      r2\" S5      r3\" S5      r4\Rj                  " \65      r7S\8S'    " S S\\3   5      r9 " S S\:5      r;SS jr<SS jr= " S S5      r>g)    )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is_type_alias_type)	BaseModelis_basemodeladd_request_id)RAW_RESPONSE_HEADER)StreamAsyncStreamis_stream_class_typeextract_stream_chunk_type)APIResponseValidationError)FinalRequestOptions)
BaseClientPR_Tzlogging.Loggerlogc                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   S\S'    SS.               S)S jjr\S*S j5       r\	S+S j5       r
\	S,S j5       r
SS.S-S jjr
\S.S j5       r\S/S j5       r\S0S j5       r\S1S j5       r\S2S  j5       r\S3S! j5       r\S2S" j5       r\S2S# j5       r\S4S$ j5       r\S5S% j5       rSS.S-S& jjr\S2S' j5       rS(rg)6LegacyAPIResponse-   a  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_responseintretries_takenr   )r8   c               f    X l         X0l        0 U l        X@l        XPl        X`l        Xl        Xpl        g N)r,   r.   r/   r1   r3   r4   r6   r8   )selfrawcast_toclientstream
stream_clsoptionsr8   s           I/var/www/html/env/lib/python3.13/site-packages/openai/_legacy_response.py__init__LegacyAPIResponse.__init__F   s2      !% *    c                L    U R                   R                  R                  S5      $ )Nzx-request-id)r6   headersgetr;   s    rB   
request_idLegacyAPIResponse.request_idZ   s    !!))--n==rE   c                   g r:    )r;   tos     rB   parseLegacyAPIResponse.parse^   s    ,/rE   c                    g r:   rM   rI   s    rB   rO   rP   a   s    rE   NrN   c                  Ub  UOU R                   nU R                  R                  U5      nUb  U$ U R                  US9n[	        U R
                  R                  5      (       a  U R
                  R                  U5      n[        U[        5      (       a  [        X@R                  5        X@R                  U'   [        [        U5      $ )a6  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`
rR   )r,   r/   rH   _parser   r4   post_parser
isinstancer   r   rJ   r   r%   )r;   rN   	cache_keycachedparseds        rB   rO   rP   d   s    @ .Bdmm	%%)))4M#DMM--..]]..v6Ffi((6??3*0Y'AvrE   c                .    U R                   R                  $ r:   )r6   rG   rI   s    rB   rG   LegacyAPIResponse.headers       !!)))rE   c                .    U R                   R                  $ r:   )r6   requestrI   s    rB   http_requestLegacyAPIResponse.http_request   r\   rE   c                .    U R                   R                  $ r:   )r6   status_coderI   s    rB   rb   LegacyAPIResponse.status_code   s    !!---rE   c                .    U R                   R                  $ r:   )r6   urlrI   s    rB   re   LegacyAPIResponse.url   s    !!%%%rE   c                .    U R                   R                  $ r:   )r_   methodrI   s    rB   rh   LegacyAPIResponse.method   s      '''rE   c                .    U R                   R                  $ )zrReturn the binary response content.

NOTE: this will be removed in favour of `.read()` in the
next major version.
)r6   contentrI   s    rB   rk   LegacyAPIResponse.content   s     !!)))rE   c                .    U R                   R                  $ )ziReturn the decoded response content.

NOTE: this will be turned into a method in the next major version.
)r6   textrI   s    rB   rn   LegacyAPIResponse.text   s     !!&&&rE   c                .    U R                   R                  $ r:   )r6   http_versionrI   s    rB   rq   LegacyAPIResponse.http_version   s    !!...rE   c                .    U R                   R                  $ r:   )r6   	is_closedrI   s    rB   rt   LegacyAPIResponse.is_closed   s    !!+++rE   c                .    U R                   R                  $ )zCThe time taken for the complete request/response cycle to complete.)r6   elapsedrI   s    rB   rw   LegacyAPIResponse.elapsed   s     !!)))rE   c               t
   Ub  UOU R                   n[        U5      (       a  UR                  nU(       a  [        U5      (       a  [	        US5      n[        U5      =(       d    UnU R                  (       Ga:  U(       ai  [        U5      (       d  [        S[         S[         35      e[        [        U" [        USS9U R                  [        [        U R                   5      S95      $ U R"                  (       aT  [        [$        U R#                  [        U R"                  5      U R                  [        [        U R                   5      S95      $ [        SU R                   R&                  5      nUc
  [)        5       e[        [$        U" UU R                  [        [        U R                   5      S95      $ U[*        L a  [        [$        S 5      $ U R                  nU[,        :X  a  [        [$        UR.                  5      $ U[0        :X  a#  [        [$        [1        UR.                  5      5      $ U[2        :X  a#  [        [$        [3        UR.                  5      5      $ U[4        :X  a+  [        [$        UR.                  R7                  5       S:H  5      $ [8        R:                  " U5      (       a+  [=        U[>        5      (       a  [        [$        U" U5      5      $ U[@        :X  a  [C        S	5      e[8        R:                  " U5      (       aN  [=        U[D        RF                  5      (       a/  U[D        RF                  :w  a  [I        S
5      e[        [$        U5      $ [8        R:                  " U5      (       a?  [=        U[J        5      (       d*  [=        U[L        RJ                  5      (       a  [        S5      eU[N        Laz  U[P        Laq  U[R        Lah  U[T        La_  [=        U[J        5      (       dJ  [C        SU S[J         S[R         S[P         S[T         S[*         S[,         S[D        RF                   S35      eURV                  RY                  SS5      R[                  S5      tpgUS:w  a|  []        U5      (       a,   UR_                  5       nU R                   Ra                  UUUS9$ U R                   Rj                  (       a  [m        USU S3UR.                  S9eUR.                  $ UR_                  5       nU R                   Ra                  UUUS9$ ! [b         a*  n	[d        Rg                  S[i        U	5      U	5         S n	A	NS n	A	ff = f)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)r=   responser>   r2   truez+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)datar=   r{   z5Could not read JSON from response data due to %s - %szMExpected Content-Type response header to be `application/json` but received `z
` instead.)r{   messagebody)7r,   r   	__value__r   r   r   r1   r   	TypeErrorr   r   r   r&   r    r6   r   r.   r3   r%   _default_stream_clsMissingStreamClassErrorr   strrn   r7   floatr0   lowerinspectisclass
issubclassHttpxBinaryResponseContentr)   RuntimeErrorhttpxResponse
ValueErrorr   pydanticobjectlistdictr   rG   rH   splitr   json_process_response_data	Exceptionr'   debugtype_strict_response_validationr!   )
r;   rN   r=   originr@   r{   content_type_r   excs
             rB   rT   LegacyAPIResponse._parse   s   "DMM g&&''G (11&w2GG$/<<<+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!-//#!//T\\2  h4= %%c>8==))c>3x}}-..e5/00d?8==..0F:;;??6""z&:T'U'U78,--&&LMM??
 
00 %..( #]__8$$ OO  vy1168#5#566tuu 6!dNdNeOvy1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--G$$	#==?D  <<>>! '!) ?   ||770%klxky  zD  E!  == }}||22 3 
 	
/ ! gIIUW[\_W`beffgs   -T 
T7 T22T7c                j    SU R                    SU R                  R                   SU R                   S3$ )Nz<APIResponse [ z] type=>)rb   r6   reason_phraser,   rI   s    rB   __repr__LegacyAPIResponse.__repr__T  s;     0 0143E3E3S3S2TT[\`\i\i[jjkllrE   )r,   r.   r4   r/   r1   r3   r6   r8   )r<   r5   r=   r+   r>   r-   r?   r0   r@   r2   rA   r"   r8   r7   returnNoner   z
str | None)rN   ztype[_T]r   r&   )r   r%   )rN   ztype[_T] | Noner   zR | _T)r   zhttpx.Headers)r   zhttpx.Request)r   r7   )r   z	httpx.URLr   r   r   bytes)r   r0   )r   zdatetime.timedelta)__name__
__module____qualname____firstlineno____doc____annotations__rC   propertyrJ   r   rO   rG   r_   rb   re   rh   rk   rn   rq   rt   rw   rT   r   r   __static_attributes__rM   rE   rB   r)   r)   -   s   
 !!))MBB!!!!M + + 	+
 %+ + F+ %+ + 
+( > > / / -1 -^ * * * * . . & & ( ( * * ' ' / / , , * * /3 M
^ m mrE   r)   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )r   iY  c                $   > [         TU ]  S5        g )NzzThe `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openai._streaming` for reference)superrC   )r;   	__class__s    rB   rC    MissingStreamClassError.__init__Z  s     I	
rE   rM   r   r   )r   r   r   r   rC   r   __classcell__)r   s   @rB   r   r   Y  s    
 
rE   r   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )Higher order function that takes one of our bound API methods and wraps it
to support returning the raw `APIResponse` object directly.
c                    > 0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   [        [        [
           T" U 0 UD65      $ Nextra_headersr|   r   r   rH   r   r)   r%   argskwargsr   funcs      rB   wrapped(to_raw_response_wrapper.<locals>.wrappede  sS    (ZDfjj6Q,R,XVX(Z-3)*"/%a($*?*?@@rE   r   zP.argsr   zP.kwargsr   zLegacyAPIResponse[R]	functoolswrapsr   r   s   ` rB   to_raw_response_wrapperr   `  s)    
 __TA A NrE   c                J   ^  [         R                  " T 5      SU 4S jj5       nU$ )r   c                    >#    0 [        [        UR                  S5      5      =(       d    0 EnSU[        '   X!S'   [        [        [
           T" U 0 UD6I S h  vN 5      $  N7fr   r   r   s      rB   r   .async_to_raw_response_wrapper.<locals>.wrappedv  s\     (ZDfjj6Q,R,XVX(Z-3)*"/%a(d0Ef0E*EFF*Es   AA"A 
	A"r   r   r   s   ` rB   async_to_raw_response_wrapperr   q  s)    
 __TG G NrE   c                     \ rS rSr% S\S'   SS jr\SS j5       r\SS j5       r\S S j5       r	\S S j5       r
S!S	 jrSS
 jrS"S#S jjrS"S$S jjrS%S jrS"S#S jjr    S&S jr\" S5      SS.     S'S jj5       rS(S jrSS jrS"S)S jjrS"S*S jjrS+S jrS"S)S jjr\" S5      SS.     S'S jj5       rS(S jrSrg),r   i  r5   r{   c                    Xl         g r:   r{   )r;   r{   s     rB   rC   #HttpxBinaryResponseContent.__init__  s     rE   c                .    U R                   R                  $ r:   )r{   rk   rI   s    rB   rk   "HttpxBinaryResponseContent.content  s    }}$$$rE   c                .    U R                   R                  $ r:   )r{   rn   rI   s    rB   rn   HttpxBinaryResponseContent.text  s    }}!!!rE   c                .    U R                   R                  $ r:   )r{   encodingrI   s    rB   r   #HttpxBinaryResponseContent.encoding  s    }}%%%rE   c                .    U R                   R                  $ r:   )r{   charset_encodingrI   s    rB   r   +HttpxBinaryResponseContent.charset_encoding  s    }}---rE   c                :    U R                   R                  " S0 UD6$ )NrM   )r{   r   )r;   r   s     rB   r   HttpxBinaryResponseContent.json  s    }}!!+F++rE   c                6    U R                   R                  5       $ r:   )r{   readrI   s    rB   r   HttpxBinaryResponseContent.read  s    }}!!##rE   Nc                8    U R                   R                  U5      $ r:   )r{   
iter_bytesr;   
chunk_sizes     rB   r   %HttpxBinaryResponseContent.iter_bytes  s    }}''
33rE   c                8    U R                   R                  U5      $ r:   )r{   	iter_textr   s     rB   r   $HttpxBinaryResponseContent.iter_text  s    }}&&z22rE   c                6    U R                   R                  5       $ r:   )r{   
iter_linesrI   s    rB   r   %HttpxBinaryResponseContent.iter_lines  s    }}''))rE   c                8    U R                   R                  U5      $ r:   )r{   iter_rawr   s     rB   r   #HttpxBinaryResponseContent.iter_raw  s    }}%%j11rE   c                    [        USS9 nU R                  R                  5        H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)aN  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openr{   r   write)r;   filefr   s       rB   write_to_file(HttpxBinaryResponseContent.write_to_file  s>     $T"a002 3 #""s   3A
AzDue to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead)r   c                   [        USS9 nU R                  R                  U5       H  nUR                  U5        M     S S S 5        g ! , (       d  f       g = fNr   r   r   )r;   r   r   r   r   s        rB   stream_to_file)HttpxBinaryResponseContent.stream_to_file  s@     $T"a00< = #""s   4A
Ac                6    U R                   R                  5       $ r:   )r{   closerI   s    rB   r   HttpxBinaryResponseContent.close  s    }}""$$rE   c                R   #    U R                   R                  5       I S h  vN $  N7fr:   )r{   areadrI   s    rB   r   HttpxBinaryResponseContent.aread  s     ]]((****   '%'c                @   #    U R                   R                  U5      $ 7fr:   )r{   aiter_bytesr   s     rB   r  &HttpxBinaryResponseContent.aiter_bytes  s     }}((44   c                @   #    U R                   R                  U5      $ 7fr:   )r{   
aiter_textr   s     rB   r  %HttpxBinaryResponseContent.aiter_text  s     }}''
33r  c                >   #    U R                   R                  5       $ 7fr:   )r{   aiter_linesrI   s    rB   r  &HttpxBinaryResponseContent.aiter_lines  s     }}((**s   c                @   #    U R                   R                  U5      $ 7fr:   )r{   	aiter_rawr   s     rB   r  $HttpxBinaryResponseContent.aiter_raw  s     }}&&z22r  c               ^  #    [         R                  " U5      nUR                  SS9I S h  vN  IS h  vN nU R                  R	                  U5        S h  vN nUR                  U5      I S h  vN   M$   NL NE N# N
 S S S 5      IS h  vN    g ! , IS h  vN  (       d  f       g = f7fr   )anyioPathr   r{   r  r   )r;   r   r   pathr   r   s         rB   astream_to_file*HttpxBinaryResponseContent.astream_to_file  s      zz$----"mm77
C $dggdm## .$# D .-----s   )B-A8B-A:B-BB A<B B1A>2B8B-:B-<B >B BB-BB-B*BB*&B-c                R   #    U R                   R                  5       I S h  vN $  N7fr:   )r{   acloserI   s    rB   r  !HttpxBinaryResponseContent.aclose  s     ]]))++++r	  r   )r{   r5   r   r   r   r   r   )r   r   r   r   r:   )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   rC   r   rk   rn   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r   rM   rE   rB   r   r     s5   ! % % " " & & . .,$43*2$ 
   	M "&	$ 	
 
%+54+3  	M "&		$$	$ 		$
 
	$	$,rE   r   )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   osr   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   r   _modelsr   r   r   
_constantsr   
_streamingr   r   r   r    _exceptionsr!   r"   _base_clientr#   r$   r%   r&   	getLoggerr   r'   r   r)   r   r   r   r   r   rM   rE   rB   <module>r2     s    " 	       U T     U U < < + \ \ 3,( cNCLT]''1^ 1im
 imX	
i 
""f, f,rE   