1.0.1 • Published 4 months ago

typescript2openai v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

This is a utility to convert TypeScript/JavaScript function signatures with jsdoc comments to OpenAI function spec.

Usage

import { parseTypeScript } from "typescript2openai";
parseTypeScript("function funcWithArrayAndOptionalParam(firstParam: string[], optional?: number) {}");

Go from this:

/**
 * Example of a function that takes an array and has an optional parameter
 * @param Marvel at how verbose these are to write manually
 * @param optional This one does not show up in required
 */
function funcWithArrayAndOptionalParam(firstParam: string[], optional?: number) {
}

to

{
  "name": "funcWithArrayAndOptionalParam",
  "description": "Example of a function that takes an array and has an optional parameter",
  "parameters": {
      "type": "object",
      "properties": {
          "firstParam": {
              "type": {
                  "type": "array",
                  "items": {
                      "type": "string"
                  }
              }
          },
          "optional": {
              "type": "number",
              "description": "This one does not show up in required"
          }
      },
      "required": [
          "firstParam"
      ]
  }
}

See the unit test for examples of conversions and usage: basic.test.ts

See also:

1.0.1

4 months ago