0.0.7 • Published 7 months ago

@n1k1t/promptkit v0.0.7

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

License npm version Dynamic XML Badge

Install

npm i -D @n1k1t/promptkit

How it works?

The promptkit uses custom JSDoc tags @ai to define what some code is actually do in a JavaScript/TypeScript project for AI perspective. It takes all segments of described code and compiles into batch of formats to use it for AI fine-tuning or rules of ContinueDEV and so on...

For example you have a NodeJs/Typescript project with some code:

// src/index.ts

const Property = (options?: object): PropertyDecorator => () => {/** ...code */};
const Class = (options?: object): ClassDecorator => () => {/** ...code */};

/** @ai Create a class Foo */
@Class()
export class Foo {
  /** @ai Create a property foo */
  @Property({ parameter: 'foo' })
  foo!: string;

  /** @ai Create a property bar */
  @Property({ parameter: 'bar' })
  bar!: string;

  /**
   * @ai Create a method baz
   * @description A baz method
   */
  public baz(): boolean {
    return true;
  }
}

Using the promptkit command npx promptkit collect src/**/*.ts the promptkit will generate a promptkit.md file in the root of project that contains:

... "promptkit.md" file content

After that you'll able to use the generated file for prompting as project context to get better results

API

General

$ npx promptkit -h

Usage: cli [options] [command]

It helps to setup AI code assistants with prompt annotations

Options:
  -h, --help                   display help for command

Commands:
  collect [options] [pattern]  Collects @ai annotations with code by provided path pattern
  help [command]               display help for command

Command collect

$ npx promptkit collect -h

Usage: cli collect [options] [pattern]

Collects @ai annotations with code by provided path pattern

Options:
  -f --format [json|md|yaml|continuedev|finetuning]  Annotations format (default: "md")
  -o --output [stdout|file]                          Annotations output (default: "file")
  -d --dest [value]                                  Destination path for a file
  -i --ignore [value]                                Ignore pattern (default: "node_modules/**")
  -h, --help                                         display help for command

Examples

$ npx promptkit collect -f json -o stdout src/*.js

[{"path":"src/index.js","lang":"js","prompt":"Create a class method test","code":"test() {\n  return true;\n}"},{"path":"src/index.js","lang":"js","prompt":"Create a class","code":"export class Test1 {\n  constructor() {}\n\n  test() {\n    return true;\n  }\n}"}]
$ npx promptkit collect -f finetuning -o stdout src/*.js

{"messages":[{"role":"user","content":"Create a class method test"},{"role":"assistant","content":"```js\ntest() {\n  return true;\n}\n```\n"}]}
{"messages":[{"role":"user","content":"Create a class"},{"role":"assistant","content":"```js\nexport class Test1 {\n  constructor() {}\n\n  test() {\n    return true;\n  }\n}\n```\n"}]}
$ npx promptkit collect -f continuedev -o stdout src/*.js

name: PROMPTKIT
version: 0.0.1
schema: v1
rules:
  - |
    # Use examples below to generate code by prompt

    ### Create a class method test

    ```js
    test() {
      return true;
    }
    ```

    ### Create a class

    ```js
    export class Test1 {
      constructor() {}

      test() {
        return true;
      }
    }
    ```

Features

Groups

The promptkit supports a grouping of segments of code using @ai {...group} format

Examples

... TypeScript code

// src/index.ts

import { ConvertTupleToUnion } from '../../types';

const Property = (options?: object): PropertyDecorator => () => {/** ...code */};
const Class = (options?: object): ClassDecorator => () => {/** ...code */};

/** @ai {enum} Create enum test with values FOO, BAR, BAZ */
export type TTest = ConvertTupleToUnion<typeof LTest>;
/** @ai {enum} */
export const LTest = <const>['FOO', 'BAR', 'BAZ'];

/** @ai {class} Create a prepared class with properties */
@Class()
class Foo {
  @Property()
  foo!: number;
}

/** @ai {class} */
@Class()
class Bar extends Foo {
  @Property()
  bar!: string;
}

... Executing the "collect" command

npx promptkit collect -f md -o stdout src/*.ts

... Console stdout

Additional

ENV

# Ignore pattern
export PROMPTKIT_IGNORE = "node_modules/**"
# A header title that will be placed as H1 tag into markdown content
export PROMPTKIT_MD_HEADER = "Use examples below to generate code by prompt"