Prompt Engineering 简明教程
Prompt Engineering - ACT LIKE Prompt
近年来,类似 ChatGPT 的 NLP 模型因其生成类似人类反应的能力而备受关注。有效利用这些模型的一个重要方面是理解和利用提示。
In the recent years, NLP models like ChatGPT have gained significant attention for their ability to generate human-like responses. One important aspect of leveraging these models effectively is understanding and utilizing prompts.
在各种提示样式中,“扮演”提示已成为指导模型行为的一项有力技术。本文探讨了 ACT LIKE 提示的概念,提供了示例,并突出了它们在不同场景中的应用。
Among the various prompt styles, the "ACT LIKE" prompt has emerged as a powerful technique to guide the model’s behavior. This article explores the concept of ACT LIKE prompts, provides examples, and highlights their applications in different scenarios.
Understanding ACT LIKE Prompts
-
Definition − An ACT LIKE prompt instructs the model to generate responses as if it were a specific character, person, or entity.
-
Role-Playing − ACT LIKE prompts enable users to interact with the model in a more immersive and engaging way by assuming different personas.
-
Influencing Responses − By specifying a character or persona, users can direct the model’s behavior, language style, tone, and knowledge base to align with the chosen identity.
Examples of ACT LIKE Prompts
Acting as a Historical Figure
Acting as a Historical Figure
-
Prompt − "ACT LIKE Albert Einstein and explain the theory of relativity."
-
Response − The model generates a response as if it were Albert Einstein, providing an explanation of the theory of relativity in his style.
Impersonating a Fictional Character
Impersonating a Fictional Character
-
Prompt − "ACT LIKE Sherlock Holmes and solve this mystery."
-
Response − The model adopts the persona of Sherlock Holmes and crafts a response showcasing deductive reasoning and detective skills.
Simulating an Expert
Simulating an Expert
-
Prompt − "ACT LIKE a NASA scientist and explain the process of space exploration."
-
Response − The model takes on the role of a NASA scientist, offering insights and technical knowledge about space exploration.
Applications of ACT LIKE Prompts
-
Storytelling and Writing − Writers can employ ACT LIKE prompts to generate dialogue or scenes in the voice of specific characters, adding depth and authenticity to their stories.
-
Learning and Education − Students can utilize ACT LIKE prompts to interact with the model as renowned historical figures, enhancing their understanding of different subjects through immersive conversations.
-
Entertainment and Games − ACT LIKE prompts can be employed in chat-based games or virtual assistants to provide interactive experiences, where users can engage with virtual characters.
Example
请看以下示例:
Take a look at the following example −
import openai
# Set up your OpenAI API credentials
openai.api_key = 'Your OpenAI Key'
# Define the ACT LIKE prompt
prompt = """
ACT LIKE Sherlock Holmes and solve the following mystery:
You are called to investigate a crime scene where a valuable diamond necklace
has been stolen from a locked room. The room has no windows, and the only
entrance is a solid wooden door. The door was locked from the inside, and
there are no signs of forced entry. The owner of the necklace claims that nobody
else had access to the room. How did the thief manage to steal the necklace?
"""
# Generate a response from the model
response = openai.Completion.create(
engine='text-davinci-003',
prompt=prompt,
max_tokens=100,
n=1,
stop=None,
temperature=0.7
)
# Print the model's response
print(response.choices[0].text.strip())
对于本文中的图像,我们做了如下的处理 -
In this case, we got the following response −
The most likely explanation is that the thief used a lock-picking device to gain entry to the room. Lock-picking devices are small tools that can be used to open locks without leaving any signs of forced entry. Therefore, it is likely that the thief used a lock-picking device to gain access to the room and then took the necklace.
注意在你的系统上,当你使用你的 OpenAI 密钥使用相同代码时,你的系统可能会产生不同的响应。
Note that the system may produce a different response on your system, when you use the same code with your OpenAI key.
Conclusion
ACT LIKE 提示可以作为与 ChatGPT 模型互动的强大工具,它允许用户扮演不同的角色、人物或专业知识。通过利用这种提示风格,个人可以创造生动而引人入胜的对话,增强讲故事能力,培养学习体验,创造互动娱乐。
ACT LIKE prompts serve as a powerful tool for engaging with ChatGPT models, allowing users to assume different roles, characters, or expertise. By leveraging this prompt style, individuals can create rich and immersive conversations, enhance storytelling, foster learning experiences, and create interactive entertainment.
了解 ACT LIKE 提示的潜力为探索自然语言处理模型的功能、让互动变得更有动感和吸引力开辟了广泛的可能性。
Understanding the potential of ACT LIKE prompts opens up a wide range of possibilities for exploring the capabilities of natural language processing models and making interactions more dynamic and engaging.