This is the official Inferable AI SDK for React. It is used to start and interact with Inferable runs from React applications.
It does not currently support registering functions as the backend SDKs do.
npm install @inferable/react
yarn add @inferable/react
pnpm add @inferable/react
More details on Inferable front-end usage can be found here.
The useRun
hook returns an object with the following properties:
{
client: ApiClient; // The underlying API client
createMessage: Function; // Function to add new messages to the run
messages: Message[]; // Array of all messages in the run
run?: Run; // Current run status and metadata
start: Function; // Function to start the run
}
It can be used to interact with an existing run by specifying the runId
:
const { messages, run, createMessage, start } = useRun({
clusterId: 'your-cluster-id',
customAuthToken: 'your-custom-auth-token',
// apiSecret: 'your-api-secret', // Not recommended
// pollInterval: 1000, // Optional: defaults to 1000ms
});
start({
runId: 'your-run-id',
})
It can be used to create a new run by specifying an initialPrompt
:
const { messages, run, createMessage, start } = useRun({
clusterId: 'your-cluster-id',
customAuthToken: 'your-custom-auth-token',
// apiSecret: 'your-api-secret', // Not recommended
// pollInterval: 1000, // Optional: defaults to 1000ms
});
start({
initialPrompt: 'Hello!',
})
You can add messages to the run by calling the createMessage
function:
// Optional: Send follow-up messages
await createMessage({
message: 'Hello!',
type: 'human'
});
You can handle errors by providing an onError
callback:
const { messages, run, createMessage } = useRun({
clusterId: 'your-cluster-id',
customAuthToken: 'your-custom-auth-token',
// apiSecret: 'your-api-secret', // Not recommended
configId: 'your-config-id',
onError: (error) => {
console.error('Run error:', error);
}
});
The hook polls for updates by default every 1000ms. You can customize this:
const { messages } = useRun({
// ... other options
pollInterval: 2000 // Poll every 2 seconds
});
There is development server included in the repository at ./demo
.
- Start the development server:
npm run dev
This will start a Vite dev server at http://localhost:3000 with the test page, which provides a simple interface to test the SDK's functionality.
- 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 React SDK are welcome. Please ensure that your code adheres to the existing style and includes appropriate tests.