这里面涵盖了AI提示词(Prompt Engineering)的核心逻辑、角色设计思维、以及在PHP接口调用(比如 OpenAI / 自建API)中的应用方式。
并结合外贸文章生成给大家一个完整的实战示例。希望对做外贸的PHPer有点帮助。
首先要弄明白PHP开发者对提示词的协同流程,如图
🧠 一、AI 的三种常见角色提示词(Role Prompt Types)
AI提示词设计中,通常分为三种角色层次(在系统中对应不同“权重”):
类型 | 位置 / 权重 | 说明 | 示例 |
---|---|---|---|
1️⃣ System Prompt(系统角色) | 最高层 | 定义AI的身份、目标、语气、行为准则 | “You are a professional B2B SEO content strategist…” |
2️⃣ User Prompt(用户输入) | 次高层 | 用户提出任务或问题 | “Write a 1500-word SEO article about industrial air compressors.” |
3️⃣ Assistant Prompt(助手思维) | 动态层 | 作为AI自我思考或中间指令(有时API不显式展示) | 例如:根据前文生成内容时的内在逻辑或上下文理解。 |
区别简明理解:
✅ System:定义“我是谁”
✅ User:定义“我要做什么”
✅ Assistant:定义“我怎么去做”
🧩 二、三种角色的作用差异(在效果上的区别)
项目 | System | User | Assistant |
---|---|---|---|
作用 | 决定AI整体风格与思维方式 | 明确任务内容与要求 | 影响具体执行方式 |
可被覆盖 | 不容易 | 可以 | 会变化 |
典型场景 | 人设、语气、领域知识 | 问题、需求、素材 | 输出结构、细节、策略 |
💬 三、在外贸文章生成中的实际示例
我们来看一个完整Prompt结构示例,用来生成外贸SEO文章(比如“industrial vacuum pump supplier”):
🔹 System(系统提示词)
You are a professional B2B SEO content strategist and technical copywriter specializing in industrial products.
Your writing style should be factual, persuasive, and optimized for global trade buyers.
🔹 User(用户提示词)
Write a 2000-word English article titled “Why Choose a Reliable Industrial Vacuum Pump Supplier”.
The article should include:
- TL;DR summary
- Product application scenarios
- Problem and solution sections
- Product advantages
- Market trend analysis
- Conclusion and FAQ
Format using <div> and inline CSS only.
🔹 Assistant(AI执行逻辑层)
(这层通常AI内部处理,不需要你手写,但可以通过指令强化)
例如添加:
Ensure each section has at least 120 words and include keyword “industrial vacuum pump supplier” 6 times naturally.
🧰 四、PHP 调用示例写法(调用三层角色)
以 OpenAI v1/chat/completions 接口为例:
<?php
$apiKey = "YOUR_API_KEY";
$data = [
"model" => "gpt-5",
"messages" => [
[
"role" => "system",
"content" => "You are a professional B2B SEO content strategist and technical copywriter specializing in industrial products."
],
[
"role" => "user",
"content" => "Write a 2000-word English article titled 'Why Choose a Reliable Industrial Vacuum Pump Supplier'.
Include TL;DR, application scenarios, problem-solution, product advantages, market trend, and FAQ sections.
Format using <div> and inline CSS only."
]
]
];
$ch = curl_init("https://api.openai.com/v1/chat/completions");
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer $apiKey"
],
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($data)
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
✅ 这个结构清晰地体现了三层角色(system、user、assistant),
你可以在 $data['messages']
数组里增加更多上下文以强化连续生成。
📏 五、提示词字数多好还是少好?
长度 | 优点 | 缺点 | 建议场景 |
---|---|---|---|
短提示词(<100字) | 响应快、成本低 | 内容泛化、风格不稳定 | 测试、内部草稿 |
中等长度提示词(100–300字) | 内容明确、可控 | 基本无明显缺点 | 推荐✅ |
长提示词(300–1000字) | 输出稳定、一致性高 | Token消耗多、响应慢 | 正式生成外贸SEO文案时使用 |
👉 结论: 对于外贸SEO类内容,提示词适中偏长最好(150–400字),
这样AI能充分理解“语气、结构、买家意图”。
🚀 六、总结:如何写出高效的外贸文章Prompt
最佳结构模板:
System: 定义身份(专业SEO文案/技术外贸专家)
User: 指定任务(主题、结构、格式、篇幅)
Assistant: 附加逻辑(关键词次数、风格、语气)
例如:
You are a professional SEO content strategist specializing in industrial products.
Write a detailed English HTML article for B2B buyers about “industrial vacuum pump supplier”.
The article should include a TL;DR summary, product application, problem-solution, benefits, and market trends.
Use friendly yet authoritative tone. Length ≥1500 words, keyword appears 6 times.
发表评论 取消回复