
    qid                         d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ  G d d	e      Zy
)z!LLM logging observer for Pipecat.    )logger)FunctionCallInProgressFrameFunctionCallResultFrameLLMContextFrameLLMFullResponseEndFrameLLMFullResponseStartFrameLLMMessagesFrameLLMTextFrame)BaseObserverFramePushed)OpenAILLMContextFrame)FrameDirection)
LLMServicec                       e Zd ZdZdefdZy)LLMLogObservera  Observer to log LLM activity to the console.

    Logs all frame instances (only from/to LLM service) of:

    - LLMFullResponseStartFrame
    - LLMFullResponseEndFrame
    - LLMTextFrame
    - FunctionCallInProgressFrame
    - LLMMessagesFrame
    - OpenAILLMContextFrame

    This allows you to track when the LLM starts responding, what it generates,
    and when it finishes.
    datac                   K   |j                   }|j                  }|j                  }|j                  }|j                  }t        |t              st        |t              sy|dz  }d}t        |t        t        f      r8t        |t              rdnd}	t        j                  d| d| d|	 d	|d
d	       yt        |t              r.t        j                  d| d| d|j                  d|d
d	       yt        |t              r[|t        j                  k7  rHt        j                  d| d| d|j                    d|j"                  d|j$                   d|d
d       yt        |t&              r.t        j                  d| d| d|j(                   d|d
d	       yt        |t*        t,        f      rdt        |t,              r|j.                  j(                  n|j.                  j1                         }
t        j                  d| d| d|
 d|d
d	       yt        |t2              r;t        j                  d| d| d|j                    d|j4                   d|d
d       yyw)zHandle frame push events and log LLM-related activities.

        Args:
            data: The frame push event data containing source, destination,
                  frame, direction, and timestamp information.
        Ni ʚ;u   →STARTENDu   🧠  z LLM z RESPONSE at z.2fsz LLM GENERATING: z at z LLM FUNCTION CALL (z): (z) at z LLM MESSAGES FRAME: z LLM CONTEXT FRAME: z LLM FUNCTION CALL RESULT ()sourcedestinationframe	direction	timestamp
isinstancer   r   r   r   debugr
   textr   r   
DOWNSTREAMtool_call_idfunction_name	argumentsr	   messagesr   r   contextget_messagesr   result)selfr   srcdstr   r   r   time_secarroweventr%   s              \/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/observers/loggers/llm_log_observer.pyon_push_framezLLMLogObserver.on_push_frame*   sw     kk

NN	NN	#z*:c:3N}, e79PQR)%1JKGQVELL5QugU5'xPSnTUVW|,LL5Qug->uzznDQYZ]P^^_`a u9:^666LLuAeW$89K9K8LCPUPcPcOffghmhwhwgxx}  G  HK  ~L  LM  N /0LLwau$9%..9IhWZ^[\] 1FGH e%:; &&]]//1 
 LL5q-A(4PXY\~]^_`67LLwau$?@R@R?SSVW\WcWcVddhiqruhvvwx 8s   I I"N)__name__
__module____qualname____doc__r   r0        r/   r   r      s    4 4r6   r   N)r4   logurur   pipecat.frames.framesr   r   r   r   r   r	   r
   pipecat.observers.base_observerr   r   1pipecat.processors.aggregators.openai_llm_contextr   "pipecat.processors.frame_processorr   pipecat.services.llm_servicer   r   r5   r6   r/   <module>r=      s9    (    F S = 3D\ Dr6   