o
    Ù°“i  ã                   @   s”   d dl mZ d dlmZ er$d dlmZ d dlmZ d dlmZm	Z	m
Z
 dddefd	d
„Z				ddd„Z				ddd„Z				ddd„ZdS )é    )ÚIterable)ÚTYPE_CHECKING)ÚTextPart)ÚUnion)ÚChatCompletionMessageParamÚ ChatCompletionSystemMessageParamÚChatCompletionContentPartParamÚmessager   Úreturnc                 C   s   t | tƒo|  d¡dkS )NÚroleÚsystem)Ú
isinstanceÚdictÚget)r	   © r   úY/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/ai/_openai_completions_api.pyÚ_is_system_instruction   s   r   Úmessagesú$Iterable[ChatCompletionMessageParam]ú list[ChatCompletionMessageParam]c                 C   s   t | tƒsg S dd„ | D ƒS )Nc                 S   s   g | ]}t |ƒr|‘qS r   )r   )Ú.0r	   r   r   r   Ú
<listcomp>   s    z,_get_system_instructions.<locals>.<listcomp>)r   r   )r   r   r   r   Ú_get_system_instructions   s   
r   Úcontentú4Union[str, Iterable[ChatCompletionContentPartParam]]ú	list[str]c                 C   sf   t | tƒr| gS t | tƒsg S g }| D ]}t |tƒr0| d¡dkr0| dd ¡}|d ur0| |¡ q|S )NÚtypeÚtext)r   Ústrr   r   r   Úappend)r   Ú
text_itemsÚpartr   r   r   r   Ú_get_text_items   s   


€r"   Úsystem_instructionsú&list[ChatCompletionSystemMessageParam]úlist[TextPart]c                 C   sL   g }| D ]}t |tƒsq| d¡}|d u rqdd„ t|ƒD ƒ}||7 }q|S )Nr   c                 S   s   g | ]}d |dœ‘qS )r   )r   r   r   )r   r   r   r   r   r   =   s    
ÿz2_transform_system_instructions.<locals>.<listcomp>)r   r   r   r"   )r#   Úinstruction_text_partsÚinstructionr   Ú
text_partsr   r   r   Ú_transform_system_instructions0   s   

ÿ
r)   N)r   r   r
   r   )r   r   r
   r   )r#   r$   r
   r%   )Úcollections.abcr   Útypingr   Úsentry_sdk._typesr   r   Úopenai.types.chatr   r   r   Úboolr   r   r"   r)   r   r   r   r   Ú<module>   s,    ÿ
þ	ÿ
þÿþ