o
    ͩZh                     @  s   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rPd dlmZ dddZG dd deZG dd deZG d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              	   C  s   |  d}|j  |d}|d}|jdddddd	d
d |jdddd
d |jdddtd |jdddtd |jdddtd |jdddtd |jddd |jd d!d"d# |jtj	t
d$ d S )%Nzchat.completions.createzrequired argumentszoptional argumentsz-gz	--messageappend   )ZROLEZ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   )funcZ
args_model)
add_parser_action_groupspopadd_argument_groupadd_argumentintfloatset_defaultsCLIChatCompletioncreateCLIChatCompletionCreateArgs)r   subreqopt r1   W/var/www/html/lang_env/lib/python3.10/site-packages/openai/cli/_api/chat/completions.pyregister   sX   



	r3   c                   @  s   e Zd ZU ded< ded< dS )
CLIMessager   rolestrcontentN)__name__
__module____qualname____annotations__r1   r1   r1   r2   r4   O   s   
 r4   c                   @  sf   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 )r-   zList[CLIMessage]messager6   modelNzOptional[int]n
max_tokenszOptional[float]temperaturetop_pzOptional[str]stopFboolstream)
r8   r9   r:   r;   r>   r?   r@   rA   rB   rD   r1   r1   r1   r2   r-   T   s   
 r-   c                   @  s6   e Zd ZedddZedd	d
ZedddZdS )r+   argsr-   r   r   c                 C  s   | j dd | jD dd}| jd ur| j|d< | jd ur!| j|d< | jd ur+| j|d< | jd ur5| j|d< | jr=| j|d	< | jd urG| j|d
< | jrRt	t
t|S tt
t|S )Nc                 S  s$   g | ]}t td  |j|jdqS )user)r5   r7   )r   r   r5   r7   ).0r<   r1   r1   r2   
<listcomp>d   s    z,CLIChatCompletion.create.<locals>.<listcomp>F)r=   messagesrD   r@   rB   rA   r>   rD   r?   )r=   r<   r@   rB   rA   r>   rD   r?   r+   _stream_creater   r   _creater   )rE   paramsr1   r1   r2   r,   `   s*   










zCLIChatCompletion.createrL   r   c                 C  s   t  jjjdi | }t|jdk}|jD ]2}|r#tjd	|j
 |jjd ur-|jjnd}tj| |s<|dsBtjd tj  qd S )N   ===== Chat Completion {} =====
r   
r1   )r   chatcompletionsr,   lenchoicessysstdoutwriteformatindexr<   r7   endswithflush)rL   
completionshould_print_headerchoicer7   r1   r1   r2   rK   |   s   
zCLIChatCompletion._creater   c                 C  s   t tt t jjjdi | }|D ]4}t|jdk}|jD ]'}|r,t	j
d|j |jjp1d}t	j
| |r@t	j
d t	j
  qqt	j
d d S )NrM   rN    rO   r1   )r   r   r   r   rP   rQ   r,   rR   rS   rT   rU   rV   rW   rX   deltar7   rZ   )rL   rD   chunkr\   r]   r7   r1   r1   r2   rJ      s   
z CLIChatCompletion._stream_createN)rE   r-   r   r   )rL   r   r   r   )rL   r   r   r   )r8   r9   r:   staticmethodr,   rK   rJ   r1   r1   r1   r2   r+   _   s    r+   )r   r   r   r   )
__future__r   rT   typingr   r   r   r   argparser   Ztyping_extensionsr   r	   _utilsr   Z_modelsr   Z
_streamingr   Z
types.chatr   r   r   Z#types.chat.completion_create_paramsr   r   r   r3   r4   r-   r+   r1   r1   r1   r2   <module>   s     
6