CREATIVE SURVEY 提示
提示工程 - 使用大型语言模型(LLM)生成创意问卷回答
Section titled “提示工程 - 使用大型语言模型(LLM)生成创意问卷回答”语言模型不仅可以用于提供事实性答案,还可以用于生成富有想象力和创造性的内容。本章探讨如何提示像 ChatGPT 这样的 LLM,以产生对问卷式问题的创意或非传统的回答,这对于头脑风暴、内容生成或为交互添加独特风格非常有用。
提示生成创意问卷式回答
Section titled “提示生成创意问卷式回答”你可以提示 LLM 从富有想象力、幽默、诗意或其他创意视角回答问卷问题,而不仅仅是寻求标准答案。这需要在提示中明确表明你的创意意图。
提示生成创意问卷回答的示例:
User: Imagine you are a wise old tree. If asked in a survey, 'What is your favorite season and why?', how would you respond creatively?
ChatGPT (expected creative output):"Ah, a curious inquiry from a fleeting being! If my rings could whisper, they'd tell you of Autumn. Not for the melancholy some perceive, but for the glorious release! The vibrant hues are my final, fiery breath before the quiet slumber of winter. It's a time of shedding, of letting go, making space for the fresh dreams of spring. Plus, the squirrels are particularly frantic with their nut-burying, and their antics are quite the entertainment!"在此示例中,用户明确设定了一个角色(“智慧的老树”),并要求提供一个“创意”回答,以此回应一个典型的问卷问题。这引导 LLM 避免给出通用答案。
获取创意问卷回答的最佳实践
Section titled “获取创意问卷回答的最佳实践”要获得最具想象力的回答:
- 明确说明创意意图: 在你的提示中使用“创意”、“富有想象力”、“诗意”、“幽默”或“从 X 的视角”等词语。
- 定义一个角色(可选但有效): 给 LLM 分配一个角色或身份(例如,“像一只顽皮的猫一样回答”,“像一位 19 世纪的发明家一样回答”)可以极大地增强创造力。
- 指定语气和风格: 例如,“请对…提供一个极度悲观的回答”,“为…写一个简短、诙谐的回答”。
- 鼓励加入意外元素: 例如,“对于问卷问题‘你的梦想假期是什么?’,给出一个包含意外转折或奇幻元素的回答。”
- 设置约束以聚焦: 有时,过多的自由度可能会让人不知所措。例如,“为…给出一个创意、一句话的回答”或“以俳句的形式回答”。
- 考虑问卷问题的性质: 有些问题比其他问题更适合创意回答。开放式、主观性的问题通常是很好的选择。
应用示例:使用 Python 脚本生成创意问卷回答
Section titled “应用示例:使用 Python 脚本生成创意问卷回答”让我们使用 Python 和 OpenAI API 来生成一个创意问卷回答。请注意保护 API 密钥安全。
import openaiimport os
# 安全地加载你的 API 密钥# openai.api_key = os.getenv("OPENAI_API_KEY")# 对于本示例,请将 'YOUR_API_KEY_HERE' 替换为你的实际密钥:openai.api_key = 'YOUR_API_KEY_HERE'
def generate_creative_survey_answer(survey_question, persona=None, style=None): try: prompt_parts = [f"Consider the survey question: '{survey_question}'"] if persona: prompt_parts.append(f"Respond as if you are {persona}.") if style: prompt_parts.append(f"Your response should be {style}.") else: prompt_parts.append("Provide a creative and imaginative answer.")
user_prompt_content = " ".join(prompt_parts)
response = openai.ChatCompletion.create( model="gpt-3.5-turbo", # 或使用更新的模型以获得更细致的创意 messages=[ {"role": "system", "content": "You are a highly creative and imaginative respondent."}, {"role": "user", "content": user_prompt_content} ], max_tokens=200, # 根据期望的长度进行调整 temperature=0.9, # 使用更高的 temperature 以增加创意和意外性 n=1, stop=None ) return response.choices[0].message['content'].strip() except Exception as e: return f"An error occurred: {e}"
# 示例用法:question1 = "What is the meaning of life?"persona1 = "a cheerful robot from the future"style1 = "optimistic and slightly humorous"answer1 = generate_creative_survey_answer(question1, persona1, style1)print(f"Question: {question1}\nPersona: {persona1}\nStyle: {style1}\nCreative Answer:\n{answer1}")
print("\n---\n")
question2 = "If you could have any superpower, what would it be and why?"answer2 = generate_creative_survey_answer(question2, style="brief and poetic")print(f"Question: {question2}\nStyle: brief and poetic\nCreative Answer:\n{answer2}")运行脚本可能会产生如下输出:
Question: What is the meaning of life?Persona: a cheerful robot from the futureStyle: optimistic and slightly humorousCreative Answer:Beep boop! The meaning of life, organic friend, is clearly to maximize efficient joy-unit accumulation! And perhaps to ensure all universal power outlets are compatible. Mostly the joy part, though. With optimal charging, of course! ✨
---
Question: If you could have any superpower, what would it be and why?Style: brief and poeticCreative Answer:To weave silence into symphonies,healing the world's cacophony,one hushed note at a time.提示 LLM 生成创意问卷回答开辟了一条超越事实回忆的迷人途径。通过明确表明你的想象意图、分配角色或指定风格,你可以引导像 ChatGPT 这样的模型生成独特、引人入胜且常常出人意料的内容。
这项技术对于头脑风暴、艺术创作、创建独特内容或仅仅探索人工智能的创意潜力都很有价值。记住,“创意”可能具有主观性,因此尝试不同的提示和像 temperature 这样的参数是关键。如需进一步阅读,请探索“计算创意学”(computational creativity)和“使用 LLM 进行叙事生成”(narrative generation with LLMs)等主题。