Skip to content

aifn-run/aifn-run

Repository files navigation

AI as a function

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"

Motivation

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.

Usage

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';

API

POST /fn

Create a function

Request:

{ "p": "Print a Lorem Ipsum paragraph with at most {length} words" }

Response:

{ "uid": "function-id" }

PUT /fn/:uid

Update a function

Request:

{ "p": "Print a Lorem Ipsum paragraph with at most {length} words and only lowercase words" }

GET /fn/:uid.js

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 }));

POST /run/[uid]

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...

GET /fn

List all functions associated with an account (requires log in first)

Configuration

The base URL used for AI requests can be changed by settings globalThis.aiBaseURL to a server running aifn.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published