o
    Cji$                     @  sJ  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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mZmZmZ ddlmZ ddlmZmZ dd	lmZ dd
l m!Z! erqddlm"Z" ddl#m$Z$m%Z%m&Z& edZ'edZ(e)e*Z+de,d< G dd de
e( Z-G dd de.Z/d#ddZ0d$ddZ1d%d!d"Z2dS )&    )annotationsN)TYPE_CHECKINGAnyUnionGenericTypeVarCallablecast)	Awaitable	ParamSpecget_argsoverride
get_origin   )NoneTypeUnknownResponseBinaryResponseContent)is_given)	BaseModelis_basemodel)RAW_RESPONSE_HEADER)APIResponseValidationError)FinalRequestOptions)Stream
BaseClientAsyncStreamPRzlogging.Loggerlogc                   @  s   e Zd ZU ded< ded< ded< ded< d	ed
< ded< ded< d:ddZd;ddZed<ddZed=d d!Zed>d#d$Z	ed?d&d'Z
ed@d)d*ZedAd,d-Zed@d.d/Zed@d0d1ZedBd3d4Zd;d5d6Zed@d7d8Zd9S )CAPIResponsetype[R]_cast_toBaseClient[Any, Any]_clientzR | None_parsedbool_stream1type[Stream[Any]] | type[AsyncStream[Any]] | None_stream_clsr   _optionshttpx.Responsehttp_responserawcast_toclientstream
stream_clsoptionsreturnNonec                C  s.   || _ || _d | _|| _|| _|| _|| _d S N)r!   r#   r$   r&   r(   r)   r+   )selfr,   r-   r.   r/   r0   r1    r6   g/var/www/html/Resume-Parser/resume-parser-inhouse/venv/lib/python3.10/site-packages/openai/_response.py__init__'   s   

zAPIResponse.__init__r   c                 C  s:   | j d ur| j S |  }t| jjr| j|}|| _ |S r4   )r$   _parser   r)   post_parser)r5   parsedr6   r6   r7   parse9   s   
zAPIResponse.parsehttpx.Headersc                 C     | j jS r4   )r+   headersr5   r6   r6   r7   r?   D      zAPIResponse.headershttpx.Requestc                 C  r>   r4   )r+   requestr@   r6   r6   r7   http_requestH   rA   zAPIResponse.http_requestintc                 C  r>   r4   )r+   status_coder@   r6   r6   r7   rF   L   rA   zAPIResponse.status_code	httpx.URLc                 C  r>   r4   )r+   urlr@   r6   r6   r7   rH   P   rA   zAPIResponse.urlstrc                 C  r>   r4   )rD   methodr@   r6   r6   r7   rJ   T   rA   zAPIResponse.methodbytesc                 C  r>   r4   )r+   contentr@   r6   r6   r7   rL   X   rA   zAPIResponse.contentc                 C  r>   r4   )r+   textr@   r6   r6   r7   rM   \   rA   zAPIResponse.textc                 C  r>   r4   )r+   http_versionr@   r6   r6   r7   rN   `   rA   zAPIResponse.http_versiondatetime.timedeltac                 C  r>   )zCThe time taken for the complete request/response cycle to complete.)r+   elapsedr@   r6   r6   r7   rP   d   s   zAPIResponse.elapsedc           	      C  s"  | j r7| jrtt| jt| j| jtt| jdS td| jj}|d u r't	 tt|| j
| jtt| jdS | j
}|tu rCttd S | j}|tkrPtt|jS t|pU|}t|rgt|trgtt||S |tkrotdt|rt|tjr|tjkrtdtt|S |tur|tur|tur|turt|tstd| dt dt dt dt d	|jd
d^}}|dkrt |rz|! }W n t"y } zt#$dt%|| W Y d }~nd }~ww | jj&|||dS | jj'rt(|d| d|jd|jS |! }| jj&|||dS )N)r-   responser.   r'   z+Unexpected state - cast_to is `APIResponse`z:Subclasses of httpx.Response cannot be passed to `cast_to`zInvalid state, expected z to be a subclass type of z, z or .zcontent-type;zapplication/jsonz5Could not read JSON from response data due to %s - %s)datar-   rQ   zMExpected Content-Type response header to be `application/json` but received `z
` instead.)rQ   messagebody))r&   r(   r	   r   _extract_stream_chunk_typer+   r   r#   _default_stream_clsMissingStreamClassErrorr!   r   rI   rM   r   inspectisclass
issubclassr   r   RuntimeErrorhttpxResponse
ValueErrorr   listdictr   r   r?   getsplitr   json	Exceptionr   debugtype_process_response_data_strict_response_validationr   )	r5   r0   r-   rQ   origincontent_type_rT   excr6   r6   r7   r9   i   s   
	
	


"


	zAPIResponse._parsec                 C  s    d| j  d| jj d| j dS )Nz<APIResponse [ z] type=>)rF   r+   reason_phraser!   r@   r6   r6   r7   __repr__   s    zAPIResponse.__repr__N)r,   r*   r-   r    r.   r"   r/   r%   r0   r'   r1   r   r2   r3   )r2   r   )r2   r=   )r2   rB   )r2   rE   )r2   rG   )r2   rI   )r2   rK   )r2   rO   )__name__
__module____qualname____annotations__r8   r<   propertyr?   rD   rF   rH   rJ   rL   rM   rN   rP   r9   r   rr   r6   r6   r6   r7   r      s>   
 


jr   c                      s   e Zd Zd fddZ  ZS )rY   r2   r3   c                   s   t  d d S )NzzThe `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openai._streaming` for reference)superr8   r@   	__class__r6   r7   r8      s   z MissingStreamClassError.__init__)r2   r3   )rs   rt   ru   r8   __classcell__r6   r6   ry   r7   rY      s    rY   r0   rh   r2   c                 C  s(   t | }|std|  tt|d S )Nz^Expected stream_cls to have been given a generic type argument, e.g. Stream[Foo] but received r   )r   	TypeErrorr	   rh   )r0   argsr6   r6   r7   rW      s   rW   funcCallable[P, R]Callable[P, APIResponse[R]]c                      t  d
 fdd}|S )Higher order function that takes one of our bound API methods and wraps it
    to support returning the raw `APIResponse` object directly.
    r}   P.argskwargsP.kwargsr2   APIResponse[R]c                    s@   i t t|dp
i }d|t< ||d< t tt  | i |S Nextra_headerstruer	   r   rc   r   r   r   r}   r   r   r~   r6   r7   wrapped   s   z(to_raw_response_wrapper.<locals>.wrappedNr}   r   r   r   r2   r   	functoolswrapsr~   r   r6   r   r7   to_raw_response_wrapper      r   Callable[P, Awaitable[R]]&Callable[P, Awaitable[APIResponse[R]]]c                   r   )r   r}   r   r   r   r2   r   c                    sH   i t t|dpi }d|t< ||d< t tt  | i |I d H S r   r   r   r   r6   r7   r      s
   z.async_to_raw_response_wrapper.<locals>.wrappedNr   r   r   r6   r   r7   async_to_raw_response_wrapper   r   r   )r0   rh   r2   rh   )r~   r   r2   r   )r~   r   r2   r   )3
__future__r   rZ   loggingdatetimer   typingr   r   r   r   r   r   r	   typing_extensionsr
   r   r   r   r   r^   _typesr   r   r   _utilsr   _modelsr   r   
_constantsr   _exceptionsr   r   _base_clientr   r   r   r   r   	getLoggerrs   r   rv   r   r|   rY   rW   r   r   r6   r6   r6   r7   <module>   s2    $ <

	