Integrate AI with your code like any other function, no build steps required!
import ai from 'https://aifn.run/ai.mjs'
await ai.configure("__AIFN_KEY__");
const noVerbs = await ai.fn({ p: 'Remove all verbs from this paragraph: "{input}"' });
export async function removeVerbsFromText(text: string) {
return await noVerbs({ input: text });
}
console.log(await removeVerbsFromText('The brown fox jumps over the lazy dog.'));
// "The brown fox over the lazy dog"
Async Functions
and ES Modules
are widely supported by browsers and can also be used to mix AI and Javascript.
One-off AI completions can help with many simples tasks, from content generation to text edition, moderation, and anything in between.
First, go to aifn.run and sign in to get an API KEY.
Next, just import the module via https in a project and start using it!
import ai from 'https://aifn.run/ai.mjs';
Create a function
Request:
{ "p": "Print a Lorem Ipsum paragraph with at most {length} words" }
Response:
{ "uid": "function-id" }
Update a function
Request:
{ "p": "Print a Lorem Ipsum paragraph with at most {length} words and only lowercase words" }
Get a Javascript module with the code to call a function
import loremIpsum from 'https://aifn.run/fn/[uid].js';
console.log(await loremIpsum({ length: 20 }));
Run a function using a function ID
Request:
{ "inputs": { "length": "20" } }
Response:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vitae sagittis lorem. Fusce auctor euismod arcu...
List all functions associated with an account (requires log in first)
The base URL used for AI requests can be changed by settings globalThis.aiBaseURL
to a server running aifn.