This is the official Inferable AI SDK for Typescript.
npm install inferable
yarn add inferable
pnpm add inferable
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
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();
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:
- in the playground UI via
inf app
- in the CLI via
inf runs list
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.
- Inferable documentation contains all the information you need to get started with Inferable.
For support or questions, please create an issue in the repository.
Contributions to the Inferable NodeJs Client are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.