JSPM

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

CLI util that collects project code examples to make AI prompts better

Package Exports

  • @n1k1t/promptkit
  • @n1k1t/promptkit/lib/src/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 (@n1k1t/promptkit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PromptKit

CLI util that collects project code examples to make AI prompts better



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

# Use examples below to generate code by prompt

### Create a property foo

```ts
@Property({ parameter: 'foo' })
foo!: string;
```

### Create a property bar

```ts
@Property({ parameter: 'bar' })
bar!: string;
```

### Create a method baz

```ts
public baz(): boolean {
  return true;
}
```

### Create a class Foo

```ts
@Class()
export class Foo {
  @Property({ parameter: 'foo' })
  foo!: string;

  @Property({ parameter: 'bar' })
  bar!: string;

  public baz(): boolean {
    return true;
  }
}
```

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 --dist [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

# Use examples below to generate code by prompt

### Create enum test with values FOO, BAR, BAZ

```ts
export type TTest = ConvertTupleToUnion;
export const LTest = ['FOO', 'BAR', 'BAZ'];
```

### Create a prepared class with properties

```ts
@Class()
class Foo {
  @Property()
  foo!: number;
}
@Class()
class Bar extends Foo {
  @Property()
  bar!: string;
}
```

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"