selfplay

Selfplay is a Python framework designed for simulating role-based dialogues using chatbot interactions. It provides a flexible environment for creating and testing conversational scenarios, making it ideal for research, training, and interactive applications. With built-in templates for various role-play situations, Selfplay helps automate dialogue

https://github.com/prdeepakbabu/selfplay

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary

Keywords

behavioral-sciences dialogue-systems gpt4 llm simulation theory-of-mind
Last synced: 6 months ago · JSON representation ·

Repository

Selfplay is a Python framework designed for simulating role-based dialogues using chatbot interactions. It provides a flexible environment for creating and testing conversational scenarios, making it ideal for research, training, and interactive applications. With built-in templates for various role-play situations, Selfplay helps automate dialogue

Basic Info
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 2
  • Releases: 0
Topics
behavioral-sciences dialogue-systems gpt4 llm simulation theory-of-mind
Created over 1 year ago · Last pushed 9 months ago
Metadata Files
Readme License Citation

README.md

MultiBot Simulation for Self-Play 🗣️🔄🗣️

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! Image

Here's the illustration of two chatbots engaging in self-play, designed to highlight their interaction in a modern tech environment.

Features

  • 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

Installation

You can install the package via pip:

```sh

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] ```

Usage

Example 1: Multi-turn Self Chat with Azure OpenAI

In this example, the chatbot will perform a self-chat to simulate a conversation with itself using Azure OpenAI.

```python import os from selfplay.chatbot import Chatbot

Set Azure OpenAI credentials

os.environ["AZUREOPENAIAPIKEY"] = "your-api-key" os.environ["AZUREOPENAIAPIENDPOINT"] = "https://your-endpoint.openai.azure.com" os.environ["AZUREOPENAIAPI_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) ```

Example 2: Chat with Another Bot using OpenAI

In this example, two chatbots interact with each other using the OpenAI API.

```python import os from selfplay.chatbot import Chatbot

Set OpenAI credentials

os.environ["OPENAIAPIKEY"] = "your-openai-api-key"

Initialize chatbots with specific roles and system messages

teacher = Chatbot( name="Teacher", sysmsg="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", sysmsg="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.", numturns=2, # maxturns in conversation filename="teacher-student.html" # export the chat results in a well-formatted HTML file ) print(response) ```

Example 3: Using Anthropic Claude

```python import os from selfplay.chatbot import Chatbot

Set Anthropic credentials

os.environ["ANTHROPICAPIKEY"] = "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) ```

Example 4: Using the Gradio UI

You can launch the Gradio UI to interact with the chatbots through a web interface:

```python from selfplay.app_gradio import main

Launch the Gradio app

main() ```

Alternatively, you can use the provided script:

sh python run_gradio.py

The 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

Contributing

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:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Make your changes and commit them (git commit -am 'Add new feature')
  4. Push the branch (git push origin feature-branch)
  5. Submit a pull request

Issues & Feedback

Found a bug or have a suggestion? Open an issue here to collaborate on improvements. We actively review and address community feedback.

Collaboration & Partnerships

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.

Owner

  • Name: Deepak Babu P R
  • Login: prdeepakbabu
  • Kind: user
  • Location: Seattle

Lead Scientist | Large Language Models, ASR, NLP, IR, Machine Learning and Statistics

Citation (CITATION.cff)

@software{selfplay2024,
  author = {Deepak Babu, Piskala},
  title = {Selfplay: A Python Framework for Role-Based Dialogue Simulation},
  year = {2024},
  howpublished = {\url{https://github.com/prdeepakbabu/selfplay}},
  note = {Version 1.0.0},
  doi = {10.5281/zenodo.13721990},
}

GitHub Events

Total
  • Watch event: 1
  • Push event: 2
Last Year
  • Watch event: 1
  • Push event: 2

Dependencies

requirements.txt pypi
  • markdown2 *
  • openai *
  • python-dotenv *
  • pyyaml *
  • requests *
setup.py pypi
  • markdown2 *
  • openai *
  • pyyaml *
  • requests *