npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

megahal.js

v1.0.3

Published

A port of kranzky/megahal to JS, written using TS

Downloads

23

Readme

megahal.js

MegaHAL is a simple chatterbot.

This is a JavaScript implementation of the MegaHAL algorithm, more specifically a direct, nearly one-to-one port of kranzky/megahal. Major credits to kranzky, without whom this wouldn't exist.

Features & Caveats

  • TypeScript types are provided within the package.

  • A Sooth stochastic predictive model is also implemented almost one-to-one and may later be extracted into a separate package.

  • Both are licensed under the Unlicense license, in the spirit of the original packages. So basically, do whatever you want with it, but no warranty!

  • Training a personality is rather slow and may take a few seconds to complete. Anyone is more than welcome to suggest any performance improvements, I am sure many can be made.

  • It is not currently usable as a CLI application, but you can embed it into your own Node.js code.

Installation

Use your favorite package manager:

pnpm install megahal.js
yarn add megahal.js
npm install megahal.js

Usage

To start you must import the main class from the module.

import MegaHAL from 'megahal.js'

Using MegaHAL

Create a new instance of MegaHAL, and provide the personality you would like to use, using the name.

If you omit the personality name, default will be used.

Use .reply(line) to get a response for a a given line of text, and also learn from that line in the process.

You can use .train(filename) or .train(lines) to manually train the bot on the go.

import { MegaHAL } from 'megahal.js'

const bot = new MegaHAL('default')

const input = 'hello!'
const message = bot.reply(input)

Loading personalities

MegaHAL comes with several personalities pre-loaded. You can list them using MegaHAL.list().

To add a custom personality, use the addPersonality method.

To switch personalities on an existing instance, use the become method.

// list all personalities

console.log(MegaHAL.list())

// load a custom personality
MegaHAL.addPersonality('name', [
  'line 1',
  'line 2',
  // ...
])

// switch personality on-the-fly
import { MegaHAL } from 'megahal.js'
const bot = new MegaHAL('default')
bot.become('sherlock')

Continuous learning

You can save & load your continuous learning to a file, at your discretion so do it as often as you feel appropriate.

import { MegaHAL } from 'megahal.js'

const bot = new MegaHAL('default')

// save bot:
await bot.save('/path/to/file.zip')

// load bot at a later time:
await bot.load('/path/to/file.zip')