加速人工智能模型的工程化

enter image description here 2025 年的即时工程已发生重大变化,每个 AI 模型(OpenAI 的 ChatGPT、DeepSeek、Google Gemini 和 GitHub Copilot)都有各自的优势和劣势。要在这些模型中培养即时工程方面的专业知识,必须了解它们的底层架构、功能和理想的即时工程技术。

🔹 2025 年快速工程的背景 提示工程现在是 AI 工程师、全栈开发人员和软件测试人员的一项关键技能。目标是制作精确、结构化的提示,以最大限度地提高 AI 模型的性能。该技能广泛应用于:

✅ AI 驱动的开发(代码生成、调试、重构)

✅测试自动化(测试用例生成、测试数据创建)

✅生产力工具(摘要、文档处理、领域特定知识检索)

✅聊天机器人和虚拟助手(用户交互、个性化、动态响应生成)

由于训练数据、微调和 API 行为的差异,每个 AI 模型对提示的响应都不同。

针对不同 AI 模型的快速工程 1️⃣ OpenAI(ChatGPT 4 和 5、GPT-4-turbo) 🛠最佳用例:

自然语言理解与生成 代码解释与调试 测试用例生成 聊天机器人和虚拟助手 📝 提示技巧:

✅思路链 (CoT) 提示→ 通过分解步骤来改进推理。✅小样本学习→ 在查询之前提供示例来指导模型。✅基于角色的提示 →为 AI 分配角色(例如,“您是高级 SDET...”)。

✅ 系统指令→ 在 API 调用中使用“系统”消息来一致地定义行为。✅ 温度和 Top-p 控制→ 针对不同用例调整创造力和随机性。

📌示例:

“您是专门从事自动化的软件测试专家。根据以下要求,生成包含先决条件、步骤和预期结果的详细测试用例。”

测试生成 💡用例:根据产品规范生成测试用例。

🔹提示:

You are an expert software tester specializing in automation.  
Given the following feature specification, generate detailed test cases, including:  
- Title  
- Preconditions  
- Steps  
- Expected Results  

### Feature Specification:  
A user should be able to reset their password by entering their registered 

预期输出

Test Case 1: Verify password reset link is sent to the registered email  

Preconditions:
- User has a registered account.
- User is on the login page.

Steps:
1. Click on "Forgot Password".
2. Enter the registered email address.
3. Click "Submit".

Expected Results:
- The system displays a success message.
- The registered email receives a password reset link.
- The link expires after 15 minutes.

ChatGPT 非常适合测试用例和文档等结构化输出。

🔹应用的最佳实践:

✔涵盖边缘案例(过期、重试、暴力攻击)

✔考虑的安全风险(暴力攻击和重放攻击)

✔测试用例文档的结构化格式

2️⃣DeepSeek(DeepSeek-VL 和 DeepSeek Coder) 🛠最佳用例:

多模式人工智能(文本+图像处理) 代码生成和重构 数学问题解决 📝 提示技巧:

✅零样本提示→ 即使没有示例也能很好地工作。✅代码优先方法→ 以鼓励直接编码的方式构造提示。✅任务细分 →要求

DeepSeek将复杂任务分解为子任务。

📌示例:

“在 NestJS 中为从 MongoDB 检索用户数据的服务生成单元测试。使用 Jest 并确保涵盖边缘情况。”

代码生成 💡用例:为 MongoDB 服务生成 NestJS 单元测试。

🔹提示:

You are a senior backend developer. Generate a unit test in NestJS using Jest for a service that retrieves user data from MongoDB.  
Ensure the test covers:  
- Valid user retrieval  
- Non-existent user handling  
- Error scenarios  

🔹预期输出(DeepSeek Coder):

import { Test, TestingModule } from '@nestjs/testing';
import { UserService } from './user.service';
import { getModelToken } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User } from './user.schema';

describe('UserService', () => {
  let service: UserService;
  let model: Model<User>;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        UserService,
        {
          provide: getModelToken('User'),
          useValue: {
            findOne: jest.fn(),
          },
        },
      ],
    }).compile();

    service = module.get<UserService>(UserService);
    model = module.get<Model<User>>(getModelToken('User'));
  });

  it('should return a user when found', async () => {
    const mockUser = { email: 'test@example.com', name: 'Test User' };
    jest.spyOn(model, 'findOne').mockResolvedValue(mockUser);

    const result = await service.getUserByEmail('test@example.com');
    expect(result).toEqual(mockUser);
  });

  it('should return null when user is not found', async () => {
    jest.spyOn(model, 'findOne').mockResolvedValue(null);

    const result = await service.getUserByEmail('notfound@example.com');
    expect(result).toBeNull();
  });
});

➡DeepSeek Coder 在真实测试场景的结构化代码生成中表现良好。

3️⃣Google Gemini 1.5(以前称为 Bard) 🛠最佳用例:

数据分析与可视化 多模式搜索(图像+文本) 创意写作与研究 📝 提示技巧:

✅混合提示→ 将结构化指令与开放式提示混合。✅ 事实核查提示→ 要求其使用来源验证其响应。✅上下文扩展提示

→ 使用较长 的提示和详细的上下文来提高准确性。

📌示例:

“总结 AI 驱动的测试用例生成的最新趋势,重点介绍使用 RAG 和 LLM 微调的工具。针对此任务提供 Gemini 和 GPT 的比较。”

人工智能研究与总结

💡用例:总结最新的 AI 驱动的测试用例生成趋势。

🔹提示:

Summarize the latest trends in AI-driven test case generation, focusing on:  
1. RAG (Retrieval-Augmented Generation)  
2. LLM fine-tuning for software testing  
3. Differences between OpenAI’s GPT-4-Turbo and Gemini for test generation  
Provide references where possible.  

🔹预期输出(Gemini 1.5):

AI-Driven Test Case Generation

Trends (2025)  

1️⃣ **Retrieval-Augmented Generation (RAG)**  
- AI models now retrieve domain-specific test cases from vector databases (e.g., MongoDB Vector Search).  
- RAG reduces hallucinations and improves context-aware test cases.  

2️⃣ **LLM Fine-Tuning for Software Testing**  
- Companies fine-tune models using their historical test cases.  
- Open-source fine-tuning frameworks like LoRA and QLoRA make it efficient.  

3️⃣ **GPT-4-Turbo vs. Gemini**  
- GPT-4-Turbo performs better in structured outputs.  
- Gemini 1.5 has stronger multimodal understanding (text + images).  

➡ Gemini 非常适合总结和 AI 研究驱动的任务。

4️⃣ GitHub Copilot(用于代码的 GPT-4-Turbo) 🛠最佳用例:

实时代码完成 代码优化和最佳实践 结对编程协助 📝 提示技巧:

✅内联注释提示→ 使用结构化注释引导代码完成。✅

函数签名完成→ 开始编写函数定义并让 Copilot 推断逻辑。✅迭代提示→ 通过与模型交互来细化建议

📌示例: // Create a NestJS controller that handles CRUD operations for users // Use dependency injection for the service 代码完成 💡用例:使用 Copilot 实时生成 NestJS CRUD API。

🔹提示(VS Code 中的内联注释):

// Create a NestJS service that handles CRUD operations for a "Product" entity
// Use dependency injection for MongoDB

🔹副驾驶完成(预期输出):

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Product, ProductDocument } from './product.schema';
@Injectable()
export class ProductService {
  constructor(@InjectModel(Product.name) private productModel: Model<ProductDocument>) {}

  async create(productDto: any): Promise<Product> {
    const newProduct = new this.productModel(productDto);
    return newProduct.save();
  }

  async findAll(): Promise<Product[]> {
    return this.productModel.find().exec();
  }

  async findOne(id: string): Promise<Product | null> {
    return this.productModel.findById(id).exec();
  }

  async update(id: string, productDto: any): Promise<Product | null> {
    return this.productModel.findByIdAndUpdate(id, productDto, { new: true }).exec();
  }

  async delete(id: string): Promise<void> {
    await this.productModel.findByIdAndDelete(id).exec();
  }
}

➡ Copilot 擅长按照开发人员的意图完成实际的生产代码。

🔹 2025 年的关键要点 ✅模型选择很重要→ 根据用例选择正确的 AI。✅ 提示结构至关重要

→正确格式化提示以实现最高效率。✅迭代方法是最好的 →根据输出不断优化提示。✅特定领域的微调→ 为测试、开发或特定于产品的工作流程自定义提示。

原文

评论