o
    i                     @   sv   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ eG dd	 d	e
jZG d
d deZdS )zFDeepSeek LLM service implementation using OpenAI-compatible interface.    )	dataclass)Optional)logger)OpenAILLMInvocationParams)BaseOpenAILLMService)OpenAILLMServicec                   @   s   e Zd ZdZdS )DeepSeekLLMSettingsz Settings for DeepSeekLLMService.N)__name__
__module____qualname____doc__ r   r   Q/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/services/deepseek/llm.pyr      s    r   c                
       sr   e Zd ZU dZeZeed< dddddededee d	ee f fd
dZ	d fdd	Z
dedefddZ  ZS )DeepSeekLLMServicezA service for interacting with DeepSeek's API using the OpenAI-compatible interface.

    This service extends OpenAILLMService to connect to DeepSeek's API endpoint while
    maintaining full compatibility with OpenAI's interface and functionality.
    	_settingszhttps://api.deepseek.com/v1N)base_urlmodelsettingsapi_keyr   r   r   c                   sV   | j dd}|dur| dd ||_|dur|| t jd|||d| dS )a  Initialize the DeepSeek LLM service.

        Args:
            api_key: The API key for accessing DeepSeek's API.
            base_url: The base URL for DeepSeek API. Defaults to "https://api.deepseek.com/v1".
            model: The model identifier to use. Defaults to "deepseek-chat".

                .. deprecated:: 0.0.105
                    Use ``settings=DeepSeekLLMService.Settings(model=...)`` instead.

            settings: Runtime-updatable settings. When provided alongside deprecated
                parameters, ``settings`` values take precedence.
            **kwargs: Additional keyword arguments passed to OpenAILLMService.
        zdeepseek-chat)r   Nr   )r   r   r   r   )Settings"_warn_init_param_moved_to_settingsr   apply_updatesuper__init__)selfr   r   r   r   kwargsdefault_settings	__class__r   r   r   $   s   
zDeepSeekLLMService.__init__c                    s&   t d|  t j||fi |S )a  Create OpenAI-compatible client for DeepSeek API endpoint.

        Args:
            api_key: The API key for authentication. If None, uses instance default.
            base_url: The base URL for the API. If None, uses instance default.
            **kwargs: Additional keyword arguments for client configuration.

        Returns:
            An OpenAI-compatible client configured for DeepSeek's API.
        z"Creating DeepSeek client with api )r   debugr   create_client)r   r   r   r   r   r   r   r    K   s   z DeepSeekLLMService.create_clientparams_from_contextreturnc              	   C   sN   | j jdddi| j j| j j| j j| j j| j jd}|| || j j |S )a  Build parameters for DeepSeek chat completion request.

        DeepSeek doesn't support some OpenAI parameters like seed and max_completion_tokens.

        Args:
            params_from_context: Parameters, derived from the LLM context, to
                use for the chat completion. Contains messages, tools, and tool
                choice.

        Returns:
            Dictionary of parameters for the chat completion request.
        Tinclude_usage)r   streamstream_optionsfrequency_penaltypresence_penaltytemperaturetop_p
max_tokens)	r   r   r&   r'   r(   r)   r*   updateextra)r   r!   paramsr   r   r   _build_chat_completion_paramsY   s   
z0DeepSeekLLMService._build_chat_completion_params)NN)r	   r
   r   r   r   r   __annotations__strr   r   r    r   dictr.   __classcell__r   r   r   r   r      s$   
 'r   N)r   dataclassesr   typingr   logurur   )pipecat.adapters.services.open_ai_adapterr    pipecat.services.openai.base_llmr   pipecat.services.openai.llmr   r   r   r   r   r   r   r   <module>   s   