prompt提示词 模板
时间: 2025-07-19 22:07:48 浏览: 4
### Prompt 提示词模板与示例
以下是几种常见的 `Prompt` 模板及其代码实现方式:
#### 1. 基本翻译任务的 Prompt 模板
对于简单的翻译任务,可以设计如下模板:
```python
template = """
You are a professional translator.
Translate the following text from {input_language} to {output_language}.
Text: "{text}"
"""
```
此模板可以通过 `.format()` 方法动态替换 `{input_language}` 和 `{output_language}` 的值[^1]。
---
#### 2. 复杂问答任务的 Prompt 模板
针对复杂问答场景,推荐采用结构化的输入输出格式。例如,在训练数据中常见的是键值对形式 `{Q: question, A: answer}`,因此可以在实际使用时保持一致以提高模型效果[^2]:
```python
template = """
Answer the following question in the format {{Q: question, A: answer}}.
Question: {question}
"""
```
---
#### 3. 文本分类任务的 Prompt 模板
用于文本分类的任务,可定义清晰的目标类别并引导模型完成预测:
```python
template = """
Classify the sentiment of the given sentence into one of these categories: Positive, Negative, or Neutral.
Sentence: "{sentence}"
Category:
"""
```
---
#### 4. 自动化用例检查的 Prompt 模板
在软件测试领域,自动化生成用例或验证其合理性是一个重要方向。以下是一则适用于此类任务的设计思路[^3]:
```python
template = """
Analyze the provided use case and identify any potential issues that could lead to missed tests during execution.
Use Case Description: "{use_case_description}"
Issues Found:
"""
```
---
#### 5. 创意写作辅助工具的 Prompt 模板
当希望利用大语言模型创作故事或其他文学作品时,提供背景设定有助于获得更高质量的结果:
```python
template = """
Write an engaging short story based on the context below:
Context: {context}
Story:
"""
```
以上展示了不同类型应用场景下的 `Prompt` 设计模式以及对应的 Python 实现片段。这些都可以作为起点进一步调整优化至满足特定需求为止。
阅读全文
相关推荐


















