a
    _g                     @  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rd dlmZ dd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)_SubParsersActionz!_SubParsersAction[ArgumentParser]None)	subparserreturnc              	   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 r0   n/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/openai/cli/_api/chat/completions.pyregister   sX    



	r2   c                   @  s   e Zd ZU ded< ded< dS )
CLIMessager   rolestrcontentN)__name__
__module____qualname____annotations__r0   r0   r0   r1   r3   O   s   
r3   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]messager5   modelNzOptional[int]n
max_tokenszOptional[float]temperaturetop_pzOptional[str]stopFboolstream)
r7   r8   r9   r:   r=   r>   r?   r@   rA   rC   r0   r0   r0   r1   r,   T   s   
r,   c                   @  sH   e Zd ZedddddZeddddd	Zed
ddddZdS )r*   r,   r   )argsr   c                 C  s   | j dd | jD dd}| jd ur.| j|d< | jd urB| j|d< | jd urV| j|d< | jd urj| j|d< | jrz| j|d	< | jd ur| j|d
< | jrt	t
t|S tt
t|S )Nc                 S  s$   g | ]}t td  |j|jdqS )user)r4   r6   )r   r   r4   r6   ).0r;   r0   r0   r1   
<listcomp>d   s   z,CLIChatCompletion.create.<locals>.<listcomp>F)r<   messagesrC   r?   rA   r@   r=   rC   r>   )r<   r;   r?   rA   r@   r=   rC   r>   r*   _stream_creater   r   _creater   )rD   paramsr0   r0   r1   r+   `   s*    










zCLIChatCompletion.creater   )rK   r   c                 C  s   t  jjjf i | }t|jdk}|jD ]d}|rFtjd	|j
 |jjd urZ|jjnd}tj| |sx|dstjd tj  q*d S )N   ===== Chat Completion {} =====
r   
)r   chatcompletionsr+   lenchoicessysstdoutwriteformatindexr;   r6   endswithflush)rK   
completionshould_print_headerchoicer6   r0   r0   r1   rJ   |   s    
zCLIChatCompletion._creater   c                 C  s   t tt t jjjf i | }|D ]h}t|jdk}|jD ]N}|rXt	j
d|j |jjpbd}t	j
| |rt	j
d t	j
  q<q$t	j
d d S )NrL   rM    rN   )r   r   r   r   rO   rP   r+   rQ   rR   rS   rT   rU   rV   rW   deltar6   rY   )rK   rC   chunkr[   r\   r6   r0   r0   r1   rI      s    
z CLIChatCompletion._stream_createN)r7   r8   r9   staticmethodr+   rJ   rI   r0   r0   r0   r1   r*   _   s   r*   )
__future__r   rS   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   r2   r3   r,   r*   r0   r0   r0   r1   <module>   s   6