Stylized content

This notebook provides a quick example of how to use EDSL to prompt an AI agent to immitate a writing style in drafting some content.

EDSL is an open-source library for simulating surveys and experiements with language models. Please see our documentation page for tips and tutorials on getting started. ThanksLori Berenberg for inspiring this demo!

Constructing a question

EDSL comes with a variety of question types that we can choose from based on the form of the response that we want to get back from the model (multiple choice, free text, linear scale, etc.). Here we use QuestionFreeText to create a question prompt to return a textual response. We compose the question with a writing sample, and then use Scenario objects to run the question for any different topics that we want the agent to write about. This allows us to run all the versions of the question at once:

[1]:
from edsl import QuestionFreeText, ScenarioList, Scenario

my_example = """Arrr, matey, let me tell ye about bein' 45! 'Tis a grand age, like a fine rum
that's been aged to perfection in the hold of an ol' ship. Ye've sailed through the squalls
and storms of life, and now ye're ridin' the calm seas with the wind at yer back. Yer beard
may be a bit grayer, and yer joints creak like an old wooden deck, but ye've got the wisdom
of the seven seas and the tales to prove it! Ye've charted yer course, found yer treasure,
and now ye're ready for new horizons and uncharted waters. So hoist the sails and set a course
for adventure, because at 45, the horizon is as bright as a golden sunset over the open ocean.
There's a whole world out there still to explore, filled with new treasures and mysteries
awaitin' a bold soul like yerself. Aye, it's a fine time to be alive, with the world at yer
feet, a hearty 'yo ho ho' in yer heart, and a spirit ready for new explorations!
"""

q = QuestionFreeText(
    question_name="my_style",
    question_text="Here's an example of my writing style: "
    + my_example
    + "Draft a paragraph about {{ topic }} in my style.",
)

topics = ScenarioList(
    Scenario({"topic": t}) for t in ["parrots", "holiday weekends", "fun with language models"]
)

Generating content

We simulate responses by adding the scenarios to the question and running it. This generates a Results object that we can readily analyze (learn more about built-in methods for analyzing results):

[2]:
results = q.by(topics).run()

Here we select the topics and responses and print them in a table:

[3]:
results.select("topic", "my_style").print(format="rich")
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ scenario                  answer                                                                               ┃
┃ .topic                    .my_style                                                                            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ parrots                   Arrr, matey, let me spin ye a yarn about them fine feathered friends, the parrots!   │
│                           Aye, these colorful squawkers be the true companions of any sea-farin' pirate worth  │
│                           his salt. With feathers as vibrant as a sunset over the Caribbean, they perch upon   │
│                           yer shoulder, whisperin' secrets of the sea in yer ear. These clever birds can mimic │
│                           the very voice of the wind, and their squawks be a familiar sound aboard any pirate  │
│                           ship. Aye, a parrot's loyalty is as steadfast as the North Star, guidin' ye through  │
│                           the darkest nights and fiercest gales. They be more than just pets; they're trusted  │
│                           mates who share in the spoils and the stories. So raise a tankard to these avian     │
│                           adventurers, for they bring color, cheer, and a touch of magic to the pirate's life! │
│                           Arrr, there's no better companion on the high seas than a trusty parrot by yer side! │
├──────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
│ fun with language models  Arrr, matey, let me spin ye a yarn about the jolly good fun ye can have with these   │
│                           here language models! 'Tis like havin' a trusty parrot on yer shoulder, always ready │
│                           with a clever quip or a bit of sage advice. These marvels of modern sorcery can spin │
│                           a tale as grand as the seven seas, fillin' yer sails with words as swift as the      │
│                           trade winds. Whether ye be chartin' a course for a new adventure or just lookin' to  │
│                           pass the time in the captain's quarters, these models be yer loyal crew, always      │
│                           ready to lend a hand. They'll help ye craft messages fit for a king or a pirate,     │
│                           with a treasure trove of knowledge and wit at their disposal. So hoist the Jolly     │
│                           Roger and set sail on a voyage of linguistic discovery, for with these language      │
│                           models at yer side, the world of words is yer oyster, and every sentence be a pearl! │
│                           Aye, there's no end to the mirth and merriment ye can have, with a hearty 'yo ho ho' │
│                           and a keyboard at yer fingertips!                                                    │
├──────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────┤
│ holiday weekends          Arrr, matey, let me spin ye a yarn about holiday weekends! These be the times when a │
│                           pirate's soul truly comes alive, like a ship breakin' free from the doldrums.        │
│                           Picture this: ye've been laborin' hard, swabbin' the decks and battlin' the daily    │
│                           grind, but now, the horizon be callin' with promises of leisure and merriment. A     │
│                           holiday weekend is like findin' a hidden cove filled with gold doubloons and rare    │
│                           spices. Ye can cast off the lines, let the wind fill yer sails, and set a course for │
│                           relaxation and revelry. Whether ye be loungin' in a hammock with a tankard of grog   │
│                           or explorin' new shores with yer trusted crew, these days be a treasure trove of joy │
│                           and freedom. The sun be shinin', the sea be calm, and the laughter of friends and    │
│                           family be the finest music to a pirate's ears. So raise yer flagon, me hearties, and │
│                           toast to the grand adventures that await on these blessed holiday weekends! Aye,     │
│                           there's no finer time to be a pirate, with the world at yer feet and the promise of  │
│                           new escapades just beyond the horizon.                                               │
└──────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────┘

Check out our documentation page for many other demo notebooks and tutorials!