pyc • Lines: 3536�
�d�ju� � �
� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl
mZ d dlmZ d dl
Z
d dlmZ e� ej d�� Zej% ddd �
� ej% ddd
�� ej% ddd�� ej% ddd�� ej' � Ze j* j- d� Z e j0 d� Z e j0 d� Ze j6 j9 dd� j; d� ZdZdZ e j6 j9 dd� Z!e j6 j9 de!� Z"e j6 j9 de!� Z#dZ$dZ%d Z&d!Z'd"d#d$�Z(d%Z) e*e)� jW � Z,d&Z-d'Z.d(Z/e j6 j9 d)e!� Z0e j6 j9 d*e!� Z1d+Z2d,Z3d-Z4d.Z5e j* j- d/� Z6d0Z7d1Z8d2Z9e j* j- d3� Z:e j* j- d4� Z;e j* j- d5� Z<i a=d6� Z> e>e;i � Z? e>e<i � Z@ e>e j* j- d7� i � ZAd�d8�ZBd9� ZCd�d:�ZDd;� ZEi ZFd<� ZGd�d=�ZHd>� ZId?� ZJd�d@�ZKdA� ZLdB� ZMdC� ZNdD� ZOdE� ZPdF� ZQd�dG�ZRdH� ZSdI� ZTdJ� ZU d�dK�ZVd�dL�ZWdM� ZXd�dN�ZYdO� ZZe7fdP�Z[e7dQfdR�Z\dS� Z]dT� Z^dU� Z_d�dV�Z`dWdXdY�ZadZ� Zbd[� Zcd\Zdd]� Ze d�d^�Zfd�d_�Zgi Zhi Zi ej� � Zkd`Zlda� Zmdb� Zndc� Zodd� Zp d�de�Zqdf� Zrdg� Zsd�dh�Ztdi� Zudj� Zv d�dk�Zw d�dl�Zx d�dn�Zydo� Zzd�dp�Z{dq� Z|dr� Z}ds� Z~dt� Z d�du�Z�dv� Z�dw� Z�dx� Z�dy� Z�dz� Z�d{� Z�d|� Z�d}� Z�d~� Z�d� Z�d�� Z�d�� Z�d�� Z� e�j d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�dddddde5fd��Z� d�d��Z� d�d��Z�d�� Z� e_� \ Z�Z�Z�Z?Z@e�s e�d�� e�dm� � eDe�� Z� e�d� e�e�� � d�e�� �� e�j@ r ec� e�d � � e�d�� Z�e��jG � �jI � d�k( Z�e�d�k( r e�� yy)�� N)�SequenceMatcher)�datetime)�load_dotenvzSelf-chat story generator)�descriptionz--config� aY Path to a custom JSON task list to use instead of the default (~/local-ai-files/tasks.json). The file may be a plain task list or an object with 'tasks' plus optional 'genre_checklists'. Each task may also carry its own 'checklist' (editor/moderator) that wins over the genre checklist. Combine with --defaults to also include the default tasks.)�default�helpz
--defaults�
store_truez`Also load the default tasks (~/local-ai-files/tasks.json) in addition to the ones from --config.)�actionr z --dry-runz�Validate the task config and environment and print the full plan for each task (genre/checklist resolution, script enforcement, medium feasibility) without making any LLM call, then exit.z--gpuz�Run the self-chat agents (kolpo/kaya/editor/moderator) on the interactive GPU llama-server (8081) instead of the RAM-backed CPU server (8079). Each /api/chat request carries mode="gpu" so chat-webui routes the agent tasks to the GPU lane.z~/local-ai-files/stories�STORIES_PREMIUM_DIR�STORIES_ADMIN_DIR�SELF_CHAT_BASE_URLzhttp://localhost:3001�/�kolpo�kaya�SELF_CHAT_PASSWORD�SELF_CHAT_A_PASSWORD�SELF_CHAT_B_PASSWORD�[END CONVERSATION]g @g >@�
�Kolpo�Kaya��A�Bz)/home/palash/local-ai-files/self_chat.txti� �editor� moderator�SELF_CHAT_EDITOR_PASSWORD�SELF_CHAT_MODERATOR_PASSWORDz//home/palash/local-ai-files/contexts/editor.txtz2/home/palash/local-ai-files/contexts/moderator.txtz1/home/palash/local-ai-files/contexts/critique.txt� z~/local-ai-files/tasks.jsonz self-chat� � z&~/local-ai-files/genre_checklists.jsonz0~/local-ai-files/contexts/genre_persona_map.jsonz+~/local-ai-files/contexts/persona_pool.jsonc �� � t | d�� 5 }t j |� cd d d � S # 1 sw Y y xY w# t t j f$ r}t d| � d|� d�� |cY d }~S d }~ww xY w)N�utf-8��encodingz[persona] Could not load �: u — using fallback)�open�json�load�FileNotFoundError�JSONDecodeError�print)�filepath�fallback�f�es �&/home/palash/git/local-ai/self-chat.py�load_json_filer3 v sk � ��
�(�W�
-� ���9�9�Q�<� � � ���t�3�3�4� �
�)�(��2�a�S�8K�L�M�����s/ �
: �.� : �7�: �: �A1�A,�&A1�,A1z-~/local-ai-files/contexts/master_details.jsonc � �� |j |� xs |j d� }|dk( r|r|D �cg c]
}|dk7 s� |�� }}�xs g �g }| j � D ]q \ }}|r||vr�
|j � D ]R \ } }
|
j d� }|r&t �fd�dD � � }|dk( r|s�5|dk( rd�vr�?|j || |
f� �T �s |sd d
d�d dd�d
�}
dd|
fS |t vs"t | d t t | d � k\ r,t
|� }t j |� |dd�t |<