typescript2openai
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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:

Package Sidebar

Install

npm i typescript2openai

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

15.2 kB

Total Files

8

Last publish

Collaborators

  • tarasglek