Skip to content

Qwen

QwenCoder

QwenCoder(model_name: str, skill_sources: 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 Qwen 2.5 Coder.

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_template str

Prompt template for the system message that guides the model to generate code actions. Must define a {python_modules} placeholder for the skill_sources.

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 QWEN_API_KEY environment variable.

None
**kwargs

Default completion kwargs passed used for request and feedback calls. These are overriden by request and feedback specific kwargs.

{}
Source code in freeact/model/qwen/model.py
def __init__(
    self,
    model_name: str,
    skill_sources: 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,
):
    # Qwen 2.5 Coder models often hallucinate results prior
    # to code execution which is prevented by stopping at the
    # beginning of an ```output ...``` block. Also, Qwen Coder
    # models on Fireworks AI sometimes leak <|im_start|> tokens
    # after generating code blocks.
    default_kwargs = {
        "stop": ["```output", "<|im_start|>"],
    }

    super().__init__(
        model_name=model_name,
        execution_output_template=execution_output_template,
        execution_error_template=execution_error_template,
        system_instruction=system_template.format(python_modules=skill_sources or ""),
        api_key=api_key or os.getenv("QWEN_API_KEY"),
        **(default_kwargs | kwargs),
    )