
    хiKm                       S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
Jr  S SKJr  S SKrSSKJr  SSKJrJrJrJrJr  SS	KJrJr  SS
KJr  SSKJrJr  SSKJ r J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)J*r+J,r-J.r/  SSK0J1r1  SSK2J3r3J4r4  SSK5J6r6  SSK7J8r8  SSK9J:r:  SSK;J<r<  SSK=J>r>  SSK?J@r@  SSKAJBrB  SSKCJDrD  SSKEJFrF  SSKGJHrH  SS/rI " S S\5      rJ " S  S\5      rK " S! S"5      rL " S# S$5      rM " S% S&5      rN " S' S(5      rOg))    )annotations)DictListTypeUnionIterableOptionalcast)partial)LiteralN   )_legacy_response)	NOT_GIVENBodyQueryHeadersNotGiven)maybe_transformasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)Stream)completion_create_params)make_request_options)ResponseFormatTvalidate_input_toolsparse_chat_completiontype_to_response_format_param)	ChatModel)ChatCompletionStreamManager AsyncChatCompletionStreamManager)ChatCompletion)ChatCompletionChunk)ParsedChatCompletion)ChatCompletionModality)ChatCompletionToolParam)ChatCompletionAudioParam)ChatCompletionMessageParam) ChatCompletionStreamOptionsParam)$ChatCompletionPredictionContentParam)#ChatCompletionToolChoiceOptionParamCompletionsAsyncCompletionsc                     \ rS rSr\S	S j5       r\S
S j5       r\\\\\\\\\\\\\\\\\\\\\\\\\\SSS\S.                                                                 SS jjr\\\\\\\\\\\\\\\\\\\\\\\\\\SSS\S.                                                                 SS jjr	Sr
g)r/   *   c                    [        U 5      $ z
This property can be used as a prefix for any HTTP method call to return the
the raw response object instead of the parsed content.

For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
)CompletionsWithRawResponseselfs    `/home/james-whalen/.local/lib/python3.13/site-packages/openai/resources/beta/chat/completions.pywith_raw_responseCompletions.with_raw_response+   s     *$//    c                    [        U 5      $ z
An alternative to `.with_raw_response` that doesn't eagerly read the response body.

For more information, see https://www.github.com/openai/openai-python#with_streaming_response
) CompletionsWithStreamingResponser6   s    r8   with_streaming_response#Completions.with_streaming_response5   s     055r;   Naudioresponse_formatfrequency_penaltyfunction_call	functions
logit_biaslogprobsmax_completion_tokens
max_tokensmetadata
modalitiesnparallel_tool_calls
predictionpresence_penaltyseedservice_tierstopstorestream_optionstemperaturetool_choicetoolstop_logprobstop_puserextra_headersextra_query
extra_bodytimeoutc                  ^^ [        T5        SS0U=(       d    0 EnSUU4S jjn!U R                  S[        0 SU_SU_SU_SU_S	U_S
U_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_S[        T5      _UUUUSUUUTUUUS.E[        R
                  5      [        UUUU U!S9[        [        [        [              [        5      SS9$ )a  Wrapper over the `client.chat.completions.create()` method that provides richer integrations with Python specific types
& returns a `ParsedChatCompletion` object, which is a subclass of the standard `ChatCompletion` class.

You can pass a pydantic model to this method and it will automatically convert the model
into a JSON schema, send it to the API and parse the response content back into the given model.

This method will also automatically parse `function` tool calls if:
- You use the `openai.pydantic_function_tool()` helper method
- You mark your tool schema with `"strict": True`

Example usage:
```py
from pydantic import BaseModel
from openai import OpenAI


class Step(BaseModel):
    explanation: str
    output: str


class MathResponse(BaseModel):
    steps: List[Step]
    final_answer: str


client = OpenAI()
completion = client.beta.chat.completions.parse(
    model="gpt-4o-2024-08-06",
    messages=[
        {"role": "system", "content": "You are a helpful math tutor."},
        {"role": "user", "content": "solve 8x + 31 = 2"},
    ],
    response_format=MathResponse,
)

message = completion.choices[0].message
if message.parsed:
    print(message.parsed.steps)
    print("answer: ", message.parsed.final_answer)
```
X-Stainless-Helper-Methodbeta.chat.completions.parsec                   > [        TU TS9$ N)rC   chat_completioninput_tools_parse_chat_completionraw_completionrC   rX   s    r8   parser!Completions.parse.<locals>.parser       ) / .! r;   /chat/completionsmessagesmodelrB   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rC   F)rQ   rR   rS   rT   streamrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   post_parserbodyoptionscast_torq   rj   r%   return%ParsedChatCompletion[ResponseFormatT])_validate_input_tools_postr   _type_to_response_formatr   CompletionCreateParamsr   r
   r   r'   r   r%   "r7   ro   rp   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   rk   s"       `                    `        r8   parseCompletions.parse>   s   ` 	e$ ()F
"

	 	 zz U U ():	
 $]   !*  ,-B !*  !*  *+> !*  '(8!" &'?'P#$ !$0 "#&4#.#."$0" ;> )??A!D )+'%" 2?CDnU]  /
 /	
r;   c                r   SS0U=(       d    0 En[        U R                  R                  R                  R                  40 SU_SU_SU_SS_S[        U5      _S	U_S
U_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S U_S!U_S"U_S#U_S$U _6n![        U!UUS%9$ )&a  Wrapper over the `client.chat.completions.create(stream=True)` method that provides a more granular event API
and automatic accumulation of each delta.

This also supports all of the parsing utilities that `.parse()` does.

Unlike `.create(stream=True)`, the `.stream()` method requires usage within a context manager to prevent accidental leakage of the response:

```py
with client.beta.chat.completions.stream(
    model="gpt-4o-2024-08-06",
    messages=[...],
) as stream:
    for event in stream:
        if event.type == "content.delta":
            print(event.delta, flush=True, end="")
```

When the context manager is entered, a `ChatCompletionStream` instance is returned which, like `.create(stream=True)` is an iterator. The full list of events that are yielded by the iterator are outlined in [these docs](https://github.com/openai/openai-python/blob/main/helpers.md#chat-completions-events).

When the context manager exits, the response will be closed, however the `stream` instance is still available outside
the context manager.
ra   beta.chat.completions.streamro   rp   rB   rq   TrC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rT   rS   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   rC   rf   )r   _clientchatcompletionscreater}   r#   "r7   ro   rp   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   api_requests"                                     r8   rq   Completions.stream   s   z ()G
"

 =DLL))00#=
#=
 #=
 	#=

 #=
 5_E#=
 0#=
 (#=
  #=
 "#=
 #=
 #8#=
 "#=
 #=
 "#=
  !#=
" !4##=
$ "%#=
& .'#=
( )#=
* &+#=
, -#=
. /#=
0 *1#=
2 $3#=
4 $5#=
6 7#=
8 &9#=
: ;#=
< =#=
> (?#=
@ $A#=
B "C#=
D E#=
H ++
 	
r;    )ry   r5   )ry   r>   Bro   $Iterable[ChatCompletionMessageParam]rp   Union[str, ChatModel]rB   -Optional[ChatCompletionAudioParam] | NotGivenrC   z type[ResponseFormatT] | NotGivenrD   Optional[float] | NotGivenrE   0completion_create_params.FunctionCall | NotGivenrF   6Iterable[completion_create_params.Function] | NotGivenrG   #Optional[Dict[str, int]] | NotGivenrH   Optional[bool] | NotGivenrI   Optional[int] | NotGivenrJ   r   rK   #Optional[Dict[str, str]] | NotGivenrL   1Optional[List[ChatCompletionModality]] | NotGivenrM   r   rN   bool | NotGivenrO   9Optional[ChatCompletionPredictionContentParam] | NotGivenrP   r   rQ   r   rR   /Optional[Literal['auto', 'default']] | NotGivenrS   *Union[Optional[str], List[str]] | NotGivenrT   r   rU   5Optional[ChatCompletionStreamOptionsParam] | NotGivenrV   r   rW   .ChatCompletionToolChoiceOptionParam | NotGivenrX   ,Iterable[ChatCompletionToolParam] | NotGivenrY   r   rZ   r   r[   str | NotGivenr\   Headers | Noner]   Query | Noner^   Body | Noner_   'float | httpx.Timeout | None | NotGivenry   rz   )Bro   r   rp   r   rB   r   rC   Jcompletion_create_params.ResponseFormat | type[ResponseFormatT] | NotGivenrD   r   rE   r   rF   r   rG   r   rH   r   rI   r   rJ   r   rK   r   rL   r   rM   r   rN   r   rO   r   rP   r   rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rX   r   rY   r   rZ   r   r[   r   r\   r   r]   r   r^   r   r_   r   ry   z,ChatCompletionStreamManager[ResponseFormatT]__name__
__module____qualname____firstlineno__r   r9   r?   r   r   rq   __static_attributes__r   r;   r8   r/   r/   *   s   0 0 6 6 @I<E8AJSLU:C.7:C/88AHQ&//8PY7@)2HQ;D+4PY2;FO>G1:,5( )-$("&;DIM
 7M
 %	M

 =M
 :M
 6M
 HM
 JM
 8M
 ,M
  8M
 -M
 6M
 FM
  $!M
" -#M
$ N%M
& 5'M
( ')M
* F+M
, 9-M
. )/M
0 N1M
2 03M
4 D5M
6 <7M
8 /9M
: *;M
< =M
B &CM
D "EM
F  GM
H 9IM
J 
/KM
h @Ifo8AJSLU:C.7:C/88AHQ&//8PY7@)2HQ;D+4PY2;FO>G1:,5( )-$("&;DIi
 7i
 %	i

 =i
 di
 6i
 Hi
 Ji
 8i
 ,i
  8i
 -i
 6i
 Fi
  $!i
" -#i
$ N%i
& 5'i
( ')i
* F+i
, 9-i
. )/i
0 N1i
2 03i
4 D5i
6 <7i
8 /9i
: *;i
< =i
B &Ci
D "Ei
F  Gi
H 9Ii
J 
6Ki
 i
r;   c                     \ rS rSr\S	S j5       r\S
S j5       r\\\\\\\\\\\\\\\\\\\\\\\\\\SSS\S.                                                                 SS jjr\\\\\\\\\\\\\\\\\\\\\\\\\\SSS\S.                                                                 SS jjr	Sr
g)r0   i9  c                    [        U 5      $ r4   )AsyncCompletionsWithRawResponser6   s    r8   r9   "AsyncCompletions.with_raw_response:  s     /t44r;   c                    [        U 5      $ r=   )%AsyncCompletionsWithStreamingResponser6   s    r8   r?   (AsyncCompletions.with_streaming_responseD  s     5T::r;   NrA   c                  ^^#    [        T5        SS0U=(       d    0 EnSUU4S jjn!U R                  S[        0 SU_SU_SU_SU_S	U_S
U_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_S[        T5      _UUUUSUUUTUUUS.E[        R
                  5      I Sh  vN [        UUUU U!S9[        [        [        [              [        5      SS9I Sh  vN $  N< N7f)a  Wrapper over the `client.chat.completions.create()` method that provides richer integrations with Python specific types
& returns a `ParsedChatCompletion` object, which is a subclass of the standard `ChatCompletion` class.

You can pass a pydantic model to this method and it will automatically convert the model
into a JSON schema, send it to the API and parse the response content back into the given model.

This method will also automatically parse `function` tool calls if:
- You use the `openai.pydantic_function_tool()` helper method
- You mark your tool schema with `"strict": True`

Example usage:
```py
from pydantic import BaseModel
from openai import AsyncOpenAI


class Step(BaseModel):
    explanation: str
    output: str


class MathResponse(BaseModel):
    steps: List[Step]
    final_answer: str


client = AsyncOpenAI()
completion = await client.beta.chat.completions.parse(
    model="gpt-4o-2024-08-06",
    messages=[
        {"role": "system", "content": "You are a helpful math tutor."},
        {"role": "user", "content": "solve 8x + 31 = 2"},
    ],
    response_format=MathResponse,
)

message = completion.choices[0].message
if message.parsed:
    print(message.parsed.steps)
    print("answer: ", message.parsed.final_answer)
```
ra   rb   c                   > [        TU TS9$ rd   rg   ri   s    r8   rk   &AsyncCompletions.parse.<locals>.parser  rm   r;   rn   ro   rp   rB   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rC   F)rQ   rR   rT   rS   rq   rU   rV   rW   rX   rY   rZ   r[   Nrr   rt   rx   )r{   r|   r   r}   r   r~   r   r
   r   r'   r   r%   r   s"       `                    `        r8   r   AsyncCompletions.parseM  s    ` 	e$ ()F
"

	 	 ZZ,U U ():	
 $]   !*  ,-B !*  !*  *+> !*  '(8!" &'?'P#$ !$0" #&4#.#."$0" ;> )??A! !D )+'%" 2?CDnU]   /
 /
 /	
!/
s$   BCC
7CCCCc                   [        U5        SS0U=(       d    0 EnU R                  R                  R                  R                  " S&0 SU_SU_SU_SS_S[        U5      _S	U_S
U_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S U_S!U_S"U_S#U_S$U _6n![        U!UUS%9$ )'a0  Wrapper over the `client.chat.completions.create(stream=True)` method that provides a more granular event API
and automatic accumulation of each delta.

This also supports all of the parsing utilities that `.parse()` does.

Unlike `.create(stream=True)`, the `.stream()` method requires usage within a context manager to prevent accidental leakage of the response:

```py
async with client.beta.chat.completions.stream(
    model="gpt-4o-2024-08-06",
    messages=[...],
) as stream:
    async for event in stream:
        if event.type == "content.delta":
            print(event.delta, flush=True, end="")
```

When the context manager is entered, an `AsyncChatCompletionStream` instance is returned which, like `.create(stream=True)` is an async iterator. The full list of events that are yielded by the iterator are outlined in [these docs](https://github.com/openai/openai-python/blob/main/helpers.md#chat-completions-events).

When the context manager exits, the response will be closed, however the `stream` instance is still available outside
the context manager.
ra   r   ro   rp   rB   rq   TrC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r   r   )r{   r   r   r   r   r}   r$   r   s"                                     r8   rq   AsyncCompletions.stream  s   x 	e$ ()G
"

 ll''33:: "
"
"
 "
 	"

 5_E"
 0"
 ("
  "
 ""
 "
 #8"
 ""
 "
 ""
 "
  !4!"
" "#"
$ .%"
& '"
( &)"
* +"
, -"
. */"
0 $1"
2 $3"
4 5"
6 &7"
8 9"
: ;"
< (="
> $?"
@ "A"
B C"
F 0+
 	
r;   r   )ry   r   )ry   r   r   )Bro   r   rp   r   rB   r   rC   r   rD   r   rE   r   rF   r   rG   r   rH   r   rI   r   rJ   r   rK   r   rL   r   rM   r   rN   r   rO   r   rP   r   rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rX   r   rY   r   rZ   r   r[   r   r\   r   r]   r   r^   r   r_   r   ry   z1AsyncChatCompletionStreamManager[ResponseFormatT]r   r   r;   r8   r0   r0   9  s   5 5 ; ; @I<E8AJSLU:C.7:C/88AHQ&//8PY7@)2HQ;D+4PY2;FO>G1:,5( )-$("&;DIM
 7M
 %	M

 =M
 :M
 6M
 HM
 JM
 8M
 ,M
  8M
 -M
 6M
 FM
  $!M
" -#M
$ N%M
& 5'M
( ')M
* F+M
, 9-M
. )/M
0 N1M
2 03M
4 D5M
6 <7M
8 /9M
: *;M
< =M
B &CM
D "EM
F  GM
H 9IM
J 
/KM
h @Ifo8AJSLU:C.7:C/88AHQ&//8PY7@)2HQ;D+4PY2;FO>G1:,5( )-$("&;DIj
 7j
 %	j

 =j
 dj
 6j
 Hj
 Jj
 8j
 ,j
  8j
 -j
 6j
 Fj
  $!j
" -#j
$ N%j
& 5'j
( ')j
* F+j
, 9-j
. )/j
0 N1j
2 03j
4 D5j
6 <7j
8 /9j
: *;j
< =j
B &Cj
D "Ej
F  Gj
H 9Ij
J 
;Kj
 j
r;   c                      \ rS rSrSS jrSrg)r5   iI  c                Z    Xl         [        R                  " UR                  5      U l        g N)_completionsr   to_raw_response_wrapperr   r7   r   s     r8   __init__#CompletionsWithRawResponse.__init__J  s#    '%==

r;   r   r   Nr   r/   ry   Noner   r   r   r   r   r   r   r;   r8   r5   r5   I      
r;   r5   c                      \ rS rSrSS jrSrg)r   iR  c                Z    Xl         [        R                  " UR                  5      U l        g r   )r   r   async_to_raw_response_wrapperr   r   s     r8   r   (AsyncCompletionsWithRawResponse.__init__S  s#    '%CC

r;   r   Nr   r0   ry   r   r   r   r;   r8   r   r   R  r   r;   r   c                      \ rS rSrSS jrSrg)r>   i[  c                D    Xl         [        UR                  5      U l        g r   )r   r   r   r   s     r8   r   )CompletionsWithStreamingResponse.__init__\  s    '1

r;   r   Nr   r   r   r;   r8   r>   r>   [  r   r;   r>   c                      \ rS rSrSS jrSrg)r   id  c                D    Xl         [        UR                  5      U l        g r   )r   r   r   r   s     r8   r   .AsyncCompletionsWithStreamingResponse.__init__e  s    '7

r;   r   Nr   r   r   r;   r8   r   r   d  r   r;   r   )P
__future__r   typingr   r   r   r   r   r	   r
   	functoolsr   typing_extensionsr   httpx r   _typesr   r   r   r   r   _utilsr   r   _compatr   	_resourcer   r   	_responser   r   
_streamingr   
types.chatr   _base_clientr   lib._parsingr   r   r{   r    rh   r!   r}   types.chat_modelr"   lib.streaming.chatr#   r$   types.chat.chat_completionr%    types.chat.chat_completion_chunkr&   !types.chat.parsed_chat_completionr'   #types.chat.chat_completion_modalityr(   %types.chat.chat_completion_tool_paramr)   &types.chat.chat_completion_audio_paramr*   (types.chat.chat_completion_message_paramr+   /types.chat.chat_completion_stream_options_paramr,   3types.chat.chat_completion_prediction_content_paramr-   3types.chat.chat_completion_tool_choice_option_paramr.   __all__r/   r0   r5   r   r>   r   r   r;   r8   <module>r      s    # D D D  %  ! @ @ = ' ; Z ! 3 1  + ` 9 D F J M O S ` h g,
-L
/ L
^M
' M
`
 

 

 

 
r;   