From 6925b5af9671e4f952594c84452099cfc2aff608 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 11 Nov 2024 17:27:52 +1030 Subject: [PATCH] docs: Add react to readme (#84) * docs: Add react to readme * docs: Update react readme --- README.md | 10 +++++---- sdk-react/README.md | 50 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 484ad0f1..c8866d12 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Inferable is a developer platform that makes it easy to build and deploy reliabl - [Node.js / TypeScript SDK](./sdk-node/README.md) - [Go SDK](./sdk-go/README.md) - [.NET SDK](./sdk-dotnet/README.md) +- [React SDK](./sdk-react/README.md) Each SDK directory contains its own README with specific installation instructions, quick start guide, and usage examples. @@ -43,15 +44,16 @@ For language-specific quick start guides, please refer to the README in each SDK - [Node.js / TypeScript Quick Start](./sdk-node/README.md#quick-start) - [Go Quick Start](./sdk-go/README.md#quick-start) - [.NET Quick Start](./sdk-dotnet/README.md#quick-start) +- [React Quick Start](./sdk-react/README.md#quick-start) ## Feature Comparison ### Core Features -| Feature | Node.js | Go | .NET | -| --------------------------------------------------------------- | :-----: | :-: | :--: | -| Register [Functions](https://docs.inferable.ai/pages/functions) | ✅ | ✅ | ✅ | -| Create [Runs](https://docs.inferable.ai/pages/runs) | ✅ | ✅ | ✅ | +| Feature | Node.js | Go | .NET | React | +| --------------------------------------------------------------- | :-----: | :-: | :--: | :---: | +| Register [Functions](https://docs.inferable.ai/pages/functions) | ✅ | ✅ | ✅ | ❌ | +| Create [Runs](https://docs.inferable.ai/pages/runs) | ✅ | ✅ | ✅ | ✅ | ### Advanced Features diff --git a/sdk-react/README.md b/sdk-react/README.md index 7aa9c531..3b56e2af 100644 --- a/sdk-react/README.md +++ b/sdk-react/README.md @@ -9,6 +9,9 @@ [![Documentation](https://img.shields.io/badge/docs-inferable.ai-brightgreen)](https://docs.inferable.ai/) This is the official Inferable AI SDK for React. +It is used to start and interact with [Inferable runs](https://docs.inferable.ai/pages/runs) from React applications. + +It does **not** currently support [registering functions](https://docs.inferable.ai/pages/functions) as the backend SDKs do. ## Installation @@ -24,33 +27,58 @@ yarn add @inferable/react pnpm add @inferable/react ``` -## Usage +## Quick Start ### useRun Hook The `useRun` hook provides real-time interaction with an Inferable run: + +#### Existing Runs +It can be used to interact with an existing run by specifying the `runId`: +```typescript +const { messages, run, createMessage, start } = useRun({ + clusterId: 'your-cluster-id', + customerProvidedSecret: 'your-customer-provided-secret', + runId: 'your-run-id', + // pollInterval: 1000, // Optional: defaults to 1000ms +}); +``` + + +#### New Runs + +It can be used to create a new run by specifying a `configId`: + ```typescript const { messages, run, createMessage, start } = useRun({ clusterId: 'your-cluster-id', customerProvidedSecret: 'your-customer-provided-secret', - // apiSecret: 'your-api-secret', // Not recomended for frontend usage - // Existing Run: - // runId: 'your-run-id', - // New (From Run Config): - // initialMessage: 'Hello!', - // configId: 'your-run-config-id', - // configInput: {} //optional if `initialPrompt` is not provided, + initialMessage: 'Hello!', + configId: 'your-run-config-id', + // configInput: {} // Optional: if the config has an inputSchema // pollInterval: 1000, // Optional: defaults to 1000ms }); +``` -// start() +#### Start + +Once the hook is initialized, you can start the run by calling the `start` function: + +``` +start() // Access messages and run state console.log(messages); // Array of messages in the run console.log(run); // Current run status and metadata +``` + + +#### Adding Messages +You can add messages to the run by calling the `createMessage` function: +``` // Optional: Send follow-up messages await createMessage({ message: 'Hello!', @@ -59,11 +87,9 @@ await createMessage({ ``` -The hook automatically polls for updates to messages and run state at the specified interval. - ## Local Development -To test the SDK locally: +There is development server included in the repository at `./test-page`. 1. Start the development server: ```bash