inferable
TypeScript icon, indicating that this package has built-in type declarations

0.30.58 • Public • Published

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

Initializing the Client

import { Inferable } from "inferable";

// Initialize the Inferable client with your API secret.
// Get yours at https://console.inferable.ai.
const client = new Inferable({
  apiSecret: "YOUR_API_SECRET",
});

If you don't provide an API key or base URL, it will attempt to read them from the following environment variables:

  • INFERABLE_API_SECRET
  • INFERABLE_API_ENDPOINT

Registering a Function

Register a "sayHello" function. This file will register the function with the control-plane.

// Register a simple function (using the 'default' service)
const sayHello = client.default.register({
  name: "sayHello",
  func: async (input: { to: string }, _context) => {
    return `Hello, ${to}!`;
  },
  schema: {
    input: z.object({
      to: z.string(),
    }),
  },
});

// Start the 'default' service
client.default.start();

Triggering a run

The following code will create an Inferable run with the prompt "Say hello to John" and the sayHello function attached.

You can inspect the progress of the run:

const run = await client.run({
  initialPrompt: "Say hello to John",
  // Optional: Explicitly attach the `sayHello` function (All functions attached by default)
  attachedFunctions: [
    {
      function: "sayHello",
      service: "default",
    },
  ],
  // Optional: Define a schema for the result to conform to
  resultSchema: z.object({
    didSayHello: z.boolean(),
  }),
  // Optional: Subscribe an Inferable function to receive notifications when the run status changes
  //onStatusChange: { function: { function: "handler", service: "default" } },
  // Optional: Pass additioanl context (passed to each function call)
  //context: { foo: "bar" },
});

console.log("Run Started", {
  result: run.id,
});

// Wait for the run to complete and log.
console.log("Run result", {
  result: await run.poll(),
});

Runs can also be triggered via the API, CLI or playground UI.

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.

Readme

Keywords

none

Package Sidebar

Install

npm i inferable

Weekly Downloads

750

Version

0.30.58

License

MIT

Unpacked Size

713 kB

Total Files

70

Last publish

Collaborators

  • ft4x
  • johnjcsmith