o
    {$f                     @  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   )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opt r4   V/var/www/html/dev/env/lib/python3.10/site-packages/openai/cli/_api/chat/completions.pyregister   sX   



	r6   c                   @  s   e Zd ZU ded< ded< dS )
CLIMessager   rolestrcontentN)__name__
__module____qualname____annotations__r4   r4   r4   r5   r7   O   s   
 r7   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 )r0   zList[CLIMessage]messager9   modelNzOptional[int]n
max_tokenszOptional[float]temperaturetop_pzOptional[str]stopFboolstream)
r;   r<   r=   r>   rA   rB   rC   rD   rE   rG   r4   r4   r4   r5   r0   T   s   
 r0   c                   @  s6   e Zd ZedddZedd	d
ZedddZdS )r.   argsr0   r   r   c                 C  st   | j dd | jD | j| j| j| jdd}| jr| j|d< | jd ur'| j|d< | jr2t	t
t|S tt
t|S )Nc                 S  s$   g | ]}t td  |j|jdqS )user)r8   r:   )r   r   r8   r:   ).0r?   r4   r4   r5   
<listcomp>d   s    z,CLIChatCompletion.create.<locals>.<listcomp>F)r@   messagesrA   rC   rD   rE   rG   rG   rB   )r@   r?   rA   rC   rD   rE   rG   rB   r.   _stream_creater   r   _creater   )rH   paramsr4   r4   r5   r/   `   s"   


zCLIChatCompletion.createrO   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   
r4   )r   chatcompletionsr/   lenchoicessysstdoutwriteformatindexr?   r:   endswithflush)rO   
completionshould_print_headerchoicer:   r4   r4   r5   rN   x   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 )NrP   rQ    rR   r4   )r   r   r   r   rS   rT   r/   rU   rV   rW   rX   rY   rZ   r[   deltar:   r]   )rO   rG   chunkr_   r`   r:   r4   r4   r5   rM      s   
z CLIChatCompletion._stream_createN)rH   r0   r   r   )rO   r   r   r   )rO   r   r   r   )r;   r<   r=   staticmethodr/   rN   rM   r4   r4   r4   r5   r.   _   s    r.   )r   r   r   r   )
__future__r   rW   typingr   r   r   r   argparser   typing_extensionsr   r	   _utilsr   _modelsr   
_streamingr   
types.chatr   r   r   #types.chat.completion_create_paramsr   r   r   r6   r7   r0   r.   r4   r4   r4   r5   <module>   s     
6