Maximizing Reusability with Prompt Functions
A Prompt Function
is a way to implement functions within a prompt to perform specific tasks, thereby maximizing reusability.
For instance, if you need to send an email with the same content to multiple people, just changing the name, you can efficiently draft the email using a prompt function as shown below.
### Instructions
Below is a prompt function for drafting an email template to send to customers.
Please use the function to draft an email. You don't need to show the actual function code.
### Prompt Function
- Function Name: draftEmail
- Inputs: Recipient's Name, Expected Delivery Date
- Output:
Hello [Recipient's Name],
We at Code Friends Mall are committed to providing a joyful shopping experience.
The shampoo you ordered is scheduled to be delivered on [Expected Delivery Date].
If there are any delays or issues with delivery, please contact us at the number below.
Customer Service: 123-456-7890
### Email Draft
draftEmail("John Doe", "October 1")
draftEmail("Jane Smith", "October 3")
draftEmail("Chris Johnson", "October 2")
### Note
Separate each email draft with `---`.
The above prompt function defines a draftEmail
function that takes [Recipient's Name] and [Expected Delivery Date] as inputs, and uses it to draft an email.
Subsequently, if you input draftEmail("John Doe", "October 1")
with the recipient's name and expected delivery date, the prompt function will output the email draft based on that information.
Using this kind of functional prompting approach allows for efficient execution of repetitive tasks.
Practice
Send a prompt example and compare the AI's responses.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.