-
Notifications
You must be signed in to change notification settings - Fork 14
Prompt Engineering Examples
Appending a context argument to a query to design it for some purpose
In this example, one way the user might consider extending GPTAI might be by adding a modified function to their config which prompts them for a string(or one that they just pass to it). Then it creates an enhanced prompt from a template you could design for your purposes. This specific example uses this idea to generate a storyboard from input text:
(defun storyboard (story-str)
"Storyboard the input string using a GPT model.
Argument STORY-STR input prompt with story description, characters, etc."
(interactive
;; prepare context string
(list (read-string "Story Description: ")))
;; if run interactively
(setq storyboard-string "Storyboard the following:")
;; combine input with context string
(setq prep-story-str (concat storyboard-string story-str))
;; send the query
(gptai-send-query prep-story-str))an example of using this and it’s output:
(storyboard "a cat meets cthulhu when the tardis saves him out of nowhere.")Act 1:
The cat is walking through a dark forest, seemingly lost and alone. Suddenly, a mysterious blue box resembling a police call box materializes in front of the cat.
Act 2:
The cat cautiously approaches the box and peers inside. To its surprise, a tall, tentacled creature with an alien face emerges from the box. The creature is Cthulhu.
Act 3:
The cat is terrified and runs away, but is quickly scooped up by Cthulhu. The cat struggles to escape, but Cthulhu’s grip is too strong.
Act 4:
Suddenly, the box emits a loud whirring sound. The cat looks around in confusion as the box begins to glow brighter and brighter.
Act 5:
The box opens and a bright light fills the area. The cat is surrounded by the blue box and is now safe in the care of the Doctor and the TARDIS. Cthulhu is nowhere to be seen.
Act 6:
The cat looks around, relieved and happy to be safe. The Doctor and the TARDIS have saved the cat from Cthulhu’s grasp.
Appending multiple contextual arguments to an input query string to specially design it for a purpose.
In this example, I’m building on the same idea by adding more descriptive text to the input prompts. This allows for even greater customization and flexibility in creating prompts. You can use this approach as a template for implementing your own customized prompts in your own configuration’s:
(defun advanced-storyboard (story-str context-str &optional characters locations
tone)
"Storyboard the input string using a GPT model, add additional context, etc.
Argument STORY-STR input prompt with story description, characters, etc.
Argument CONTEXT-STR additional context to the story.
Argument CHARACTERS characters in the story.
Argument LOCATIONS locations in the story.
Argument TONE overall tone of the story."
(interactive
;; prepare context strings
(list (read-string "Story Description: ")
(read-string "Additional Context: ")))
(setq storyboard-string "Storyboard the following: ")
(setq context-string "Additional Context: ")
(setq char-string "Characters: ")
(setq location-string "Locations: ")
(setq tone-string "Tone: ")
;; if interactively called
(if (called-interactively-p 'any)
;; then
((setq storxt-str (concat context-string context-str))
(setq prep-story-str (concat storyboard-string story-str storxt-str))
(gptai-send-query prep-story-str))
;; else
;; add optional args
(setq char-string (concat char-string characters))
(setq location-string (concat location-string locations))
(setq tone-string (concat tone-string tone))
(setq storxt-str (concat context-string context-str))
;; combine all strings
(setq prep-story-str (concat "Write the following storyboard, be detailed
and use story-teller
prose: "
storyboard-string
story-str
storxt-str
char-string
location-string
tone-string))
;; send query with gptai functionality
(gptai-send-query prep-story-str)))here is an example of how you might use this, and it’s output:
(advanced-storyboard "a battle between elder gods." ;; story concept
"the universe cracks." ;; additional context
"cthulhu and dagon." ;; characters
"deepspace." ;; location(s)
"epic." ;; overall tone
)The heavens tremble and shake in fear as the two elder gods, Cthulhu and Dagon, clash in the depths of space. The stars flicker and the galaxies bend and break around them as they battle with a ferocity rarely seen in the universe.
Cthulhu, the monstrous horror from beyond time and space, charges forward with an ancient and powerful rage, unleashing its eldritch powers and sending shockwaves through the cosmos. Dagon retaliates, his tentacles slashing through the vacuum of space as he attempts to overpower Cthulhu.
Their battle rages on, neither willing to yield. Lightning crackles and shockwaves ripple through the universe as they fight, the force of their clash reverberating through the cosmos. The stars dim and the galaxies quiver as the two elder gods battle for supremacy.
The two gods clash and fight, their power and rage rising until it seems that the universe itself will be torn apart by their battle. But in the end, it is Dagon who emerges victorious, his tentacles ensnaring and overpowering Cthulhu, sending him plummeting back into the depths of space.
The heavens slowly calm, the stars and galaxies returning to their normal state. But the universe will never forget the epic battle of the two elder gods, Cthulhu and Dagon.