is-true-that
v1.0.2
Published
Is it true that? A AI-based check utility library for JavaScript. Check the truth of any kind of statement.
Downloads
65
Maintainers
Readme
Is True That
is-true-that
is the most serious library you'll ever need to determine if something is true. Or not. Seriously. Given an object and a natural language condition, it evaluates whether it is true or false.
What is this?
Free, funny and (maybe) useful truth testing tool
This library is designed to bring a bit of humor to your coding experience while providing a straightforward way to assess truthiness in your JavaScript applications.
In short, you can test the veracity of anything you like.
Important: This is a beta release. Accuracy is not guaranteed, and computing speed is relatively slow. Please refer to the Timing section for details.
Installation
npm install is-true-that
Usage
This library is easy to import and use. The basic usage involves the isTrueThat
function, where you pass an object and a natural language statement, receiving true
if the condition holds, and false
otherwise.
const isTrueThat = require('is-true-that');
console.log(isTrueThat({ food: 'pizza', toppings: ['cheese', 'pepperoni'] }, 'is it a pizza with pepperoni')); // true
console.log(isTrueThat({ food: 'pizza', toppings: ['cheese', 'pepperoni'] }, 'is it a pizza with pepperoni but without cheese and tomatoes')); // false
console.log(isTrueThat(7, 'is it a prime number')); // true
console.log(isTrueThat(1000, 'is this the number of soldiers in a Roman legion?')); // false
console.log(isTrueThat({ animal: 'snake', length: 5 }, 'is it 3+2 meters long?')); // true
For more advanced usage, you can configure LLM (Large Language Model) options, timing, verbosity, and capabilities:
import { isTrueThat, initModel } from 'is-true-that';
async function main() {
const options = {
verbose: true,
modelName: 'your-model-name-here'
};
// Initialize a model
options.model = await initModel(options);
// These requests share the same chat, speeding up computation
console.log(await isTrueThat({ food: 'pizza', toppings: ['cheese', 'pepperoni'] }, 'is it a pizza with pepperoni', options)); // true
console.log(await isTrueThat({ food: 'pizza', toppings: ['cheese', 'pepperoni'] }, 'is it a pizza with pepperoni but without cheese and tomatoes', options)); // false
console.log(await isTrueThat(7, 'is it a prime number', options)); // true
console.log(await isTrueThat(1000, 'is this the number of soldiers in a Roman legion?', options)); // false
console.log(await isTrueThat({ animal: 'snake', length: 5 }, 'is it 3+2 meters long?', options)); // true
}
main();
Caution: Each
isTrueThat
function call initializes a new model or chat session if they are not provided in theoptions
.
Why?
Sometimes you just need to know if something is true. And sometimes, you need a good laugh.
On a more serious note, in certain situations, such as dynamic user inputs, you may require a quick truth assessment based on natural language queries without having to implement complex logic. LLMs can be useful for evaluating such truths!
Features
- 82% Accuracy: Generally tells you if something is true or not.
- Lightweight: No unnecessary bloat (basic model requires 2GB of disk space and up to 4GB of RAM).
- Humorous: Because why not?
Timing
We ran 150 test cases using npm test
and found that the average execution time is 16,834ms with a standard deviation of 5,230ms. Longer execution times occur when the context window exceeds 1,000 tokens, which can take up to 16 seconds to recover (typically every 5-10 requests). This can be mitigated by clearing the chat or increasing the number of context tokens.
Sample Test Results
| Test Case | Description | Expected Result | Actual Result | Pass/Fail | |-----------|-------------|-----------------|---------------|-----------| | 1 | Pizza with pepperoni | true | true | Pass | | 2 | Pizza with pepperoni but without cheese and tomatoes | false | false | Pass | | 3 | Prime number check for 7 | true | true | Pass | | 4 | Roman legion soldiers count | false | false | Pass | | 5 | Snake length check | true | true | Pass |
These results demonstrate the accuracy and reliability of the is-true-that
library in various scenarios.
Models
Is True That uses orca-mini-3b-gguf2-q4_0.gguf
as base model which is a performant but non-commercial model offered with gpt4all
. It weights 2GB and will be installed once and then cached. It requires 4GB of RAM to be executed locally.
For more consistent results, we suggests Llama 3 8B Instruct or heavier models. More information at gpt4all-models.
Other
Contributing
- Fork the repository!
- Create a feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request!
License
MIT
Made with ❤️ and a sense of humor.