Add magic spells to your code.
Incant gives you primtivies that let you integrate language model invocations safely to your program.
Warning
All data provided as input to incant primitives will be sent to upstream providers. Avoid sending personal and sensitive information.
// incant looks in your env array for an OPENAI_API_KEY & other vars
// easy to end users to configure for your cli
const { createSelector } = createIncant({
env: Deno.env.toObject(),
});
// create a llm-powered function to pick highest number
const pickHighestNumber = createSelector<number>("Pick the highest number");
const input = [
1,
10,
3,
10000,
5,
999,
];
// type-safe and hallucination-safe – output is guaranteed to be one of input array
const highestNumber = await pickHighestNumber(input);
// make a function to filter only male names
const filterMaleNames = createFilter<string>("Return male names");
const maleNames = await filterMaleNames([
"John",
"Jack",
"Jane",
"Beatrice",
"Mike",
"Emily",
"Charlie",
"Robin",
"Alex",
]);
// original array ordering is preserved
// no hallucinations possible: output is guaranteed to be subset of input array
// [ "John", "Jack", "Mike", "Charlie", "Alex" ]