什么是通义千问3-Coder-Plus
Qwen3-Coder-Plus 是阿里巴巴通义实验室推出的开源代码大模型,属于 Qwen3-Coder 系列的最强版本,专为高效编程和智能体任务设计。
一、Qwen3-Coder-Plus 的核心特性
架构与性能
- 混合专家(MoE)架构:总参数 4800 亿,推理时仅激活 350 亿参数,兼顾性能与效率。
- 长上下文支持:原生支持 256K token,通过 YaRN 技术可扩展至 1M token,适合处理大型代码库。
- 多任务强化学习:通过执行驱动的代码强化学习(Code RL)和长时序交互(Agent RL),在 SWE-Bench 等复杂任务中达到开源模型 SOTA。
代码能力表现
- 生成与调试:支持从基础代码生成到复杂项目构建(如品牌官网生成仅需 5 分钟),代码测试和修复效率提升至分钟级。
- 智能体编程(Agentic Coding):可自主规划多步骤任务,调用浏览器、API 等工具完成复杂开发流程。
- 多语言与工具集成:支持 Python、JavaScript 等主流语言,并与 VS Code、Jupyter 等开发工具无缝集成。
二、API 申请与配置流程
1. 获取 API 密钥
步骤:
- 访问 https://bailian.console.aliyun.com/,注册并完成实名认证。
- 在模型市场中找到 Qwen3-Coder,创建 API 密钥并保存。
- 免费额度:新用户可领取 100 万 token 的免费调用额度。
2. 在 Roo Code 上配置 API
Roo Code 作为 AI 编程工具,需通过以下步骤接入 Qwen3-Coder:
安装 Roo Code:
- 从官网或插件市场下载安装(支持 VS Code 扩展)。
配置 API 参数:
- 打开 Roo Code 设置,选择 OpenAI 兼容模式。
填写以下信息:
- API Key:从阿里云百炼获取的密钥。
- Base URL:
https://dashscope.aliyuncs.com/compatible-mode/v1
- Model Name:
qwen3-coder-plus
。
验证配置:
- 输入测试提示词(如生成一个网页爬虫代码),观察返回结果是否正常。
使用 web 技术栈生成一个贪吃蛇游戏
我:使用 web 技术栈生成一个贪吃蛇游戏
Roo Code会给出一个Todo List updated:
- 创建项目结构
- 实现游戏逻辑
- 添加样式
- 测试游戏
- 完善游戏功能
然后按照这个顺序依次创建文件,直至测试游戏。
总结
对于这个简单的任务,它一次就生成成功了。据说Qwen3-Coder-Plus适合需要处理复杂代码逻辑或长时序任务的场景。有机会我们让它接手一个复杂项目试试。
大家觉得以下代码质量如何?
入口文件index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>贪吃蛇游戏</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>贪吃蛇游戏</h1>
<div class="game-container">
<canvas id="gameCanvas" width="400" height="400"></canvas>
</div>
<script src="script.js"></script>
</body>
</html>
样式文件style.css
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
h1 {
background-color: #333;
color: white;
padding: 1em 0;
margin: 0;
}
.game-container {
margin: 20px auto;
width: 400px;
height: 400px;
background-color: #fff;
border: 2px solid #333;
display: flex;
justify-content: center;
align-items: center;
}
canvas {
border: 1px solid #000;
}
游戏逻辑文件script.js
// 游戏配置
const config = {
canvasSize: 400,
gridSize: 20,
initialSpeed: 150,
foodColor: '#ff0000',
snakeColor: '#00ff00',
snakeBorderColor: '#006600'
};
// 获取画布上下文
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
// 蛇的表示
let snake = [{
x: 100,
y: 100
}];
// 食物的位置
let food = {
x: 200,
y: 200
};
// 游戏状态
let score = 0;
let dx = config.gridSize;
let dy = 0;
let speed = config.initialSpeed;
let gameInterval;
// 键盘控制
document.addEventListener('keydown', changeDirection);
// 开始游戏
function startGame() {
gameInterval = setInterval(gameLoop, speed);
}
// 游戏循环
function gameLoop() {
// 移动蛇
const head = {
x: snake[0].x + dx,
y: snake[0].y + dy
};
// 插入新头到蛇的前面
snake.unshift(head);
// 检查是否吃到食物
if (head.x === food.x && head.y === food.y) {
// 增加分数
score++;
// 生成新食物
placeFood();
} else {
// 移除蛇尾
snake.pop();
}
// 检查碰撞
if (checkCollision()) {
// 结束游戏
endGame();
return;
}
// 重绘游戏
drawGame();
}
// 绘制游戏
function drawGame() {
// 清除画布
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// 绘制分数
ctx.fillStyle = '#000';
ctx.font = '16px Arial';
ctx.fillText('分数: ' + score, 10, 20);
// 绘制蛇
for (let i = 0; i < snake.length; i++) {
ctx.fillStyle = config.snakeColor;
ctx.strokeStyle = config.snakeBorderColor;
ctx.fillRect(snake[i].x, snake[i].y, config.gridSize, config.gridSize);
ctx.strokeRect(snake[i].x, snake[i].y, config.gridSize, config.gridSize);
}
// 绘制食物
ctx.fillStyle = config.foodColor;
ctx.fillRect(food.x, food.y, config.gridSize, config.gridSize);
}
// 放置食物
function placeFood() {
// 计算随机位置
const newX = Math.floor(Math.random() * (config.canvasSize / config.gridSize)) * config.gridSize;
const newY = Math.floor(Math.random() * (config.canvasSize / config.gridSize)) * config.gridSize;
// 检查是否与蛇重叠
for (let i = 0; i < snake.length; i++) {
if (newX === snake[i].x && newY === snake[i].y) {
// 重试
placeFood();
return;
}
}
// 设置食物位置
food.x = newX;
food.y = newY;
}
// 改变方向
function changeDirection(event) {
const key = event.key;
// 避免反向移动
if (key === 'ArrowLeft' && dx === 0) {
dx = -config.gridSize;
dy = 0;
} else if (key === 'ArrowRight' && dx === 0) {
dx = config.gridSize;
dy = 0;
} else if (key === 'ArrowUp' && dy === 0) {
dx = 0;
dy = -config.gridSize;
} else if (key === 'ArrowDown' && dy === 0) {
dx = 0;
dy = config.gridSize;
}
}
// 检查碰撞
function checkCollision() {
// 检查墙碰撞
if (snake[0].x < 0 || snake[0].x >= config.canvasSize ||
snake[0].y < 0 || snake[0].y >= config.canvasSize) {
return true;
}
// 检查自身碰撞
for (let i = 1; i < snake.length; i++) {
if (snake[0].x === snake[i].x && snake[0].y === snake[i].y) {
return true;
}
}
return false;
}
// 结束游戏
function endGame() {
// 停止游戏循环
clearInterval(gameInterval);
// 显示游戏结束
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
ctx.fillRect(0, 0, canvas.width, canvas.height, 50);
ctx.fillStyle = '#fff';
ctx.font = '30px Arial';
ctx.fillText('游戏结束', 90, 200);
ctx.font = '20px Arial';
ctx.fillText('分数: ' + score, 155, 240);
ctx.font = '16px Arial';
ctx.fillText('按空格键重新开始', 130, 270);
// 重置游戏
document.addEventListener('keydown', restartGame);
}
// 重新开始游戏
function restartGame(event) {
if (event.key === ' ') {
// 重置蛇
snake = [{
x: 100,
y: 100
}];
// 重置食物
food = {
x: 200,
y: 200
};
// 重置分数
score = 0;
// 重置方向
dx = config.gridSize;
dy = 0;
// 移除事件监听器
document.removeEventListener('keydown', restartGame);
// 开始新游戏
startGame();
}
}
// 初始化游戏
startGame();