
    qi                         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 ddlmZ e G d	 d
e
             Z G d de      Zy)zFDeepSeek LLM service implementation using OpenAI-compatible interface.    )	dataclass)Optional)logger)OpenAILLMInvocationParams)OpenAILLMSettings)OpenAILLMService)_warn_deprecated_paramc                       e Zd ZdZy)DeepSeekLLMSettingsz Settings for DeepSeekLLMService.N)__name__
__module____qualname____doc__     O/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/deepseek/llm.pyr   r      s    *r   r   c            
       v     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
Z	d fd	Z
dedefdZ x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                    t        d      }|t        dt         d       ||_        ||j                  |       t	        |   d|||d| y)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=OpenAILLMSettings(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   )r   r	   r   apply_updatesuper__init__)selfr   r   r   r   kwargsdefault_settings	__class__s          r   r   zDeepSeekLLMService.__init__%   s_    0 /_E "7,?I%*"
 ))(3a8FVaZ`ar   c                 V    t        j                  d|        t        |   ||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!   s       r   r$   z DeepSeekLLMService.create_clientL   s0     	9(DEw$WhA&AAr   params_from_contextreturnc           	      |   | j                   j                  dddi| j                   j                  | j                   j                  | j                   j                  | j                   j
                  | j                   j                  d}|j                  |       |j                  | 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%   paramss      r   _build_chat_completion_paramsz0DeepSeekLLMService._build_chat_completion_paramsZ   s     ^^)).5!%!A!A $ ? ?>>55^^))..33	
 	)*dnn**+r   )NN)r   r   r   r   r   Settings__annotations__strr   r   r$   r   dictr3   __classcell__)r!   s   @r   r   r      sx     #H"" 6#26%b %b 	%b
 }%b ./%bNBAZ _c r   r   N)r   dataclassesr   typingr   logurur   )pipecat.adapters.services.open_ai_adapterr    pipecat.services.openai.base_llmr   pipecat.services.openai.llmr   pipecat.services.settingsr	   r   r   r   r   r   <module>r@      sK    M !   O > 8 < 	+ 	 	[) [r   