� ���g����UddlZddlmZddlmZiZeeejfed<iZ d defd�Z d d�Z defd�Z d �Z d �Zdefd �ZdS) �N)�Dict)�uuid4�tasks�task_idc��t�|d��|rg|t�|g��vrLt|�|��t|s!t�|d��dSdSdSdS)zQ Remove a completed or canceled task from the global `tasks` dictionary. N)r�pop� chat_tasks�get�remove)r�ids �`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/open_webui/tasks.py� cleanup_taskr s��� �I�I�g�t���� �%�g�����B�/�/�/�/��2����g�&�&�&��"�~� %� �N�N�2�t� $� $� $� $� $�%�%�/�/� %� %�c�>���tt�����tj|��}|���fd���|t �<t ����r!t �����n �gt �<�|fS)zM Create a new asyncio task and add it to the global task dictionary. c�$��t����S�N)r)�tr rs ��r �<lambda>zcreate_task.<locals>.<lambda> s���\�'�2�%>�%>�r) �strr�asyncio� create_task�add_done_callbackrr r �append)� coroutiner �taskrs ` @r rrs������%�'�'�l�l�G� � �y� )� )�D� ���>�>�>�>�>�?�?�?��E�'�N��~�~�b���#��2����g�&�&�&�&�!�� �2�� �D�=�rc�6�t�|��S)z) Retrieve a task by its task ID. )rr )rs r �get_taskr,s�� �9�9�W� � �rc�N�tt�����S)z- List all currently active task IDs. )�listr�keys�rr � list_tasksr"3s�� �� � � � � � �rc�8�t�|g��S)z7 List all tasks associated with a specific ID. )r r )r s r �list_task_ids_by_chat_idr$:s�� �>�>�"�b� !� !�!rc��$K�t�|��}|std|�d����|��� |�d{V��n9#tj$r't�|d��dd|�d�d�cYSwxYwdd |�d �d�S) zH Cancel a running task and remove it from the global task list. z Task with ID z not found.NTzTask z successfully stopped.)�status�messageFzFailed to stop task �.)rr � ValueError�cancelr�CancelledErrorr)rrs r � stop_taskr,As����� �9�9�W� � �D� �?��=��=�=�=�>�>�>��K�K�M�M�M�T�� � � � � � � � �� � !�T�T�T� � � �'�4� � � ��+R�7�+R�+R�+R�S�S�S�S�S�T���� �(I�w�(I�(I�(I� J� J�Js�A�3B�Br)r�typingr�uuidrrr�Task�__annotations__r rrrr"r$r,r!rr �<module>r1s��������������������"$��t�C��� ��#�#�#� � � %� %�#� %� %� %� %�����(�c��������"�"�"�K�S�K�K�K�K�K�Kr
Memory