AI

Integrate generative AI into your applications.
Airplane's AI built-ins allow you to quickly integrate with LLMs (large language models) with minimal configuration. The Airplane SDKs provide a simple interface to send a message to an LLM, maintain a conversation with an AI assistant, or define an AI function to convert inputs to outputs by following a set of instructions.
See Building AI tasks for more information.

Chat

Send a single message to an LLM. Similar to calling the OpenAI completion endpoint or the Anthropic complete endpoint. If you would like to send multiple messages in a conversation, use ChatBot instead.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "company_tagline",
6
parameters: { description: "shorttext" },
7
envVars: { OPENAI_API_KEY: { config: "OPENAI_API_KEY" } },
8
},
9
async (params): string => {
10
const tagline = await airplane.ai.chat(
11
`Write a company tagline given this description: ${params.description}`,
12
);
13
return `Here's a tagline: ${tagline}`;
14
},
15
);
airplane.ai.chat(message, opts)
message
REQUIRED
string

The message to send to the LLM.

opts.model
optional
Default
"gpt-3.5-turbo" for OpenAI and "claude-v1" for Anthropic
string

The model to use.

opts.temperature
optional
Default
0
number

The temperature setting for the LLM. Defaults to 0. Lower temperatures will result in less variable output. Valid values are between 0 and 1.

Returns
string

The response from the LLM.

ChatBot

Facilitate a conversation with an LLM. You can create a ChatBot and send multiple messages — the conversation history is automatically included between messages. This allows you to have a conversation that builds context and allows you to refer to any previous messages.
The ChatBot optionally takes in instructions, which can inform the ChatBot on how to respond, what tone to use, any additional context it needs to converse, and more. For example:
  • Provide concise answers with less than 10 words
  • Be polite and always assume the customer is correct
  • Do not guess answers if you are unsure
  • If the customer doesn't ask a question, thank them and end the conversation
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "chat_bot",
6
envVars: { OPENAI_API_KEY: { config: "OPENAI_API_KEY" } },
7
},
8
async () => {
9
const bot = new airplane.ai.ChatBot();
10
console.log(await bot.chat("Name all of the planets in the solar system."));
11
console.log(await bot.chat("Which one is the farthest away?"));
12
},
13
);
airplane.ai.ChatBot(opts)
opts.instructions
optional
Default
""
string

Optional instructions to include for the LLM. Useful for providing additional context, guiding the tone of the response, shaping the output, and more.

opts.model
optional
Default
"gpt-3.5-turbo" for OpenAI and "claude-v1" for Anthropic
string

The model to use.

opts.temperature
optional
Default
0
number

The temperature setting for the LLM. Defaults to 0. Lower temperatures will result in less variable output. Valid values are between 0 and 1.


airplane.ai.ChatBot.chat(message)
message
REQUIRED
string

The message to send to the LLM.

Returns
string

The response from the LLM.

Func

Define a custom AI-powered function to transform data following a set of instructions. You can use Func to quickly build tools for data extraction, classification, summarization, and more.
You must provide at least one example of input and output data to assist the LLM. The function must be called with an input type that matches the provided examples and will generate an output type that matches the provided examples.
LLMs are probabilistic and can make errors. To help work with LLMs, the function output is returned with a confidence score between 0 and 1, with 0 being least confident and 1 being the most confident. You can use the confidence score to decide whether to ask for human confirmation or take automated action.
Func will attempt to parse the LLM output into a native data type matching your examples. If parsing fails, the raw string will still be returned with a confidence of 0.
typescript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "ai_func",
6
parameters: { word: "shorttext" },
7
envVars: { OPENAI_API_KEY: { config: "OPENAI_API_KEY" } },
8
},
9
async (params): string[] => {
10
const genSynonyms = airplane.ai.func("Provide synonyms for the provided input", [
11
{ input: "happy", output: ["content", "cheeful", "joyful"] },
12
{ input: "sad", output: ["unhappy", "downcast", "despondent"] },
13
]);
14
15
// Since the example outputs are an array of strings, the output will be an array of strings.
16
// Confidence will be a number between 0 and 1.
17
const { output, confidence } = await genSynonyms(params.word);
18
console.log(`Confidence score: ${confidence}`);
19
return output;
20
},
21
);
airplane.ai.func(instructions, examples, opts)
instructions
REQUIRED
string

Instructions on how to transform the function input into output.

examples
REQUIRED
{ input: any, output: any }[]

Examples that describe the appropriate output for a potential function input. Examples are used to help the LLM understand the expected behavior, as well as inform the LLM of the expected output format. Example inputs must be the same type and must match the input type when calling the function. Example outputs must be the same type and will match the type of the output when calling the function.

opts.model
optional
Default
"gpt-3.5-turbo" for OpenAI and "claude-v1" for Anthropic
string

The model to use.

opts.temperature
optional
Default
0
number

The temperature setting for the LLM. Defaults to 0. Lower temperatures will result in less variable output. Valid values are between 0 and 1.


airplane.ai.Func(input)
input
REQUIRED
any

The input to pass into the function.

Returns
output
any | string

The output of the function. If the output cannot be parsed into the correct type, the function will return the raw string output with a confidence of 0.

confidence
number

The LLM's confidence score for the output. This is a value between 0 and 1.