DashScope

Use Alibaba DashScope Qwen models with Kern agents.

Leverage DashScope's powerful command models and more.

DashScope supports a wide range of models

We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:

  • qwen-plus model is good for most use-cases.

Authentication

Set your DASHSCOPE_API_KEY environment variable. Get your key from here.

1export DASHSCOPE_API_KEY=***
1setx DASHSCOPE_API_KEY ***

Example

Use DashScope with your Agent:

1from kern.agent import Agent
2from kern.models.dashscope import DashScope
3
4agent = Agent(
5 model=DashScope(id="qwen-plus"),
6 markdown=True
7)
8
9# Print the response in the terminal
10agent.print_response("Share a 2 sentence horror story.")
Note View more examples here.

Parameters

ParameterTypeDefaultDescription
idstr"qwen-plus"The id of the Qwen model to use
namestr"Qwen"The name of the model
providerstr"Dashscope"The provider of the model
api_keyOptional[str]NoneThe API key for DashScope (defaults to DASHSCOPE_API_KEY env var)
base_urlstr"https://dashscope-intl.aliyuncs.com/compatible-mode/v1"The base URL for the DashScope API. For users in Mainland China, you must set the base URL to https://dashscope.aliyuncs.com/compatible-mode/v1 to avoid the “invalid API key” error.
enable_thinkingboolFalseEnable thinking process for reasoning models
include_thoughtsOptional[bool]NoneInclude thinking process in response (alternative parameter)
thinking_budgetOptional[int]NoneBudget for thinking tokens in reasoning models

DashScope extends the OpenAI-compatible interface and supports most parameters from the OpenAI model.

Thinking Models

DashScope supports reasoning models with thinking capabilities:

1from kern.agent import Agent
2from kern.models.dashscope import DashScope
3
4agent = Agent(
5 model=DashScope(
6 id="qwen-plus",
7 enable_thinking=True,
8 thinking_budget=5000
9 ),
10 markdown=True
11)