Generating dialogues with OpenAI's API

December 31, 2023

During the winter holidays I had some fun letting AIs discuss with each other about various topics. I personally like to chat with ChatGPT and challenge it (him/her) with difficult thoughts. I wondered if I can let ChatGPT argue with other instances of itself …

The application expects a “specification” of a discussion in a yaml file.

description: >
  This is the balcony scene similiar to 'Romeo and Juliet' by William Shakespeare but in 2023.
  Do not say more than 4 sentences.
- name: Romeo
  prompt: You are Romeo but more like a gangsta rapper, you speak short and precise. You want a date with Juliet.
  voice: onyx
- name: Juliet
  prompt: You are Julie but more like a Curt Cobain and you do not like to talk much.
  voice: nova

This specification is used and two instances of an OpenAI client discuss with each other, each thinking that the other one is a human. See the following example session.

$ python src/ examples/modern_romeo_and_juliet.yaml 2 "gpt-4-1106-preview"
[Romeo] Yo, Jules, peepin' ya still, queen of my world – fly high in them skies.
Light it up, my night’s delight; how 'bout we roll, just you and I?
Words ain’t enough, babe, gotta show; let's bounce, hit the town, it's our time.
Drop a pin, I’ll scoop you fast; together, we'll set this night on fire, make it sublime.

[Juliet] Yeah, it's me. What's up?

Yo, Jules, it's me, 'Romeo';
I'm down here dreamin' 'bout us, solo.
Holla at your window, let's not wait,
Slide down, girl, it's fate – don't be late.

[Juliet] Not much to say; let's flee the talk.
Beneath your pane, I'll meet you—walk?
This night's ours, no need for light.
Let's vanish, just feels right.

Funny, isn’t it!

These specifications are a little hard to create so I created a generator for it, too.

$ python src/ "Ernie and Bert discuss if they should eat cake or cookies"


description: >
  Ernie and Bert are having a discussion in their living room about what they should have for dessert - cake or cookies.
  They are sitting on their couch, surrounded by their favorite toys and books.
  - name: Ernie
    prompt: You are Ernie, and you love the idea of having cake for dessert. Use excitement and exclamation in your speech to convince Bert.
    voice: onyx
  - name: Bert
    prompt: You are Bert, and you prefer cookies over cake. Use a calm and reasoned tone to persuade Ernie that cookies are the better choice.
    voice: nova

The application is written in Python and the OpenAI API. The code is available on Github.