Install:
npm install github:StudioProcess/eliza-js
Single file builds are available in the build/ folder:
- build/eliza.mjs (ES Module)
- build/eliza.js (CommonJS Module)
Requirements:
- node >= 14.0.0
- npm >= 7.24.0
Clone git repo:
git clone https://github.com/StudioProcess/eliza-js
Install dependencies:
cd eliza-js
npm install
Start dev server:
npm start
import { make_eliza_async } from 'eliza-js';
(async () => {
const eliza = await make_eliza_async('./scripts/example.mjs');
console.log( 'Eliza: ' + eliza.get_initial() );
while ( ! eliza.is_quit() ) {
const input = await GET_USER_INPUT();
console.log( 'You: ' + input )''
console.log( 'Eliza: ' + eliza.transform(input) );
}
})();
To construct a chatbot instance call the make_eliza_async() function supplied by the library:
import { make_eliza_async } from 'eliza-js';
const eliza = await make_eliza_async('./scripts/example.mjs');
Note that the function is async, since it needs to dynamically load the script file.
If you've got a script object already, you can use make_eliza() instead.
Params:
script_url
: URL to script (.mjs with a default export, e.g. scripts/example.mjs)options
: (optional) object containing one or more of the following optionsdebug
: (defaultfalse
)debug_options
: (defaultfalse
)debug_script
: (defaultfalse
)memory_size
: (default100
)shuffle_choices
: (defaultfalse
)lowercase_input
: (defaulttrue
)lowercase_input_quit
: (defaulttrue
)lowercase_output
: (defaultfalse
)seed
: (default-1
)wildcard_marker
: (default'*'
)tag_marker
: (default'#'
)memory_marker
: (default'@'
)goto_marker
: (default'='
)param_marker_pre
: (default'$'
)param_marker_post
: (default''
)stop_chars
: (default'.,;:?!'
)stop_words
: (default['but']
)allow_chars
: (default'\'äöüß-'
)fallback_reply
: (default'I am at a loss for words.'
)fixed_initial
: (default:0
)fixed_final
: (default:0
)reverse_parts
: (default:false
)shuffle_parts
: (default:false
)
Returns:
- Promise that resolves with an ElizaInstance object
Params:
script
: script object (see e.g. the default export in scripts/example.mjs) or string. Allowed strings are JSON source text with //-style comments (see scripts/example.json) or mjs source text with a single default export (see scripts/example.mjs).options
: (optional) see make_eliza_async()
Returns:
- A new ElizaInstance object
An eliza instance is an object with the following functions:
Additionally, it contains async versions of the three text-generating functions, which add a delay before an answer is returned:
Get an initial greeting from Eliza. Use at the beginning of the conversation.
Params:
- None
Returns:
- String. Initial sentence from Eliza.
Get a farewell message from Eliza. Can be used at the end of the conversation to get more final messages. Note when is_quit() returns true, the first final message has already been received, as the return value of the last transform().
Params:
- None
Returns:
- String. Final sentence from Eliza.
To talk to Eliza, an input text is 'transformed' into a reply. Use to get Eliza's replies to user inputs.
Params:
text
: The input sentence.
Returns:
- String. Eliza's response.
Check if a quit phrase (like 'goodbye') has been encountered since the start of the conversation. Call after every transform() to check if a quit condition has been reached, in which case the conversation should be stopped.
Params:
- None
Returns:
- Boolean.
true
if a quit condition has been encountered so far,false
otherwise.
Reset Eliza's internal state to initial conditions. Use to start a new conversation without creating a new chatbot instance (which reloads and reparses the script).
Params:
- None
Returns:
- None
Retrieve options object used to construct the chatbot instance. See make_eliza_async().
Params:
- None
Returns:
- The options object.
Asyncronous version of get_initial(), that adds a delay to Eliza's response.
Params:
delay
: See transform_async(text, delay)
Returns:
- Promise that resolves to a string with Eliza's response.
Asyncronous version of get_final(), that adds a delay to Eliza's response.
Params:
delay
: See transform_async(text, delay)
Returns:
- Promise that resolves to a string with Eliza's response.
Asyncronous version of transform(), that adds a delay to Eliza's response.
Params:
text
: The input sentence.delay
: (Default[1, 3]
) Delay in seconds before response is returned. Either a single number or an array with two numbers[delay_min, delay_max]
in which case the delay is a random number between the two values.
Returns:
- Promise that resolves to a string with Eliza's response.