
    	h                        d dl mZ d dlZd dlmZ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 d	d
lmZ d	dlmZmZmZ d	dlmZmZ erd dlmZ ddZ G d de          Z G d de          Z G d d          ZdS )    )annotationsN)TYPE_CHECKINGListOptionalcast)ArgumentParser)Literal
NamedTuple   )
get_client)	BaseModel   )Stream)ChatCompletionRoleChatCompletionChunkCompletionCreateParams)CompletionCreateParamsStreaming"CompletionCreateParamsNonStreaming)_SubParsersAction	subparser!_SubParsersAction[ArgumentParser]returnNonec           	        |                      d          }|j                                         |                    d          }|                    d          }|                    dddddd	d
           |                    dddd
           |                    dddt
                     |                    dddt
                     |                    dddt                     |                    dddt                     |                    dd           |                    d d!d"#           |                    t          j	        t          $           d S )%Nzchat.completions.createzrequired argumentszoptional argumentsz-gz	--messageappend   )ROLECONTENTzbA message in `{role} {content}` format. Use this argument multiple times to add multiple messages.T)actionnargsmetavarhelprequiredz-mz--modelzThe model to use.)r"   r#   z-nz--nz6How many completions to generate for the conversation.)r"   typez-Mz--max-tokensz)The maximum number of tokens to generate.z-tz--temperaturezWhat sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.

Mutually exclusive with `top_p`.z-Pz--top_pa  An alternative to sampling with temperature, called nucleus sampling, where the 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.

            Mutually exclusive with `temperature`.z--stopzCA stop sequence at which to stop generating tokens for the message.)r"   z--streamz!Stream messages as they're ready.
store_true)r"   r   )func
args_model)
add_parser_action_groupspopadd_argument_groupadd_argumentintfloatset_defaultsCLIChatCompletioncreateCLIChatCompletionCreateArgs)r   subreqopts       m/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/openai/cli/_api/chat/completions.pyregisterr7      s   


8
9
9C

 
 !5
6
6C

 
 !5
6
6C#q      	     E	     T>0[befff$      6      R     Z&IR^___+2?Z[[[[[    c                  $    e Zd ZU ded<   ded<   dS )
CLIMessager   rolestrcontentN)__name__
__module____qualname____annotations__ r8   r6   r:   r:   O   s%         LLLLLr8   r:   c                  x    e Zd ZU ded<   ded<   dZded<   dZded<   dZd	ed
<   dZd	ed<   dZded<   dZ	ded<   dS )r2   zList[CLIMessage]messager<   modelNzOptional[int]n
max_tokenszOptional[float]temperaturetop_pzOptional[str]stopFboolstream)
r>   r?   r@   rA   rF   rG   rH   rI   rJ   rL   rB   r8   r6   r2   r2   T   s         JJJA $J$$$$#'K''''!E!!!!DFr8   r2   c                  V    e Zd Zedd            Zedd            Zedd
            ZdS )r0   argsr2   r   r   c                   | j         d | j        D             dd}| j        
| j        |d<   | j        
| j        |d<   | j        
| j        |d<   | j        
| j        |d<   | j        r
| j        |d<   | j        
| j        |d	<   | j        r-t          	                    t          t          |                    S t                              t          t          |                    S )
Nc                ^    g | ]*}t          t          d          |j                  |j        d+S )user)r;   r=   )r   r	   r;   r=   ).0rD   s     r6   
<listcomp>z,CLIChatCompletion.create.<locals>.<listcomp>d   s?       ^egfow|<<YY  r8   F)rE   messagesrL   rH   rJ   rI   rF   rL   rG   )rE   rD   rH   rJ   rI   rF   rL   rG   r0   _stream_creater   r   _creater   )rN   paramss     r6   r1   zCLIChatCompletion.create`   s     Z imiu   *
 *
 '$($4F=!9 !YF6N:!"jF7O6&F3K; 	+#{F8?&#'?F< ; 	c$33D9XZ`4a4abbb ((.PRX)Y)YZZZr8   rW   r   c                    t                      j        j        j        di | }t	          |j                  dk    }|j        D ]}|r7t          j                            d	                    |j
                             |j        j        |j        j        nd}t          j                            |           |s|                    d          st          j                            d           t          j                                         d S )N   ===== Chat Completion {} =====
r   
rB   )r   chatcompletionsr1   lenchoicessysstdoutwriteformatindexrD   r=   endswithflush)rW   
completionshould_print_headerchoicer=   s        r6   rV   zCLIChatCompletion._create|   s    9Z\\&29CCFCC
!*"4559 ( 
	 
	F" Z
  !C!J!J6<!X!XYYY060F0Rfn,,X^GJW%%%" ''*:*:4*@*@ '
  &&&J
	 
	r8   r   c                ^   t          t          t                    t                      j        j        j        di |           }|D ]}t          |j                  dk    }|j        D ]}|r7t          j
                            d                    |j                             |j        j        pd}t          j
                            |           |rt          j
                            d           t          j
                                         t          j
                            d           d S )NrY   rZ    r[   rB   )r   r   r   r   r\   r]   r1   r^   r_   r`   ra   rb   rc   rd   deltar=   rf   )rW   rL   chunkrh   ri   r=   s         r6   rU   z CLIChatCompletion._stream_create   s!    &')M):)F)M)W)WPV)W)W
 
  	# 	#E"%em"4"4q"8- 
# 
#& ^J$$%G%N%Nv|%\%\]]] ,.4"
  )))& +J$$T***
  """"
# 	
r8   N)rN   r2   r   r   )rW   r   r   r   )rW   r   r   r   )r>   r?   r@   staticmethodr1   rV   rU   rB   r8   r6   r0   r0   _   sv        [ [ [ \[6    \    \  r8   r0   )r   r   r   r   )
__future__r   r`   typingr   r   r   r   argparser   typing_extensionsr	   r
   _utilsr   _modelsr   
_streamingr   
types.chatr   r   r   #types.chat.completion_create_paramsr   r   r   r7   r:   r2   r0   rB   r8   r6   <module>rx      s   " " " " " " 



 6 6 6 6 6 6 6 6 6 6 6 6 # # # # # # 1 1 1 1 1 1 1 1                         ! ! ! ! ! !         
       
  +******3\ 3\ 3\ 3\l       
    )   A A A A A A A A A Ar8   