
    +h                    <   d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlZddlmZmZmZmZmZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& erddl'm(Z(m)Z) ddgZ* G d de      Z+ G d de      Z, G d d      Z- G d d      Z.y)    )annotations)TYPE_CHECKINGDictListUnionOptionaloverload)LiteralN   )	NOT_GIVENBodyQueryHeadersNotGiven)required_argsmaybe_transform)SyncAPIResourceAsyncAPIResource)to_raw_response_wrapperasync_to_raw_response_wrapper)StreamAsyncStream)ChatCompletionChatCompletionChunkChatCompletionToolParamChatCompletionMessageParam#ChatCompletionToolChoiceOptionParamcompletion_create_params)make_request_options)OpenAIAsyncOpenAICompletionsAsyncCompletionsc                      e Zd ZU ded<   d fdZeeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zeeeeeeeeeeeeeeeeddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Zeeeeeeeeeeeeeeeeddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z eddgg d      eeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZ	S )r"   CompletionsWithRawResponsewith_raw_responsec                D    t         |   |       t        |       | _        y N)super__init__r%   r&   selfclient	__class__s     T/var/www/html/venv/lib/python3.12/site-packages/openai/resources/chat/completions.pyr*   zCompletions.__init__"   s     !;D!A    Nfrequency_penaltyfunction_call	functions
logit_bias
max_tokensnpresence_penaltyresponse_formatseedstopstreamtemperaturetool_choicetoolstop_puserextra_headersextra_query
extra_bodytimeoutmessagesmodelc                    ya  
        Creates a model response for the given chat conversation.

        Args:
          messages: A list of messages comprising the conversation so far.
              [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).

          model: ID of the model to use. See the
              [model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
              table for details on which models work with the Chat API.

          frequency_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on their
              existing frequency in the text so far, decreasing the model's likelihood to
              repeat the same line verbatim.

              [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/gpt/parameter-details)

          function_call: Deprecated in favor of `tool_choice`.

              Controls which (if any) function is called by the model. `none` means the model
              will not call a function and instead generates a message. `auto` means the model
              can pick between generating a message or calling a function. Specifying a
              particular function via `{"name": "my_function"}` forces the model to call that
              function.

              `none` is the default when no functions are present. `auto`` is the default if
              functions are present.

          functions: Deprecated in favor of `tools`.

              A list of functions the model may generate JSON inputs for.

          logit_bias: Modify the likelihood of specified tokens appearing in the completion.

              Accepts a JSON object that maps tokens (specified by their token ID in the
              tokenizer) to an associated bias value from -100 to 100. Mathematically, the
              bias is added to the logits generated by the model prior to sampling. The exact
              effect will vary per model, but values between -1 and 1 should decrease or
              increase likelihood of selection; values like -100 or 100 should result in a ban
              or exclusive selection of the relevant token.

          max_tokens: The maximum number of [tokens](/tokenizer) to generate in the chat completion.

              The total length of input tokens and generated tokens is limited by the model's
              context length.
              [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
              for counting tokens.

          n: How many chat completion choices to generate for each input message.

          presence_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on
              whether they appear in the text so far, increasing the model's likelihood to
              talk about new topics.

              [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/gpt/parameter-details)

          response_format: An object specifying the format that the model must output.

              Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
              message the model generates is valid JSON.

              **Important:** when using JSON mode, you **must** also instruct the model to
              produce JSON yourself via a system or user message. Without this, the model may
              generate an unending stream of whitespace until the generation reaches the token
              limit, resulting in increased latency and appearance of a "stuck" request. Also
              note that the message content may be partially cut off if
              `finish_reason="length"`, which indicates the generation exceeded `max_tokens`
              or the conversation exceeded the max context length.

          seed: This feature is in Beta. If specified, our system will make a best effort to
              sample deterministically, such that repeated requests with the same `seed` and
              parameters should return the same result. Determinism is not guaranteed, and you
              should refer to the `system_fingerprint` response parameter to monitor changes
              in the backend.

          stop: Up to 4 sequences where the API will stop generating further tokens.

          stream: If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
              sent as data-only
              [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
              as they become available, with the stream terminated by a `data: [DONE]`
              message.
              [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).

          temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
              make the output more random, while lower values like 0.2 will make it more
              focused and deterministic.

              We generally recommend altering this or `top_p` but not both.

          tool_choice: Controls which (if any) function is called by the model. `none` means the model
              will not call a function and instead generates a message. `auto` means the model
              can pick between generating a message or calling a function. Specifying a
              particular function via
              `{"type: "function", "function": {"name": "my_function"}}` forces the model to
              call that function.

              `none` is the default when no functions are present. `auto` is the default if
              functions are present.

          tools: A list of tools the model may call. Currently, only functions are supported as a
              tool. Use this to provide a list of functions the model may generate JSON inputs
              for.

          top_p: An alternative to sampling with temperature, called nucleus sampling, where the
              model considers the results of the tokens with top_p probability mass. So 0.1
              means only the tokens comprising the top 10% probability mass are considered.

              We generally recommend altering this or `temperature` but not both.

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        N r,   rF   rG   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   s                          r/   createzCompletions.create&       R 	r0   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   r>   r?   r@   rA   rB   rC   rD   rE   c                    ya  
        Creates a model response for the given chat conversation.

        Args:
          messages: A list of messages comprising the conversation so far.
              [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).

          model: ID of the model to use. See the
              [model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility)
              table for details on which models work with the Chat API.

          stream: If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
              sent as data-only
              [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
              as they become available, with the stream terminated by a `data: [DONE]`
              message.
              [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).

          frequency_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on their
              existing frequency in the text so far, decreasing the model's likelihood to
              repeat the same line verbatim.

              [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/gpt/parameter-details)

          function_call: Deprecated in favor of `tool_choice`.

              Controls which (if any) function is called by the model. `none` means the model
              will not call a function and instead generates a message. `auto` means the model
              can pick between generating a message or calling a function. Specifying a
              particular function via `{"name": "my_function"}` forces the model to call that
              function.

              `none` is the default when no functions are present. `auto`` is the default if
              functions are present.

          functions: Deprecated in favor of `tools`.

              A list of functions the model may generate JSON inputs for.

          logit_bias: Modify the likelihood of specified tokens appearing in the completion.

              Accepts a JSON object that maps tokens (specified by their token ID in the
              tokenizer) to an associated bias value from -100 to 100. Mathematically, the
              bias is added to the logits generated by the model prior to sampling. The exact
              effect will vary per model, but values between -1 and 1 should decrease or
              increase likelihood of selection; values like -100 or 100 should result in a ban
              or exclusive selection of the relevant token.

          max_tokens: The maximum number of [tokens](/tokenizer) to generate in the chat completion.

              The total length of input tokens and generated tokens is limited by the model's
              context length.
              [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
              for counting tokens.

          n: How many chat completion choices to generate for each input message.

          presence_penalty: Number between -2.0 and 2.0. Positive values penalize new tokens based on
              whether they appear in the text so far, increasing the model's likelihood to
              talk about new topics.

              [See more information about frequency and presence penalties.](https://platform.openai.com/docs/guides/gpt/parameter-details)

          response_format: An object specifying the format that the model must output.

              Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
              message the model generates is valid JSON.

              **Important:** when using JSON mode, you **must** also instruct the model to
              produce JSON yourself via a system or user message. Without this, the model may
              generate an unending stream of whitespace until the generation reaches the token
              limit, resulting in increased latency and appearance of a "stuck" request. Also
              note that the message content may be partially cut off if
              `finish_reason="length"`, which indicates the generation exceeded `max_tokens`
              or the conversation exceeded the max context length.

          seed: This feature is in Beta. If specified, our system will make a best effort to
              sample deterministically, such that repeated requests with the same `seed` and
              parameters should return the same result. Determinism is not guaranteed, and you
              should refer to the `system_fingerprint` response parameter to monitor changes
              in the backend.

          stop: Up to 4 sequences where the API will stop generating further tokens.

          temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
              make the output more random, while lower values like 0.2 will make it more
              focused and deterministic.

              We generally recommend altering this or `top_p` but not both.

          tool_choice: Controls which (if any) function is called by the model. `none` means the model
              will not call a function and instead generates a message. `auto` means the model
              can pick between generating a message or calling a function. Specifying a
              particular function via
              `{"type: "function", "function": {"name": "my_function"}}` forces the model to
              call that function.

              `none` is the default when no functions are present. `auto` is the default if
              functions are present.

          tools: A list of tools the model may call. Currently, only functions are supported as a
              tool. Use this to provide a list of functions the model may generate JSON inputs
              for.

          top_p: An alternative to sampling with temperature, called nucleus sampling, where the
              model considers the results of the tokens with top_p probability mass. So 0.1
              means only the tokens comprising the top 10% probability mass are considered.

              We generally recommend altering this or `temperature` but not both.

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        NrJ   r,   rF   rG   r<   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   r>   r?   r@   rA   rB   rC   rD   rE   s                          r/   rL   zCompletions.create   rM   r0   c                    yrP   rJ   rQ   s                          r/   rL   zCompletions.create|  rM   r0   rF   rG   r<   c          
        | j                  dt        i d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|it        j                        t	        ||||      t
        |xs dt        t                 S Nz/chat/completionsrF   rG   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   )rB   rC   rD   rE   F)bodyoptionscast_tor<   
stream_cls)_postr   r   CompletionCreateParamsr   r   r   r   rK   s                          r/   rL   zCompletions.create'  s6   ^ zz U (): $]	
   !* !*  '(8 & D D f "; ";  U!" U#$ D%( )??+. )+Q[el #?U12=  
 	
r0   )r-   r    returnNone.rF    List[ChatCompletionMessageParam]rG     Union[str, Literal['gpt-4-1106-preview', 'gpt-4-vision-preview', 'gpt-4', 'gpt-4-0314', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0314', 'gpt-4-32k-0613', 'gpt-3.5-turbo-1106', 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0301', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k-0613']]r2   Optional[float] | NotGivenr3   0completion_create_params.FunctionCall | NotGivenr4   2List[completion_create_params.Function] | NotGivenr5   #Optional[Dict[str, int]] | NotGivenr6   Optional[int] | NotGivenr7   re   r8   ra   r9   2completion_create_params.ResponseFormat | NotGivenr:   re   r;   *Union[Optional[str], List[str]] | NotGivenr<   z#Optional[Literal[False]] | NotGivenr=   ra   r>   .ChatCompletionToolChoiceOptionParam | NotGivenr?   (List[ChatCompletionToolParam] | NotGivenr@   ra   rA   str | NotGivenrB   Headers | NonerC   Query | NonerD   Body | NonerE   'float | httpx.Timeout | None | NotGivenr\   r   ).rF   r_   rG   r`   r<   Literal[True]r2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   zStream[ChatCompletionChunk]).rF   r_   rG   r`   r<   boolr2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   ,ChatCompletion | Stream[ChatCompletionChunk]).rF   r_   rG   r`   r2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r<   3Optional[Literal[False]] | Literal[True] | NotGivenr=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   rq   
__name__
__module____qualname____annotations__r*   r	   r   rL   r   __classcell__r.   s   @r/   r"   r"      s   11B 0 9BJSHQ:C/8&/7@NW)2;D6?2;FO:C,5( )-$("&;DYh 3h
	h. 6/h0 H1h2 F3h4 85h6 -7h8 $9h: 5;h< L=h> '?h@ 9AhB 4ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
[h hT 2 9BJSHQ:C/8&/7@NW)2;D2;FO:C,5( )-$("&;DYh 3h
	h. /h0 61h2 H3h4 F5h6 87h8 -9h: $;h< 5=h> L?h@ 'AhB 9ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
%[h hT 2 9BJSHQ:C/8&/7@NW)2;D2;FO:C,5( )-$("&;DYh 3h
	h. /h0 61h2 H3h4 F5h6 87h8 -9h: $;h< 5=h> L?h@ 'AhB 9ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
6[h hT J(*IJ0 9BJSHQ:C/8&/7@NW)2;DFO2;FO:C,5( )-$("&;DYM
 3M

	M
. 6/M
0 H1M
2 F3M
4 85M
6 -7M
8 $9M
: 5;M
< L=M
> '?M
@ 9AM
B DCM
D 0EM
F DGM
H 8IM
J *KM
L MM
R &SM
T "UM
V  WM
X 9YM
Z 
6[M
 KM
r0   c                      e Zd ZU ded<   d fdZeeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zeeeeeeeeeeeeeeeeddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Zeeeeeeeeeeeeeeeeddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z eddgg d      eeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZ	S )r#   AsyncCompletionsWithRawResponser&   c                D    t         |   |       t        |       | _        y r(   )r)   r*   r{   r&   r+   s     r/   r*   zAsyncCompletions.__init__{  s     !@!Fr0   Nr1   rF   rG   c                  K   ywrI   rJ   rK   s                          r/   rL   zAsyncCompletions.create       R 	   rN   c                  K   ywrP   rJ   rQ   s                          r/   rL   zAsyncCompletions.create*  r~   r   c                  K   ywrP   rJ   rQ   s                          r/   rL   zAsyncCompletions.create  r~   r   rS   c          
     *  K   | j                  dt        i d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|it        j                        t	        ||||      t
        |xs dt        t                  d {   S 7 wrU   )rZ   r   r   r[   r   r   r   r   rK   s                          r/   rL   zAsyncCompletions.create  sD    ^ ZZ U (): $]	
   !* !*  '(8 & D D f "; ";  U!" U#$ D%( )??+. )+Q[el #?U"#67=   
 
 	
 
s   B
BBB)r-   r!   r\   r]   r^   ).rF   r_   rG   r`   r<   ro   r2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   z AsyncStream[ChatCompletionChunk]).rF   r_   rG   r`   r<   rp   r2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   1ChatCompletion | AsyncStream[ChatCompletionChunk]).rF   r_   rG   r`   r2   ra   r3   rb   r4   rc   r5   rd   r6   re   r7   re   r8   ra   r9   rf   r:   re   r;   rg   r<   rr   r=   ra   r>   rh   r?   ri   r@   ra   rA   rj   rB   rk   rC   rl   rD   rm   rE   rn   r\   r   rs   ry   s   @r/   r#   r#   x  s   66G 0 9BJSHQ:C/8&/7@NW)2;D6?2;FO:C,5( )-$("&;DYh 3h
	h. 6/h0 H1h2 F3h4 85h6 -7h8 $9h: 5;h< L=h> '?h@ 9AhB 4ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
[h hT 2 9BJSHQ:C/8&/7@NW)2;D2;FO:C,5( )-$("&;DYh 3h
	h. /h0 61h2 H3h4 F5h6 87h8 -9h: $;h< 5=h> L?h@ 'AhB 9ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
*[h hT 2 9BJSHQ:C/8&/7@NW)2;D2;FO:C,5( )-$("&;DYh 3h
	h. /h0 61h2 H3h4 F5h6 87h8 -9h: $;h< 5=h> L?h@ 'AhB 9ChD 0EhF DGhH 8IhJ *KhL MhR &ShT "UhV  WhX 9YhZ 
;[h hT J(*IJ0 9BJSHQ:C/8&/7@NW)2;DFO2;FO:C,5( )-$("&;DYM
 3M

	M
. 6/M
0 H1M
2 F3M
4 85M
6 -7M
8 $9M
: 5;M
< L=M
> '?M
@ 9AM
B DCM
D 0EM
F DGM
H 8IM
J *KM
L MM
R &SM
T "UM
V  WM
X 9YM
Z 
;[M
 KM
r0   c                      e Zd ZddZy)r%   c                8    t        |j                        | _        y r(   )r   rL   r,   completionss     r/   r*   z#CompletionsWithRawResponse.__init__  s    -
r0   N)r   r"   r\   r]   rt   ru   rv   r*   rJ   r0   r/   r%   r%         
r0   r%   c                      e Zd ZddZy)r{   c                8    t        |j                        | _        y r(   )r   rL   r   s     r/   r*   z(AsyncCompletionsWithRawResponse.__init__  s    3
r0   N)r   r#   r\   r]   r   rJ   r0   r/   r{   r{     r   r0   r{   )/
__future__r   typingr   r   r   r   r   r	   typing_extensionsr
   httpx_typesr   r   r   r   r   _utilsr   r   	_resourcer   r   	_responser   r   
_streamingr   r   
types.chatr   r   r   r   r   r   _base_clientr   _clientr    r!   __all__r"   r#   r%   r{   rJ   r0   r/   <module>r      s{    # G G %  ? ? 4 : O -  1.,
-V	
/ V	
rV	
' V	
r
 

 
r0   