Skip to content

DeepSeek

DeepSeekV3

DeepSeekV3(model_name: str, skill_sources: str | None = None, system_extension: str | None = None, system_template: str = SYSTEM_TEMPLATE, execution_output_template: str = EXECUTION_OUTPUT_TEMPLATE, execution_error_template: str = EXECUTION_ERROR_TEMPLATE, api_key: str | None = None, **kwargs)

Bases: LiteLLM

Code action model class for DeepSeek V3.

Parameters:

Name Type Description Default
model_name str

The LiteLLM-specific name of the model.

required
skill_sources str | None

Skill modules source code to be included into system_template.

None
system_extension str | None

Domain- or environment-specific extensions to the system_template.

None
system_template str

Prompt template for the system instruction that guides the model to generate code actions. Must define a {python_modules} placeholder for the skill_sources and an {extensions} placeholder for the system_extension.

SYSTEM_TEMPLATE
execution_output_template str

A template for formatting successful code execution output. Must define an {execution_feedback} placeholder.

EXECUTION_OUTPUT_TEMPLATE
execution_error_template str

A template for formatting code execution errors. Must define an {execution_feedback} placeholder.

EXECUTION_ERROR_TEMPLATE
api_key str | None

Provider-specific API key. If not provided, reads from DEEPSEEK_API_KEY environment variable.

None
**kwargs

Default completion kwargs.

{}
Source code in freeact/model/deepseek/model.py
def __init__(
    self,
    model_name: str,
    skill_sources: str | None = None,
    system_extension: str | None = None,
    system_template: str = v3.SYSTEM_TEMPLATE,
    execution_output_template: str = v3.EXECUTION_OUTPUT_TEMPLATE,
    execution_error_template: str = v3.EXECUTION_ERROR_TEMPLATE,
    api_key: str | None = None,
    **kwargs,
):
    system_instruction = system_template.format(
        python_modules=skill_sources or "",
        extensions=system_extension or "",
    )
    super().__init__(
        model_name=model_name,
        execution_output_template=execution_output_template,
        execution_error_template=execution_error_template,
        system_instruction=system_instruction,
        api_key=api_key or os.getenv("DEEPSEEK_API_KEY"),
        **kwargs,
    )

DeepSeekR1

DeepSeekR1(model_name: str, skill_sources: str | None = None, instruction_extension: str | None = EXAMPLE_EXTENSION, instruction_template: str = INSTRUCTION_TEMPLATE, execution_output_template: str = EXECUTION_OUTPUT_TEMPLATE, execution_error_template: str = EXECUTION_ERROR_TEMPLATE, api_key: str | None = None, **kwargs)

Bases: LiteLLM

Code action model class for DeepSeek R1.

Does not set a system instruction. All instructions go into the first user message formatted with instruction_template.

Parameters:

Name Type Description Default
model_name str

The LiteLLM-specific name of the model.

required
skill_sources str | None

Skill modules source code to be included into system_template.

None
instruction_extension str | None

Domain- or environment-specific extensions to the instruction_template.

EXAMPLE_EXTENSION
instruction_template str

Prompt template that guides the model to generate code actions. Must define a {user_query} placeholder for the user query, an {extensions} placeholder for the instruction_extension and a {python_modules} placeholder for the skill_sources.

INSTRUCTION_TEMPLATE
execution_output_template str

A template for formatting successful code execution output. Must define an {execution_feedback} placeholder.

EXECUTION_OUTPUT_TEMPLATE
execution_error_template str

A template for formatting code execution errors. Must define an {execution_feedback} placeholder.

EXECUTION_ERROR_TEMPLATE
api_key str | None

Provider-specific API key. If not provided, reads from DEEPSEEK_API_KEY environment variable.

None
**kwargs

Default completion kwargs.

{}
Source code in freeact/model/deepseek/model.py
def __init__(
    self,
    model_name: str,
    skill_sources: str | None = None,
    instruction_extension: str | None = r1.EXAMPLE_EXTENSION,
    instruction_template: str = r1.INSTRUCTION_TEMPLATE,
    execution_output_template: str = r1.EXECUTION_OUTPUT_TEMPLATE,
    execution_error_template: str = r1.EXECUTION_ERROR_TEMPLATE,
    api_key: str | None = None,
    **kwargs,
):
    default_kwargs = {
        "temperature": 0.6,
        "max_tokens": 8192,
    }

    super().__init__(
        model_name=model_name,
        execution_output_template=execution_output_template,
        execution_error_template=execution_error_template,
        system_instruction=None,
        api_key=api_key or os.getenv("DEEPSEEK_API_KEY"),
        **(default_kwargs | kwargs),
    )

    self.instruction_template = instruction_template
    self.instruction_kwargs = {
        "python_modules": skill_sources or "",
        "extensions": instruction_extension or "",
    }

extract_code

extract_code(response: LiteLLMResponse) -> str | None

Extracts the last code block from response.text.

DeepSeek-R1 often produces code blocks during thinking but usually only the last code block in the actual response is relevant.

Source code in freeact/model/deepseek/model.py
def extract_code(self, response: LiteLLMResponse) -> str | None:
    """Extracts the last code block from `response.text`.

    DeepSeek-R1 often produces code blocks during thinking but usually
    only the last code block in the actual response is relevant.
    """
    return code_block(response.text, -1)