就在刚刚,OpenAI重磅发布GPT-4.1系列三款全新模型,号称“史上最小、最快、最便宜”!不仅体积更轻量,整体性能还全面超越GPT-4o及其mini版。
本次发布的GPT-4.1系列包括三款模型:GPT-4.1、GPT-4.1 mini 和 GPT-4.1 nano。三者均支持高达100万 tokens的上下文窗口,最大输出可达32768个 tokens,知识覆盖截止至2024年6月。
根据OpenAI公布的基准测试结果,GPT-4.1系列在代码生成、指令执行以及长文本理解能力方面,全面领先于GPT-4o及GPT-4o mini,性能表现令人惊艳。
GPT-4.1 在各种编码任务上都比 GPT-4o 表现得更好,包括代理解决编码任务、前端编码、减少无关编辑、可靠地遵循差异格式、确保一致的工具使用等等。
虽然目前GPT-4.1系列模型需通过API调用,但是Cursor 和 Windsurf 都宣布,所有用户均可使用 GPT-4.1!现在我们可以通过第三方的平台来直接免费调用使用。
免费调用GPT 4.1的平台:
1、Cursor:【官方链接】
Cursor虽然已经内置了GPT4.1模型,但是默认并未开启,需要在设置中心,找到Model选项,在里面勾选GPT4.1模型,就可以愉快的免费使用了!
2、Windsurf :【官方链接】
相对来说,Windsurf 更显大方,因为官方有说明,即使是免费用户也可以无限免费使用GPT4.1模型,大家可以尽情使用,经过零度的测试,无论是代码生成,推理,图片识别能等,比之前的GPT -4o 好太多了!生成的代码直接完美运行,关键是生成速度极快!
跑酷游戏代码,由 Cursor 中的GPT4.1 生成
// 袋鼠跑酷游戏 by AI
// 只需在p5.js编辑器中粘贴本代码即可运行
let kangaroo;
let obstacles = [];
let groundY;
let score = 0;
let gameOver = false;
let bgOffset = 0;
function setup() {
createCanvas(600, 300);
groundY = height - 40;
kangaroo = new Kangaroo(60, groundY - 32);
obstacles.push(new Obstacle(width + 40));
textFont('monospace');
}
function draw() {
background(135, 206, 235); // 天空蓝
drawBackground();
// 地面
noStroke();
fill(80, 200, 120);
rect(0, groundY, width, 40);
if (!gameOver) {
kangaroo.update();
kangaroo.show();
// 障碍物逻辑
for (let i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
obstacles[i].show();
if (obstacles[i].hits(kangaroo)) {
gameOver = true;
}
if (obstacles[i].offscreen()) {
obstacles.splice(i, 1);
score++;
}
}
// 随机生成障碍物
if (obstacles.length < 2 && random() < 0.02) {
obstacles.push(new Obstacle(width + 40));
}
// 背景偏移
bgOffset -= 2;
} else {
kangaroo.show();
for (let obs of obstacles) obs.show();
fill(0, 180);
rect(width/2-90, height/2-40, 180, 60, 10);
fill(255);
textSize(20);
textAlign(CENTER, CENTER);
text('游戏结束', width/2, height/2-10);
textSize(14);
text('按R重来', width/2, height/2+18);
}
// 说明与得分
fill(0, 180);
rect(10, 10, 170, 50, 8);
fill(255);
textSize(14);
textAlign(LEFT, TOP);
text('空格:跳跃', 20, 18);
text('得分:' + score, 20, 38);
}
function keyPressed() {
if (key == ' ' && !gameOver) {
kangaroo.jump();
}
if (gameOver && (key == 'r' || key == 'R')) {
restartGame();
}
}
function restartGame() {
score = 0;
gameOver = false;
kangaroo = new Kangaroo(60, groundY - 32);
obstacles = [new Obstacle(width + 40)];
bgOffset = 0;
}
// 像素袋鼠类
class Kangaroo {
constructor(x, y) {
this.x = x;
this.y = y;
this.vy = 0;
this.size = 32;
this.onGround = true;
}
update() {
this.vy += 1.2; // 重力
this.y += this.vy;
if (this.y >= groundY - this.size) {
this.y = groundY - this.size;
this.vy = 0;
this.onGround = true;
} else {
this.onGround = false;
}
}
jump() {
if (this.onGround) {
this.vy = -16;
}
}
show() {
push();
translate(this.x, this.y);
noSmooth();
scale(2);
// 袋鼠身体
fill(180, 120, 60);
rect(4, 8, 6, 8); // 身体
rect(6, 4, 4, 4); // 头
fill(120, 80, 40);
rect(10, 6, 2, 2); // 耳朵
rect(6, 6, 2, 2); // 耳朵
fill(180, 120, 60);
rect(2, 14, 4, 4); // 腿
rect(10, 14, 2, 4); // 腿
fill(200, 160, 90);
rect(8, 12, 2, 2); // 肚子
fill(180, 120, 60);
rect(0, 10, 4, 2); // 尾巴
pop();
}
}
// 障碍物类
class Obstacle {
constructor(x) {
this.x = x;
this.y = groundY - 20;
this.w = random([16, 20, 24]);
this.h = random([20, 24, 28]);
this.type = random([0, 1]); // 0: 石头, 1: 仙人掌
}
update() {
this.x -= 6;
}
show() {
push();
noSmooth();
if (this.type == 0) {
// 石头
fill(100, 100, 100);
rect(this.x, this.y + this.h - 12, this.w, 12, 3);
} else {
// 仙人掌
fill(60, 180, 80);
rect(this.x, this.y, this.w, this.h, 3);
fill(80, 220, 100);
rect(this.x + this.w/3, this.y + this.h/2, this.w/4, this.h/2, 2);
}
pop();
}
hits(k) {
return (k.x + k.size > this.x && k.x < this.x + this.w && k.y + k.size > this.y);
}
offscreen() {
return this.x + this.w < 0;
}
}
// 像素背景
function drawBackground() {
push();
noSmooth();
// 云
for (let i = 0; i < 3; i++) {
let cx = (i * 200 + bgOffset * 0.5) % width;
fill(255, 255, 255, 200);
rect(cx, 40, 32, 8, 4);
rect(cx + 10, 36, 16, 8, 4);
}
// 树
for (let i = 0; i < 4; i++) {
let tx = (i * 160 + bgOffset * 0.8) % width;
fill(100, 60, 30);
rect(tx, groundY - 32, 6, 32);
fill(60, 180, 80);
rect(tx - 8, groundY - 44, 22, 16, 6);
}
pop();
}
可以直接在这个平台上运行使用:https://editor.p5js.org/
射击游戏代码:
由 windsurf 的 GPT4.1生成
// p5.js 炫酷射击游戏
// 作者:Cascade AI
// 玩法说明:
// - 鼠标左右移动飞船
// - 鼠标点击或按空格发射子弹
// - 击中敌人得分,漏掉敌人扣血
// - 血量为0游戏结束
let player;
let bullets = [];
let enemies = [];
let particles = [];
let score = 0;
let health = 5;
let gameState = 'start'; // 'start', 'playing', 'gameover'
let enemySpawnTimer = 0;
let bgStars = [];
function setup() {
createCanvas(600, 800);
player = new Player();
for (let i = 0; i < 80; i++) {
bgStars.push({
x: random(width),
y: random(height),
speed: random(0.5, 2),
size: random(1, 3)
});
}
}
function draw() {
background(10, 20, 40);
drawBgStars();
if (gameState === 'start') {
drawTitleScreen();
} else if (gameState === 'playing') {
runGame();
} else if (gameState === 'gameover') {
drawGameOver();
}
}
function drawBgStars() {
noStroke();
fill(255, 255, 255, 180);
for (let s of bgStars) {
ellipse(s.x, s.y, s.size);
s.y += s.speed;
if (s.y > height) {
s.y = 0;
s.x = random(width);
}
}
}
function drawTitleScreen() {
fill(255);
textAlign(CENTER, CENTER);
textSize(48);
text('炫酷射击游戏', width/2, height/2 - 100);
textSize(24);
text('玩法说明:', width/2, height/2 - 30);
textSize(20);
text('1. 鼠标左右移动飞船', width/2, height/2);
text('2. 鼠标点击或空格发射子弹', width/2, height/2 + 30);
text('3. 击中敌人得分,漏掉敌人扣血', width/2, height/2 + 60);
text('4. 血量为0游戏结束', width/2, height/2 + 90);
textSize(24);
fill(0, 255, 180);
text('点击鼠标或按空格开始', width/2, height/2 + 160);
}
function runGame() {
// 玩家
player.update();
player.show();
// 子弹
for (let b of bullets) b.update();
for (let b of bullets) b.show();
bullets = bullets.filter(b => !b.offscreen && !b.hit);
// 敌人
for (let e of enemies) e.update();
for (let e of enemies) e.show();
enemies = enemies.filter(e => !e.offscreen && !e.hit);
// 粒子
for (let p of particles) p.update();
for (let p of particles) p.show();
particles = particles.filter(p => !p.finished());
// 碰撞检测
for (let b of bullets) {
for (let e of enemies) {
if (!e.hit && !b.hit && dist(b.x, b.y, e.x, e.y) < e.size/2 + b.size/2) {
e.hit = true;
b.hit = true;
score++;
for (let i = 0; i < 25; i++) {
particles.push(new Particle(e.x, e.y, e.col));
}
}
}
}
for (let e of enemies) {
if (!e.hit && e.y > height - 50) {
e.hit = true;
health--;
for (let i = 0; i < 15; i++) {
particles.push(new Particle(e.x, height-50, color(255,0,0)));
}
if (health <= 0) {
gameState = 'gameover';
}
}
}
// 敌人生成
enemySpawnTimer--;
if (enemySpawnTimer <= 0) {
enemies.push(new Enemy());
enemySpawnTimer = int(random(25, 50));
}
// UI
fill(255);
textSize(22);
textAlign(LEFT, TOP);
text('分数: ' + score, 20, 20);
text('血量: ' + health, 20, 50);
}
function drawGameOver() {
fill(255, 60, 60);
textAlign(CENTER, CENTER);
textSize(48);
text('游戏结束', width/2, height/2 - 60);
textSize(30);
fill(255);
text('你的分数: ' + score, width/2, height/2);
textSize(22);
fill(0, 255, 180);
text('点击鼠标或按空格重新开始', width/2, height/2 + 80);
}
function mousePressed() {
if (gameState === 'start' || gameState === 'gameover') {
restartGame();
} else if (gameState === 'playing') {
player.shoot();
}
}
function keyPressed() {
if (gameState === 'start' || gameState === 'gameover') {
if (key === ' ' || key === 'Spacebar') restartGame();
} else if (gameState === 'playing') {
if (key === ' ' || key === 'Spacebar') player.shoot();
}
}
function restartGame() {
score = 0;
health = 5;
bullets = [];
enemies = [];
particles = [];
gameState = 'playing';
}
// 玩家类
class Player {
constructor() {
this.x = width/2;
this.y = height - 50;
this.size = 60;
this.cooldown = 0;
}
update() {
this.x = constrain(mouseX, this.size/2, width-this.size/2);
if (this.cooldown > 0) this.cooldown--;
}
show() {
push();
translate(this.x, this.y);
noStroke();
fill(0, 200, 255);
ellipse(0, 0, this.size, this.size/2);
fill(255, 255, 255, 200);
ellipse(0, 0, this.size*0.5, this.size*0.18);
pop();
}
shoot() {
if (this.cooldown <= 0) {
bullets.push(new Bullet(this.x, this.y - this.size/2));
this.cooldown = 10;
}
}
}
// 子弹类
class Bullet {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = 12;
this.speed = 12;
this.offscreen = false;
this.hit = false;
}
update() {
this.y -= this.speed;
if (this.y < -this.size) this.offscreen = true;
}
show() {
if (!this.hit) {
noStroke();
fill(255, 255, 0);
ellipse(this.x, this.y, this.size, this.size*1.5);
fill(255, 255, 255, 120);
ellipse(this.x, this.y, this.size*0.4, this.size*0.8);
}
}
}
// 敌人类
class Enemy {
constructor() {
this.size = random(32, 48);
this.x = random(this.size/2, width-this.size/2);
this.y = -this.size/2;
this.speed = random(2, 4) + score/20;
this.hit = false;
this.offscreen = false;
this.col = color(random(120,255), random(60,180), random(60,255));
}
update() {
this.y += this.speed;
if (this.y > height + this.size) this.offscreen = true;
}
show() {
if (!this.hit) {
push();
translate(this.x, this.y);
noStroke();
fill(this.col);
ellipse(0, 0, this.size, this.size);
fill(255, 255, 255, 60);
ellipse(0, 0, this.size*0.5, this.size*0.5);
pop();
}
}
}
// 粒子爆炸
class Particle {
constructor(x, y, col) {
this.x = x;
this.y = y;
this.vx = random(-3, 3);
this.vy = random(-3, 3);
this.alpha = 255;
this.col = col;
}
update() {
this.x += this.vx;
this.y += this.vy;
this.vy += 0.08;
this.alpha -= 7;
}
show() {
noStroke();
fill(red(this.col), green(this.col), blue(this.col), this.alpha);
ellipse(this.x, this.y, 8, 8);
}
finished() {
return this.alpha < 20;
}
}