SelfPlay is a Python package that allows you to simulate conversations between multiple chatbots. The package includes an orchestrator bot to determine the order of responses based on a given goal.
Introducing SelfPlay Project – a versatile and intelligent chatbot package designed to enhance your conversational AI capabilities. With features enabling multi-turn self-chat and seamless interaction between two chatbots, this package leverages the power of LLMs to deliver insightful and dynamic conversations. Perfect for developers, educators, and businesses looking to integrate advanced chatbot functionalities, Self-play offers robust logging, error handling, and easy customization to meet your unique needs.
NEW: SelfPlay now includes a Gradio-based UI and support for multiple LLM providers including OpenAI, Azure OpenAI, Anthropic, Google, Meta, and AWS Bedrock!

Here's the illustration of two chatbots engaging in self-play, designed to highlight their interaction in a modern tech environment.
- Simulate conversations among multiple bots
- Orchestrator bot to manage conversation flow
- Provides Memory for LLM conversations
- Multi-turn Conversations with control for maximum turns
- Ability to export conversation as a neatly formatted HTML
- Easy-to-use API
- NEW: Gradio-based user interface for easy interaction
- NEW: Support for multiple LLM providers:
- Azure OpenAI
- OpenAI
- Anthropic (Claude)
- Google (Gemini)
- Meta (Llama)
- AWS Bedrock
You can install the package via pip:
# Basic installation
pip install selfplay
# With UI support
pip install selfplay[ui]
# With all providers
pip install selfplay[all]
# With specific providers
pip install selfplay[anthropic,google,aws]In this example, the chatbot will perform a self-chat to simulate a conversation with itself using Azure OpenAI.
import os
from selfplay.chatbot import Chatbot
# Set Azure OpenAI credentials
os.environ["AZURE_OPENAI_API_KEY"] = "your-api-key"
os.environ["AZURE_OPENAI_API_ENDPOINT"] = "https://your-endpoint.openai.azure.com"
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-12-01-preview"
# Self-chat multi-turn conversation
bot = Chatbot(
name="default",
sys_msg="You are a helpful assistant and honest in responses. You give short and concise responses.",
provider="azure", # Using Azure OpenAI
model="gpt-4"
)
bot.chat("What is the capital of California?")
bot.chat("How about Oregon?")
bot.chat("How many people live here?")
print(bot)In this example, two chatbots interact with each other using the OpenAI API.
import os
from selfplay.chatbot import Chatbot
# Set OpenAI credentials
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
# Initialize chatbots with specific roles and system messages
teacher = Chatbot(
name="Teacher",
sys_msg="You are a helpful teacher with extensive knowledge of science and math. "
"You ask thoughtful questions to motivate and invoke students' curiosity and depth. "
"Provide concise, crisp, and clear replies.",
provider="openai", # Using OpenAI
model="gpt-4"
)
student = Chatbot(
name="Student",
sys_msg="You are a student trying to learn from a teacher. "
"Ask clarifying questions until the topic is clear to you.",
provider="openai", # Using OpenAI
model="gpt-4"
)
# Interact between the teacher and student chatbots
response = teacher.interact(
student, # who to interact with
start="I'm a 4th grader and I don't seem to quite understand what complex numbers are.",
num_turns=2, # max_turns in conversation
filename="teacher-student.html" # export the chat results in a well-formatted HTML file
)
print(response)import os
from selfplay.chatbot import Chatbot
# Set Anthropic credentials
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-api-key"
# Create a chatbot using Anthropic Claude
bot = Chatbot(
name="Claude",
sys_msg="You are Claude, a helpful and harmless AI assistant.",
provider="anthropic",
model="claude-3-opus"
)
response = bot.chat("Tell me about the history of artificial intelligence.")
print(response)You can launch the Gradio UI to interact with the chatbots through a web interface:
from selfplay.app_gradio import main
# Launch the Gradio app
main()Alternatively, you can use the provided script:
python run_gradio.pyThe UI allows you to:
- Select different LLM providers
- Configure API credentials
- Choose between Self-Chat, Bot-to-Bot Chat, and Template-Based Chat
- Customize bot personas and conversation parameters
- View and export conversation results
We welcome contributions to the Selfplay framework! Please read our CONTRIBUTING.md for guidelines on how to contribute, including submitting pull requests and reporting issues.
To contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch) - Make your changes and commit them (
git commit -am 'Add new feature') - Push the branch (
git push origin feature-branch) - Submit a pull request
Found a bug or have a suggestion? Open an issue here to collaborate on improvements. We actively review and address community feedback.
We’re open to collaborating with researchers and developers interested in extending Selfplay or integrating it into larger projects. Feel free to reach out via [prdeepak.babu@gmail.com] for discussions regarding joint development or research partnerships.