Skip to content

Instantly share code, notes, and snippets.

@obeone
Last active January 14, 2024 10:28
Show Gist options
  • Save obeone/da3ab8725726df9aa4d97e9cf672110b to your computer and use it in GitHub Desktop.
Save obeone/da3ab8725726df9aa4d97e9cf672110b to your computer and use it in GitHub Desktop.
TypingMind Plugin API Writer

TypingMind API Plugin Writer

Introduction

You can use GPT-3.5 (and obviously GPT-4) to write API plugins for TypingMind !

With the right character and the right documentation used by GPT, it can write your plugin in a few seconds, you just have to use copy/paste. Here is an example

Prerequisites

  • TypingMind, obviously
  • A way to download data (do a HTTPs GET). You can use my Simple CORS proxy or anything else, like Browserless integration...

Usage

  • Add this character
  • Always tell it to downloads the documentation ! I didn't find a way to do it using system prompt.
  • Be precise in what you want your plugin does.

API Documentation for TypingMind Plugin Development

Introduction

TypingMind plugins allow you to extend the capabilities of the AI assistant by providing external tools. Plugins are JavaScript code executed locally in the user's browser.

This documentation (especially the raw file, ~700 tokens) can be given to GPT to ask for a plugin.

Plugin Development

To create a plugin, you need to provide an OpenAI Function Spec and the JavaScript implementation.

Mandatory parts are:

  • Code for the JavaScript implementation.
  • OpenAI Function Spec

Optional parts are:

  • User Settings
  • Custom Output

OpenAI Function Spec

  • Must be in the correct JSON format.
  • Format is a kind of JSON Schema but specific to OpenAI.
  • The name field must be unique among all your plugins.
  • Include meaningful names and descriptions to facilitate understanding and usage by the AI.

Example JSON specification:

{
  "name": "generate_random_number_in_range",
  "description": "Generates a random integer between 'a' and 'b'.",
  "parameters": {
    "type": "object",
    "properties": {
      "a": {
        "type": "number",
        "description": "The number a (the smallest)"
      },
      "b": {
        "type": "number",
        "description": "The number b (the largest)"
      }
    },
    "required": ["a", "b"]
  }
}

Code Implementation

  • The code must be valid JavaScript.
  • The function name must match the one specified in the JSON.
  • The function accepts two parameters: params (AI parameters) and userSettings (user parameters).

Example JavaScript code:

function generate_random_number_in_range({a, b}) {
  var min = Math.ceil(a);
  var max = Math.floor(b);
  return Math.floor(Math.random() * (max - min + 1) + min);
}

User Parameters (Plugin User Settings)

Allows defining input fields for users in JSON format.

Example JSON format for user parameters:

[
  {
    "name": "searchEngineID",
    "label": "Search Engine ID"
  },
  {
    "name": "searchEngineAPIKey",
    "label": "Search Engine API Key",
    "type": "password"
  }
]

Custom Output

Use custom output to directly display the result to users.

Example of custom output:

return {
  _TM_CUSTOM_OUTPUT: true,
  type: 'markdown',
  data: markdownText,
  response: "The images have been rendered and displayed to the user."
};

Plugin Testing

After saving the information, enable your plugin and test it by interacting with the AI.

Plugin Examples

Community-created plugin examples are available for reference.

Known Issues

  • Hallucination issue: the AI may attempt to call your function with incorrect parameters. Use "Regenerate" to retry.

Update

Last updated: June 29, 2023


This documentation is a summary of the essential information for creating a plugin for TypingMind. For complete details, please refer to the official documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment