Login Sign Up

GPT Assistants Playground

The GPT Assistants Playground is an open-source project that provides an interface for building AI assistants using Gradio and the OpenAI Assistants API. This guide will walk you through the installation, setup, and customization of the Playground.

Installing and Running the Playground

Since no PyPI package is available, install it manually.

Installation Steps

> git clone https://github.com/cxbxmxcx/GPTAssistantsPlayground
> cd GPTAssistantsPlayground
> pip install -r requirements.txt

Set up your OpenAI API key and run the application:

export OPENAI_API_KEY="your-api-key"
python main.py

Access the interface at http://127.0.0.1:7860.

Creating and Using Custom Actions

Custom actions allow assistants to perform specialized tasks.

Adding a Custom Action

  1. Navigate to playground/assistant_actions/.
  2. Create a new Python file (e.g., custom_action.py) or edit an existing one.
  3. Define a function and decorate it with @agent_action.

Example: Save File Action

import os

from playground.actions_manager import agent_action

OUTPUT_FOLDER = "assistant_outputs"

@agent_action    #1

def save_file(filename, content):     #2

    """

    Save content to a file.     #3

    :param filename: The name of the file including extension.

    :param content: The content to save in the file.

    """

    file_path = os.path.join(OUTPUT_FOLDER, filename)

    with open(file_path, "w", encoding="utf-8") as file:

        file.write(content)

    print(f"File '{filename}' saved successfully.")     #4

Restart the Playground to load the new action.

Installing Prebuilt Assistants

Use the assistants.db database to install prebuilt assistants.

Steps to Install Assistants

  1. Create a new assistant or use an existing one.
  2. Add the create_manager_assistant action from the Actions section.
  3. Ask the assistant: “Please create the Manager Assistant.”
  4. Refresh your browser and select Manager Assistant.
  5. Ask: “Install all available assistants.”

RunCode Locally

The Playground supports local Python code execution.

Enabling Code Execution

  1. Enable the following actions:
    • run_code
    • run_shell_command (allows pip install for dependencies)
  2. Ask the assistant to generate and run Python code.

Example Request

“Write and execute a Python function for Fibonacci sequence.”

Example Code Execution

def fibonacci(n):

    a, b = 0, 1

    for _ in range(n):

        print(a, end=" ")

        a, b = b, a + b

    print()

fibonacci(10)

Monitoring Assistant Logs

The Playground captures assistant interactions for debugging.

Steps to View Logs

  1. Perform an assistant action.
  2. Open the logs section in the interface.
  3. Use logs to debug and optimize assistant behavior.

Investigating Assistant Actions with Logs

To monitor assistant processes, OpenAI Assistants API provides event logging.

Example: Using Logs to Debug

  1. Give an assistant the Code Interpreter tool.
  2. Ask it to plot an equation.
  3. Open the logs to see how the assistant executed the task.

This feature is useful for diagnosing assistant behavior and optimizing performance.