chatin

1.2.3 • Public • Published

Chatin

Chatin is a functions plugin interface for chatbots such as ChatGPT.

Chatin simplifies the development of tools leveraging chatbots by providing a simple decorator-based interface for developing chat functions. It also provides a controller for managing chat interactions.

An example of a "system" plugin is provided in example_plugin.ts, and example usage can be found in example_usage.ts.

Plugins are defined in a class, and functions exposed to the chatbot are decorated with descriptions that are passed to the chatbot:

export class SystemPlugin {

    /** Fetch a URL and return raw text. */
    @ChatFunction({
        name: "fetch",
        description: "Fetch a URL and return raw text"
    })
    async chatFetch(
        @ChatParameter({
            description: "The URL to fetch",
            type: "string",
            required: true
        }) url: string) {
        return await (await fetch(url)).text();
    }
    ...
}

Your application can then register the plugin, which will be passed to the bot during a conversation:

const configuration = new Configuration({
    apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);
const controller = new ChatFunctionsController(openai);
const plugin = new SystemPlugin();

controller.registerFunctions(plugin, { enable : ['date_time', 'fetch'] });

controller.addSystemMessage("You are helpful chatbot who uses functions to answer user questions.");

let completion = await controller.getCompletionWithMessage({
    role: 'user',
    content: "Who is the current president of the United States?"
})

While Chatin is currently tied to OpenAI's ChatGPT API, the plan would be to decouple this in the future so existing plugins could be used by any chatbot in the future.

Readme

Keywords

none

Package Sidebar

Install

npm i chatin

Weekly Downloads

1

Version

1.2.3

License

Apache-2.0

Unpacked Size

37.6 kB

Total Files

5

Last publish

Collaborators

  • no2chem