JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q51879F
  • License MIT

A simple TypeScript/Javascript functions to openai tool call format

Package Exports

  • @draftor/tools
  • @draftor/tools/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@draftor/tools) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@draftor/tools

A simple TypeScript npm package designed to transform your function comments into an OpenAI Tool calling format. It's an alternative to zod and z. Built to maintain functions used for tool calling in a separate file, this package allows you to generate OpenAI Tool Calling JSON format without writing extensive code or using .describe().

⚠️ Caution: Check your Linter and Prettier config before add this package!

This approach deviates from typical TypeScript patterns. The comment must reside within the function, not outside. For example:

DO ✅ 
export function foo(bar:string) {
  /**
   * @description Converts a number to its string representation.
   * @param {boolean} bar - The bool to convert.
   * @param {number} abc - The number to convert.
   * @param {string} xyz - The string to convert.
   * @param {undefined} mpn - The any to convert.
   * @returns {object} The Object as response.
   */
  return bar.toString();
}

DON'T ❌
/**
 * @description Converts a number to its string representation.
 * @param {boolean} bar - The number to convert.
 * @param {number} abc - The number to convert.
 * @param {string} xyz - The number to convert.
 * @param {undefined} mpn - The number to convert.
 * @returns {object} The string representation of the input number.
 */
export function foo(bar: string) {
  return bar.toString();
}

Installation

To install the package, use npm:

npm install @draftor/tools

Usage

Here's a basic example of how to use the Tools class:

Your tool/functions for tool calling

# yourFunctions.ts

export function foo(bar:string) {
  /**
   * @description Converts a number to its string representation.
   * @param {boolean} bar - The number to convert.
   * @param {number} abc - The number to convert.
   * @param {string} xyz - The number to convert.
   * @param {undefined} mpn - The number to convert.
   * @returns {object} The string representation of the input number.
   */
  return bar.toString();
}
import { Tools } from '@draftor/tools';
import { foo } from './yourFunctions';

const tools = new Tools(funcs);
const result = tools.toOpenAI('string');
console.log(result); //will print in json string as output
{
  "name": "foo",
  "description": "No description provided.",
  "params": {
    "type": "object",
    "properties": {
      "bar": {
        "type": "boolean",
        "description": "The number to convert."
      },
      "abc": {
        "type": "number",
        "description": "The number to convert."
      },
      "xyz": {
        "type": "string",
        "description": "The number to convert."
      },
      "mpn": {
        "type": "any",
        "description": "The number to convert."
      }
    },
    "required": [
      "bar",
      "abc",
      "xyz",
      "mpn"
    ]
  },
  "returns": {
    "type": "object",
    "description": "The string representation of the input number."
  }
}

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT License.

Author

https://x.com/p_naix

Acknowledgments