WorkflowAI is a low-code tool for product managers and software engineers that makes it easier to ship features powered by AI.
- Go to workflowai.com.
- Enter your company URL, and get suggestions of AI-powered features for your product.
- Build your first AI features in a few minutes.
- Then go to the Code section to copy the code generated for Typescript.
// Initialize WorkflowAI Client
import { WorkflowAI } from '@workflowai/workflowai';
const workflowAI = new WorkflowAI({
// optional, defaults to process.env.WORKFLOWAI_API_KEY
// key: // Add your API key here
});
// Initialize Your AI agent
export interface GetCapitalInfoInput {
city: string;
}
export interface GetCapitalInfoOutput {
country: string;
capital: string;
fun_fact: string;
}
const getCapitalInfo = workflowAI.agent<
GetCapitalInfoInput,
GetCapitalInfoOutput
>({
id: 'get-capital-info',
schemaId: 1,
version: '1.4',
// Cache options:
// - "auto" (default): if a previous run exists with the same version and input, and if
// the temperature is 0, the cached output is returned
// - "always": the cached output is returned when available, regardless
// of the temperature value
// - "never": the cache is never used
useCache: 'auto',
});
// Run Your AI agent
async function getCapitalInfoRun() {
const input: GetCapitalInfoInput = {
city: 'Wellington',
};
try {
const {
output,
data: { duration_seconds, cost_usd, version },
} = await getCapitalInfo(input);
console.log(output);
console.log('\nModel: ', version?.properties?.model);
console.log('Cost: $', cost_usd);
console.log('Latency: ', duration_seconds?.toFixed(2), 's');
} catch (error) {
console.error('Failed to run :', error);
}
}