Skip to content

Commit

Permalink
docs: Add react to readme (#84)
Browse files Browse the repository at this point in the history
* docs: Add react to readme

* docs: Update react readme
  • Loading branch information
johnjcsmith authored Nov 11, 2024
1 parent 328cd92 commit 6925b5a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
50 changes: 38 additions & 12 deletions sdk-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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!',
Expand All @@ -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
Expand Down

0 comments on commit 6925b5a

Please sign in to comment.