
    +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y)    )annotationsN)TYPE_CHECKINGListOptionalcast)ArgumentParser)Literal
NamedTuple   )
get_client)	BaseModel   )Stream)ChatCompletionRoleChatCompletionChunkCompletionCreateParams)CompletionCreateParamsStreaming"CompletionCreateParamsNonStreaming)_SubParsersActionc           	     X   | j                  d      }|j                  j                          |j                  d      }|j                  d      }|j	                  dddddd	d
       |j	                  dddd
       |j	                  dddt
               |j	                  dddt
               |j	                  dddt               |j	                  dddt               |j	                  dd       |j	                  d d!d"#       |j                  t        j                  t        $       y )%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)	subparsersubreqopts       S/var/www/html/venv/lib/python3.12/site-packages/openai/cli/_api/chat/completions.pyregisterr4      sc   


8
9C

 
 !5
6C

 
 !5
6C#q    	   E	   T>0[bef$    6    R   Z&IR^_+22?Z[    c                  "    e Zd ZU ded<   ded<   y)
CLIMessager   rolestrcontentN)__name__
__module____qualname____annotations__ r5   r3   r7   r7   O   s    
Lr5   r7   c                  v    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<   y)r.   zList[CLIMessage]messager9   modelNzOptional[int]n
max_tokenszOptional[float]temperaturetop_pzOptional[str]stopFboolstream)
r;   r<   r=   r>   rC   rD   rE   rF   rG   rI   r?   r5   r3   r.   r.   T   sI    JA} $J$#'K'!E?!D-FDr5   r.   c                  B    e Zd Zedd       Zedd       Zedd       Zy)r,   c                   | j                   | j                  D cg c],  }t        t        d   |j                        |j
                  d. c}| j                  | j                  | j                  | j                  dd}| j                  r| j                  |d<   | j                  | j                  |d<   | j                  r#t        j                  t        t        |            S t        j                  t        t         |            S c c}w )Nuser)r8   r:   F)rB   messagesrC   rE   rF   rG   rI   rI   rD   )rB   rA   r   r	   r8   r:   rC   rE   rF   rG   rI   rD   r,   _stream_creater   _creater   )argsrA   paramss      r3   r-   zCLIChatCompletion.create`   s     ZZimiuiu^egfow||<Y ++ZZII*
 ;;#{{F8??&#'??F< ;;$33D9XZ`4abb ((.PRX)YZZ%s   1Dc                `    t               j                  j                  j                  di | }t	        |j
                        dkD  }|j
                  D ]  }|r8t        j                  j                  dj                  |j                               |j                  j                  |j                  j                  nd}t        j                  j                  |       |s|j                  d      st        j                  j                  d       t        j                  j                           y )N   ===== Chat Completion {} =====
None
r?   )r   chatcompletionsr-   lenchoicessysstdoutwriteformatindexrA   r:   endswithflush)rQ   
completionshould_print_headerchoicer:   s        r3   rO   zCLIChatCompletion._createx   s    9Z\&&2299CFC
!*"4"459 (( 
	F"

  !C!J!J6<<!XY060F0F0Rfnn,,X^GJJW%"'*:*:4*@

  &JJ
	r5   c                   t        t        t            t               j                  j
                  j                  di |       }|D ]  }t        |j                        dkD  }|j                  D ]  }|r8t        j                  j                  dj                  |j                               |j                  j                  xs d}t        j                  j                  |       |rt        j                  j                  d       t        j                  j!                            t        j                  j                  d       y )NrS   rT    rV   r?   )r   r   r   r   rW   rX   r-   rY   rZ   r[   r\   r]   r^   r_   deltar:   ra   )rQ   rI   chunkrc   rd   r:   s         r3   rN   z CLIChatCompletion._stream_create   s     &')M):):)F)F)M)M)WPV)W
  	#E"%emm"4q"8-- 
#&JJ$$%G%N%Nv||%\] ,,..4"

  )&JJ$$T*

  "
#	# 	

r5   N)rP   r.   returnrU   )rQ   r   ri   rU   )rQ   r   ri   rU   )r;   r<   r=   staticmethodr-   rO   rN   r?   r5   r3   r,   r,   _   s>    [ [.    r5   r,   )r/   z!_SubParsersAction[ArgumentParser]ri   rU   )
__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   r4   r7   r.   r,   r?   r5   r3   <module>rt      s`    " 
 6 6 # 1     ! 

 *3\l 
) = =r5   