Skip to content

Latest commit

 

History

History
140 lines (102 loc) · 3.23 KB

README.md

File metadata and controls

140 lines (102 loc) · 3.23 KB

Inferable Logo

Typescript SDK

npm version License: MIT Documentation Downloads

This is the official Inferable AI SDK for Typescript.

Installation

npm

npm install inferable

yarn

yarn add inferable

pnpm

pnpm add inferable

⚡️ Quick Start

Initialize Client

import { Inferable } from "inferable";

const inferable = new Inferable({
  // Get yours at https://app.inferable.ai
  apiSecret: ""
  // Optional, if self-hosting (https://docs.inferable.ai/pages/self-hosting)
  // baseUrl: "http://localhost:4000",
});

Register a Tool

Register a tool which is available for your agents to use.

ℹ️ This example demonstrates Node.js. Tools can also be written in Go or .NET.

inferable.tools.register({
  name: "greet",
  func: async (input) => {
    return `Hello, ${input.name}! My name is ${os.hostname()}.`;
  },
  schema: {
    input: z.object({
      name: z.string(),
    }),
  },
});

inferable.tools.listen();

Create a Workflow

Workflows are a way to orchestrate agents. They are durable, distributed, and run on the machine that they are registered on.

ℹ️ Workflow definitions can currently only be written in Node.js.

const workflow = inferable.workflows.create({
  name: "greeting",
  inputSchema: z.object({
    executionId: z.string(),
    userName: z.string(),
  }),
});

workflow.version(1).define(async (ctx, input) => {
  const greetingAgent = ctx.agent({
    name: "greeter",
    tools: ["greet"],
    systemPrompt: helpers.structuredPrompt({
      facts: ["You are a friendly greeter"],
      goals: ["Return a greeting to the user"]
    }),
    resultSchema: z.object({
      greeting: z.string(),
    }),
  });

  const result = await greetingAgent.trigger({
    data: {
      name: input.userName,
    }
  });

  console.log(result.result.greeting);
  // ... or chain this to anther ctx.agent()
});

workflow.listen();

Trigger the Workflow

Tgger the workflow from your application code or via a HTTP request.

await inferable.workflows.trigger('greeting', {
  executionId: `123`,
  userName: "Alice",
});
curl -XPOST https://api.inferable.ai/clusters/$CLUSTER_ID/workflows/greeting/executions \
  -d '{"executionId": "123", "userName": "Alice"}' \
  -H "Authorization: Bearer $API_SECRET"

Documentation

Support

For support or questions, please create an issue in the repository.

Contributing

Contributions to the Inferable NodeJs Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.