刚刚,阿里开源了其最强代码模型:Qwen3-Coder-480B-A35B-Instruct,性能媲美 Claude Sonnet4

发布于:2025-07-31 ⋅ 阅读:(20) ⋅ 点赞:(0)

刚刚,阿里开源了其最强代码模型:Qwen3-Coder-480B-A35B-Instruct,性能媲美 Claude Sonnet4

刚刚,阿里开源了其最强代码模型:Qwen3-Coder-480B-A35B-Instruct,性能媲美 Claude Sonnet4

阿里最新开源的代码模型 Qwen3-Coder-480B-A35B-Instruct,拥有 480B 参数量,35B 激活参数,采用 Mixture-of-Experts 机制(MoE)。模型原生支持 256K 上下文长度,通过 YaRN 可扩展到 1M,在代码理解、生成与 Agent 能力上对标目前最强的 Claude Sonnet4。

此外,阿里还提供了基于 Gemini CLI 修改的 Qwen Code CLI 工具,进一步增强了 Qwen3-Coder 系列模型的解析器和工具支持。


一、快速体验

在这里插入图片描述


二、通义千问代码模型概览

下表列出了阿里云百炼平台上可用的主要代码模型及其参数和定价情况。

商业版模型对比

模型名称 版本 上下文长度 最大输入 最大输出 输入成本 输出成本 免费额度(注)
qwen3-coder-plus (与 qwen3-coder-plus-2025-07-22 能力相同) 稳定版 1,048,576 1,000,000 65,536 阶梯计价,详见下表 各100万Token 有效期内:百炼开通后180天
qwen3-coder-plus-2025-07-22 快照版
qwen-coder-plus (与 qwen-coder-plus-2024-11-06 相同) 稳定版 131,072 129,024 8,192 0.0035元/千Token 0.007元/千Token
qwen-coder-plus-latest 最新版
qwen-coder-turbo (与 qwen-coder-turbo-2024-09-19 相同) 稳定版 131,072 129,024 8,192 0.002元/千Token 0.006元/千Token
qwen-coder-turbo-latest 最新版
qwen3-coder-plus 阶梯计费明细
输入 Token 数 输入成本(每千 Token) 输出成本(每千 Token)
0~32K 0.004元 0.016元
32K~128K 0.006元 0.024元
128K~256K 0.01元 0.04元
256K~1M 0.02元 0.2元

提示: qwen3-coder-plus 支持 上下文缓存,可显著降低输入 Token 成本。

更多限流信息请参见限流


三、使用方法

以下示例展示了如何通过 OpenAI 兼容接口在 Python 和 curl 中调用通义千问代码模型。

1. 简单示例:寻找质数函数

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # 或直接填写 API Key
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen3-coder-plus",
    messages=[
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': (
            '请编写一个Python函数 find_prime_numbers,该函数接受一个整数 n 作为参数,'
            '并返回一个包含所有小于 n 的质数(素数)的列表。'
            '质数是指仅能被1和其自身整除的正整数,如2, 3, 5, 7等。'
            '不要输出非代码的内容。'
        )}
    ],
)
print(completion.choices[0].message.content)

返回结果:

```python
def find_prime_numbers(n):
    if n <= 2:
        return []
    
    primes = []
    
    for num in range(2, n):
        is_prime = True
        for i in range(2, int(num ** 0.5) + 1):
            if num % i == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(num)
    
    return primes
```

2. 工具调用:Coding Agent 能力

Qwen3-Coder 系列模型支持 Function Calling,可通过配置读写文件、列目录等工具,实现直接修改和生成文件。

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # 若未配置环境变量,可直接替换为您的 API Key
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

tools = [
    {
        "type": "function",
        "function": {
            "name": "read_file",
            "description": "读取指定路径的文件内容。",
            "parameters": {
                "type": "object",
                "properties": {
                    "path": {"type": "string", "description": "目标文件路径"}
                },
                "required": ["path"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "write_file",
            "description": "将内容写入指定文件,若文件不存在则创建。",
            "parameters": {
                "type": "object",
                "properties": {
                    "path": {"type": "string", "description": "目标文件路径"},
                    "content": {"type": "string", "description": "写入内容"}
                },
                "required": ["path", "content"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "list_directory",
            "description": "列出指定目录中的文件和子目录。",
            "parameters": {
                "type": "object",
                "properties": {
                    "path": {"type": "string", "description": "目标目录路径"}
                },
                "required": ["path"]
            }
        }
    }
]

messages = [{"role": "user", "content": "写一个python代码,快速排序,命名为quick_sort.py"}]
completion = client.chat.completions.create(
    model="qwen3-coder-plus",
    messages=messages,
    tools=tools
)

print(completion.model_dump_json())

示例返回(摘录):

{
    "choices": [
        {
            "message": {
                "tool_calls": [
                    {
                        "function": {
                            "name": "write_file",
                            "arguments": "{\"content\": \"def quick_sort(arr):...\", \"path\": \"quick_sort.py\"}"
                        }
                    }
                ]
            }
        }
    ]
}

模型通过 tool_calls 参数输出函数调用信息,运行相应工具即可完成代码文件的创建或更新。


四、代码补全功能

通义千问代码模型还提供基于 Completions 接口Partial Mode 的多种补全方案。

1. 前缀补全(Completions 接口)

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key=os.getenv("DASHSCOPE_API_KEY")
)

completion = client.completions.create(
    model="qwen2.5-coder-32b-instruct",
    prompt="<|fim_prefix|>写一个python的快速排序函数,def quick_sort(arr):<|fim_suffix|>",
)

print(completion.choices[0].text)

2. 前缀+后缀补全(Partial Mode)

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key=os.getenv("DASHSCOPE_API_KEY")
)

prefix_content = f"""def reverse_words_with_special_chars(s):
'''
反转字符串中的每个单词(保留非字母字符的位置),并保持单词顺序。
示例:
reverse_words_with_special_chars("Hello, world!") -> "olleH, dlrow!"
参数:
    s (str): 输入字符串(可能包含标点符号)
返回:
    str: 处理后的字符串,单词反转但非字母字符位置不变
'''
"""

suffix_content = "return result"

completion = client.completions.create(
    model="qwen2.5-coder-32b-instruct",
    prompt=f"<|fim_prefix|>{prefix_content}<|fim_suffix|>{suffix_content}<|fim_middle|>",
)

print(completion.choices[0].text)

五、总结

阿里开源的 Qwen3-Coder-480B-A35B-Instruct,凭借超大参数量、Mixture-of-Experts 架构及超长上下文能力,已经跃居行业前列。无论是交互式开发、Agent 驱动还是大规模代码补全,均能提供媲美或超越同级别竞品的性能。马上访问以上链接,一起体验这款最强代码模型吧!


网站公告

今日签到

点亮在社区的每一天
去签到