o
    i                     @   s   d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZ e	deeef dZG d	d
 d
eee ZdS )zBase adapter for LLM provider integration.

This module provides the abstract base class for implementing LLM provider-specific
adapters that handle tool format conversion and standardization.
    )ABCabstractmethod)AnyDictGenericListTypeVar)logger)ToolsSchema)
LLMContextLLMContextMessageLLMSpecificMessageNotGivenTLLMInvocationParams)boundc                   @   s   e Zd ZdZeedefddZedede	fddZ
ededee fd	d
Zededeeeef  fddZdedefddZdedee fddZdedee eB fddZdS )BaseLLMAdaptera  Abstract base class for LLM provider adapters.

    Provides a standard interface for converting to provider-specific formats.

    Handles:

    - Extracting provider-specific parameters for LLM invocation from a
      universal LLM context
    - Converting standardized tools schema to provider-specific tool formats.
    - Extracting messages from the LLM context for the purposes of logging
      about the specific provider.

    Subclasses must implement provider-specific conversion logic.
    returnc                 C      dS )zGet the identifier used in LLMSpecificMessage instances for this LLM provider.

        Returns:
            The identifier string.
        N )selfr   r   U/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/adapters/base_llm_adapter.pyid_for_llm_specific_messages.   s   z+BaseLLMAdapter.id_for_llm_specific_messagescontextc                 K   r   )aR  Get provider-specific LLM invocation parameters from a universal LLM context.

        Args:
            context: The LLM context containing messages, tools, etc.
            **kwargs: Additional provider-specific arguments that subclasses can use.

        Returns:
            Provider-specific parameters for invoking the LLM.
        Nr   )r   r   kwargsr   r   r   get_llm_invocation_params8      z(BaseLLMAdapter.get_llm_invocation_paramstools_schemac                 C   r   )zConvert tools schema to the provider's specific format.

        Args:
            tools_schema: The standardized tools schema to convert.

        Returns:
            List of tools in the provider's expected format.
        Nr   )r   r   r   r   r   to_provider_tools_formatE   s   
z'BaseLLMAdapter.to_provider_tools_formatc                 C   r   )a  Get messages from a universal LLM context in a format ready for logging about this provider.

        Args:
            context: The LLM context containing messages.

        Returns:
            List of messages in a format ready for logging about this
            provider.
        Nr   r   r   r   r   r   get_messages_for_loggingQ   r   z'BaseLLMAdapter.get_messages_for_loggingmessagec                 C   s   t | j|dS )zCreate an LLM-specific message (as opposed to a standard message) for use in an LLMContext.

        Args:
            message: The message content.

        Returns:
            A LLMSpecificMessage instance.
        )llmr    )r   r   )r   r    r   r   r   create_llm_specific_message^   s   	z*BaseLLMAdapter.create_llm_specific_messagec                 C   s   | | jS )zGet messages from the LLM context, including standard and LLM-specific messages.

        Args:
            context: The LLM context containing messages.

        Returns:
            List of messages including standard and LLM-specific messages.
        )get_messagesr   r   r   r   r   r#   i   s   	zBaseLLMAdapter.get_messagestoolsc                 C   s,   t |trtdt|   | |S |S )a  Convert tools from standard format to provider format.

        Args:
            tools: Tools in standard format or provider-specific format.

        Returns:
            List of tools converted to provider format, or original tools
            if not in standard format.
        z(Retrieving the tools using the adapter: )
isinstancer
   r	   debugtyper   )r   r$   r   r   r   from_standard_toolst   s   


z"BaseLLMAdapter.from_standard_toolsN)__name__
__module____qualname____doc__propertyr   strr   r   r   r   r
   r   r   r   r   r   r   r"   r   r#   r   r(   r   r   r   r   r      s     r   N)r,   abcr   r   typingr   r   r   r   r   logurur	   %pipecat.adapters.schemas.tools_schemar
   *pipecat.processors.aggregators.llm_contextr   r   r   r   dictr.   r   r   r   r   r   r   <module>   s   