o
    i5                     @  sj   d dl mZ d dlmZmZ d dlZd dlZG dd dejZ	G dd de	Z
G dd	 d	eZd
d ZdS )    )annotations)ComfyExtensionioNc                   @  s.   e Zd ZedddZeg dfdddZdS )ContextWindowsManualNodereturn	io.Schemac                 C  s  t jddddt jjdddt jjdd	d
dddt jjddddddt jjdtjjj	tjjj
tjjjtjjjgddt jjdd	d	dddt jjddddt jjdtjjjtjjjddt jjddddd d!t jjd"dd#dt jjd$d%d&dt jjd'dd(dgt jjd)dgdd*S )+NContextWindowsManualzContext Windows (Manual)contextzManually set context windows.model6The model to apply context windows to during sampling.tooltipcontext_length      !The length of the context window.Tmindefaultr   advancedcontext_overlapr      "The overlap of the context window.context_schedule!The stride of the context window.optionsr   context_strideGThe stride of the context window; only applicable to uniform schedules.closed_loopFNWhether to close the context window loop; only applicable to looped schedules.r   r   fuse_method.The method to use to fuse the context windows.r   r   r   dim   z.The dimension to apply the context windows to.)r   maxr   r   	freenoiseEWhether to apply FreeNoise noise shuffling, improves window blending.cond_retain_index_list zList of latent indices to retain in the conditioning tensors for each window, for example setting this to '0' will use the initial start image for each window.split_conds_to_windowszkWhether to split multiple conditionings (created by ConditionCombine) to each window based on region index.z7The model with context windows applied during sampling.)node_iddisplay_namecategorydescriptioninputsoutputsis_experimental)r   SchemaModelInputIntCombocomfycontext_windowsContextSchedulesSTATIC_STANDARDUNIFORM_STANDARDUNIFORM_LOOPEDBATCHEDBooleanContextFuseMethodsLIST_STATICPYRAMIDStringOutput)cls rG   @/mnt/c/Users/fbmor/ComfyUI/comfy_extras/nodes_context_windows.pydefine_schema   s8   z&ContextWindowsManualNode.define_schemaFr
   io.Model.Typer   intr   r   strr   r   boolr"   r%   r(   r*   	list[int]r,   io.Modelc                 C  sd   |  }tjjtj|tj|||||||	|
|d
|jd< tj| |	r-tj| t	
|S )N)
r   r"   r   r   r   r   r%   r(   r*   r,   context_handler)cloner9   r:   IndexListContextHandlerget_matching_context_scheduleget_matching_fuse_methodmodel_optionscreate_prepare_sampling_wrappercreate_sampler_sample_wrapperr   
NodeOutput)rF   r
   r   r   r   r   r   r"   r%   r(   r*   r,   rG   rG   rH   execute'   s"   


z ContextWindowsManualNode.executeNr   r   )r
   rJ   r   rK   r   rK   r   rL   r   rK   r   rM   r"   rL   r%   rK   r(   rM   r*   rN   r,   rM   r   rO   )__name__
__module____qualname__classmethodrI   rY   rG   rG   rG   rH   r      s    r   c                      s:   e Zd Zed fddZeg dfd fddZ  ZS )WanContextWindowsManualNoder   r   c                   s   t   }d|_d|_d|_tjjdddtjjddt	j
d	d
dddtjjddddddtjjdtjjjtjjjtjjjtjjjgddtjjddddddtjjddddtjjdtjjjtjjjddtjjddd dg|_|S )!NWanContextWindowsManualzWAN Context Windows (Manual)z9Manually set context windows for WAN-like models (dim=2).r
   r   r   r   r   r   Q   r   T)r   r'   stepr   r   r   r   r      r   r   r   r   r   r   r   r   Fr    r!   r"   r#   r$   r(   r)   )superrI   r-   r.   r0   r   r5   r6   r7   nodesMAX_RESOLUTIONr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   r1   )rF   schema	__class__rG   rH   rI   >   s*   
z)WanContextWindowsManualNode.define_schemaFr
   rJ   r   rK   r   r   rL   r   r   rM   r"   r(   r*   rN   r,   rO   c                   sN   t |d d d d}t |d d d d}t j|||||||d||	|
dS )Nr   r   r      )r%   r(   r*   r,   )r'   rd   rY   )rF   r
   r   r   r   r   r   r"   r(   r*   r,   rh   rG   rH   rY   W   s   "z#WanContextWindowsManualNode.executerZ   )r
   rJ   r   rK   r   rK   r   rL   r   rK   r   rM   r"   rL   r(   rM   r*   rN   r,   rM   r   rO   )r[   r\   r]   r^   rI   rY   __classcell__rG   rG   rh   rH   r_   =   s    r_   c                   @  s   e Zd ZdddZdS )ContextWindowsExtensionr   list[type[io.ComfyNode]]c                   s
   t tgS N)r   r_   )selfrG   rG   rH   get_node_list`   s   z%ContextWindowsExtension.get_node_listN)r   rm   )r[   r\   r]   rp   rG   rG   rG   rH   rl   _   s    rl   c                   C  s   t  S rn   )rl   rG   rG   rG   rH   comfy_entrypointf   s   rq   )
__future__r   comfy_api.latestr   r   comfy.context_windowsr9   re   	ComfyNoder   r_   rl   rq   rG   rG   rG   rH   <module>   s    6"