Skip to content

Instantly share code, notes, and snippets.

@DennisGross
Created April 13, 2023 21:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DennisGross/9ab35d40f142dc99a5782751f1c5eece to your computer and use it in GitHub Desktop.
Save DennisGross/9ab35d40f142dc99a5782751f1c5eece to your computer and use it in GitHub Desktop.
AI Philosopher's Roundtable: Enhancing AI-Driven Debates with Real-Time Analysis Using a Python Script
import openai
import time
openai.api_key = "API-KEY"
def generate_moderator_text(prompt, name, topic, model="gpt-4"):
response = openai.ChatCompletion.create(
model=model,
messages=[
{"role": "system", "content": f"You are a moderator named {name}, dedicated to ensuring that participants stay focused on the topic '{topic}' and engage in a deep, meaningful exploration of the subject matter. Your role is to critique, guide, and foster a productive discussion, continually driving the conversation forward. Your goal is to maintain the momentum of the discussion and maximize its potential for generating valuable insights. Rather than engaging directly in conversations, you communicate by simply writing your name followed by a colon (:). This enigmatic approach encourages others to reflect on their own ideas and consider alternative perspectives. Sometimes an EVALUATION is written, which you should use to improve your moderating skills."},
{"role": "user", "content": f"{prompt}"},
]
)
return response["choices"][0]["message"]["content"].strip()
def generate_text(prompt, name, model="gpt-4"):
response = openai.ChatCompletion.create(
model=model,
messages=[
{"role": "system", "content": f"You are a philosopher named {name}, known for your critical thinking and ability to drive discussions forward. Rather than engaging directly in conversations, you communicate by simply writing your name followed by a colon (:). This enigmatic approach encourages others to reflect on their own ideas and consider alternative perspectives. Sometimes an EVALUATION is written, which you should use to improve your discussion skills."},
{"role": "user", "content": f"{prompt}"},
]
)
return response["choices"][0]["message"]["content"].strip()
def evaluate(prompt, model="gpt-4"):
response = openai.ChatCompletion.create(
model=model,
messages=[
{"role": "system", "content": f"You are a GPT-based analysis system designed to summarize and evaluate discussions. Your purpose is to identify and highlight both the positive and negative aspects of a conversation. By these things, you help participants recognize the key points and main takeaways. Additionally, you carefully assess the strengths and weaknesses of the discussion, offering constructive feedback to encourage improvement and foster better understanding. Your goal is to promote meaningful and effective communication. Rather than engaging directly in conversations, you communicate by simply writing your EVALUATION followed by a colon (:). This enigmatic approach encourages others to reflect on their own ideas and consider alternative perspectives."},
{"role": "user", "content": f"{prompt}"},
]
)
return response["choices"][0]["message"]["content"].strip()
def main():
MAX_ITERATIONS = 39
system1 = "System1"
system2 = "System2"
moderator = "Moderator"
topic = input("Enter the topic to be discussed: ")
conversation = f"Discuss the topic '{topic}'."
with open(f"{topic}.txt", "w") as f:
f.write(conversation)
print(conversation.strip())
for i in range(MAX_ITERATIONS):
if i % 3 == 0:
if i % 12 == 0 and i != 0:
response += evaluate(conversation)
print("EVALUATION")
f.write(f"\n\n{response}\n")
print(f"\n\n{response}\n")
print("MODERATOR")
response = generate_moderator_text(conversation + f"{moderator}: ", moderator, topic)
conversation += f"{moderator}: {response}\n"
f.write(f"{moderator}: {response}\n")
print(f"{moderator}: {response}\n")
elif i % 3 == 1:
print("SYSTEM1")
response = generate_text(conversation + f"{system1}: ", system1)
conversation += f"{system1}: {response}\n"
f.write(f"{system1}: {response}\n")
print(f"{system1}: {response}\n")
else:
print("SYSTEM2")
response = generate_text(conversation + f"{system2}: ", system2)
conversation += f"{system2}: {response}\n"
f.write(f"{system2}: {response}\n")
print(f"{system2}: {response}\n")
time.sleep(1) # To avoid hitting the rate limits
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment