Conversing Comedians: A Hilarious Dialogue Between Language Models

Conversing Comedians: A Hilarious Dialogue Between Language Models

LLM Conversation Script

This is a simple Python script that allows two language models (LLMs) to have a conversation based on a seeded topic and saves the output to a text file. The script utilizes the OpenAI GPT-3 API for generating responses from the models.

Installation

Ensure you have the openai library installed. You can do this using pip:


pip install openai

Here’s the Script:



import openai

# Set up your API key
openai.api_key = 'your_openai_api_key'

def get_response(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
return response['choices'][0]['message']['content']

def main(topic):
# Seed the conversation with a topic
messages = [
f"Let's have a hilarious conversation about {topic}!"
]

# Initiate two LLMs talking to each other
for _ in range(5): # Number of exchanges
user_message = messages[-1]
assistant_response = get_response(user_message)
messages.append(assistant_response)
# Use the assistant's response as the next user's prompt
messages.append(f"Assistant: {assistant_response}")

# Simulate the second LLM responding
response2 = get_response(assistant_response)
messages.append(response2)

# Save the conversation to a text file
with open("llm_conversation.txt", "w") as file:
for message in messages:
file.write(message + "\n")

print("Conversation saved to llm_conversation.txt")

if __name__ == "__main__":
seed_topic = "the secret life of house cats"
main(seed_topic)

How It Works:

  1. Setup: The script initializes your OpenAI API key and imports the necessary library.
  2. Response Function: It defines a get_response function to interact with the OpenAI API and fetch responses.
  3. Main Logic: The main function seeds the conversation with a topic, simulates dialogue between two LLMs, and collects their exchanges.
  4. Output: Finally, it writes the conversation to a text file named llm_conversation.txt.

Usage:

  • Install the necessary library.
  • Replace the API key with your own.
  • Adjust the seed topic to any fun or hilarious subject you'd like.
  • Run the script and check the output in llm_conversation.txt.

Enjoy your fun and light-hearted exchange between two LLMs!

Post Comment

You May Have Missed

Ready to try the best AI voices on the market?

elevenlabs
https://elevenlabs.io/