@workflowai/workflowai
TypeScript icon, indicating that this package has built-in type declarations

1.6.7 • Public • Published

Javascript / Typescript SDK for WorkflowAI

WorkflowAI

npm version License: Apache 2.0

WorkflowAI

WorkflowAI is a low-code tool for product managers and software engineers that makes it easier to ship features powered by AI.

Get Started

  1. Go to workflowai.com.
  2. Enter your company URL, and get suggestions of AI-powered features for your product.
  3. Build your first AI features in a few minutes.
  4. Then go to the Code section to copy the code generated for Typescript.

Code Section

Example Syntax

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

/@workflowai/workflowai/

    Package Sidebar

    Install

    npm i @workflowai/workflowai

    Weekly Downloads

    1,038

    Version

    1.6.7

    License

    none

    Unpacked Size

    1.17 MB

    Total Files

    35

    Last publish

    Collaborators

    • gui-workflowai
    • pvalade