OpenPlugin Toolset

repository·main·Indexed 42 days ago

https://github.com/cakecrusher/openplugin

A toolset for integrating with OpenAI's ChatGPT plugins via API. It provides core packages (openplugincore) for direct plugin interaction using an OpenAI API key, and client packages (openpluginclient) that outsource requests to an OpenPlugin API using early access tokens. Available for Python (PyPI) and JavaScript/TypeScript (NPM).

Tokens
7K
Snippets
23
Records
34
Agent score
52%

What's inside OpenPlugin

  1. Overview of OpenPlugin packages

    main

    OpenPlugin allows you to integrate with OpenAI's ChatGPT plugins via API, providing functionality similar to the ChatGPT API + plugins ecosystem. The project is divided into two main functional layers: Core and Client.

    Core Packages

    Contains the essential tools required to interface with ChatGPT plugins (similar to ChatGPT Pro functionality).

    • Python: openplugincore (available on PyPI)
    • JavaScript/TypeScript: openplugincore (available on NPM)

    Client Packages

    These packages outsource requests to an OpenPlugin API, meaning you do not need to manage your own OpenAI API key. Instead, you use an early access token.

    • Python: openpluginclient (available on PyPI)
    • JavaScript/TypeScript: openpluginclient (available on NPM)
  2. Requirements for adding a plugin to the OpenPlugin ecosystem

    main

    To successfully add a plugin to the OpenPlugin ecosystem, ensure the following conditions are met:

    • Public Accessibility: The plugin must be deployed to a publicly accessible URL.
    • Authentication: Note that authentication is currently not supported for plugins.
  3. Install and use the PyPI `openpluginclient` package

    main

    The openpluginclient package allows you to outsource requests to an OpenPlugin API. This enables you to use specific plugins without managing your own OpenAI API key directly.

    To get started, install the package via PyPI and use the openplugin_completion function to interact with plugins.

    from openpluginclient import openplugin_completion
    
    plugin_name = "ByByAI" # enter plugin "Namespace" as written on PLUGINS.md 
    completion = openplugin_completion(
        early_access_token = "__extra__-c22a34e2-89a8-48b2-8474-c664b577526b", # (required)
        plugin_name = plugin_name, # optional
        model = "gpt-3.5-turbo-0613", # optional
        messages = [ # regular ChatGPT messages argument (required)
            {
                "role": "user",
                "content": "Show me a Best Amazon products for puzzles"
            }
        ],
        temperature = 0, # optional
        # ...other openai.ChatCompletion.create arguments
    )
    
    print(completion)
  4. Setup instructions to add a new plugin

    main

    Follow these steps to develop and register a new plugin within the OpenPlugin repository:

    1. Prepare your branch: Fork the repository, clone it locally, and create a new branch using the naming convention plugin/<PLUGIN_NAME> (e.g., git checkout -b plugin/todo).
    2. Configure OpenAI Credentials: Generate a new OpenAI secret key and add it to your environment variables as OPENAI_API_KEY.
    3. Environment Setup:
      • Create and activate a Python virtual environment.
      • Navigate to the openplugin/migrations/plugin_store directory.
      • Install dependencies: pip install -r requirements.txt.
    4. Registration:
      • Run the registration script: python add_plugin.py.
      • Follow the interactive prompts provided by the script.
    5. Submission:
      • Commit your changes (ensuring you exclude your virtual environment).
      • Create a pull request to merge your plugin/<PLUGIN_NAME> branch into the main branch of CakeCrusher/openplugin.
    # Example branch creation
    git checkout -b plugin/todo
    
    # Environment setup
    python -m venv venv
    source venv/bin/activate  # or venv\Scripts\activate on Windows
    cd openplugin/migrations/plugin_store
    pip install -r requirements.txt
    
    # Run the plugin addition script
    python add_plugin.py
  5. Use the OpenPlugin Client with early access tokens

    main

    When using the openpluginclient (NPM or PyPI), you do not need an OpenAI API key. Instead, you must provide one of the following early access token values to authenticate your requests to the OpenPlugin API:

    • __extra__-c22a34e2-89a8-48b2-8474-c664b577526b
    • __extra__-692df72b-ec3f-49e4-a1ce-fb1fbc34aebd
  6. Use openpluginCompletion for chat completions

    main

    The openpluginCompletion function allows you to outsource requests to an OpenPlugin API. It accepts arguments similar to the OpenAI ChatCompletion.create method.

    Required Arguments:

    • earlyAccessToken: A required access token string.
    • messages: An array of message objects (e.g., { role: 'user', content: '...' }).

    Optional Arguments:

    • pluginName: The "Namespace" of the plugin to use (refer to PLUGINS.md for valid names, e.g., "ByByAI").
    • model: The model identifier (e.g., "gpt-3.5-turbo-0613").
    • temperature: Sampling temperature.
    • Other standard OpenAI ChatCompletion.create arguments.
    import {openpluginCompletion} from 'openpluginclient'
    
    const pluginName = "ByByAI" // enter plugin "Namespace" as written on PLUGINS.md 
    const completion = await openpluginCompletion({
      earlyAccessToken: "__extra__-c22a34e2-89a8-48b2-8474-c664b577526b", // (required)
      pluginName: pluginName, // optional
      model: "gpt-3.5-turbo-0613", // optional
      messages: [ // regular ChatGPT messages argument (required)
          {
              "role": "user",
              "content": "Show me a Best Amazon products for puzzles"
          }
      ],
      temperature: 0, // optional
      // ...other openai.ChatCompletion.create arguments
    })
    
    // print as prettified JSON
    console.log(completion)
  7. Understand OpenPluginInfo data structures

    main

    The classification process relies on several TypedDict structures to manage plugin metadata. These structures track the lifecycle of a plugin from raw data to a validated OpenPlugin instance.

    • OpenPluginInfoBase: The core metadata including namespace, domain, openapi_url, and descriptions for both humans and models.
    • OpenPluginInfoInit: Extends the base with a whitelisted boolean.
    • OpenPluginInfoStimulated: Extends the init state with stimulated (boolean) and an optional stimulous_prompt (the prompt used to trigger the plugin).
    • OpenPluginInfo: The final state which includes a status string (supported, tentative, or unsupported).
  8. Classify and validate plugins using the classification pipeline

    main

    The classification pipeline processes raw plugin data (e.g., from OpenAI responses) to determine their compatibility and support status within OpenPlugin. The process follows these stages:

    1. Base Info Generation: Extracts metadata like namespace, auth, domain, and openapi_url from the raw plugin manifest.
    2. Whitelisting/Fetch Test: Attempts to instantiate an OpenPlugin class using the plugin's root_url. If successful, the plugin is marked as whitelisted.
    3. Stimulation Test: Uses an LLM (e.g., GPT-3.5) to generate a natural language prompt designed to trigger the plugin. It then calls openplugin_class.fetch_plugin() with that prompt. If the plugin responds correctly, it is marked as supported.

    Plugin Statuses:

    • supported: Passed the stimulation test (should work).
    • tentative: Passed basic whitelisting/fetch tests but failed or did not undergo stimulation (may work).
    • unsupported: Failed whitelisting, is blacklisted, or requires complex authentication that isn't handled.
    # Example of the high-level classification call
    composite = classify_plugin(openplugins_info, openai_res_ex)