0.1.2 • Published 6 months ago

@rightbrain/sdk v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

@rightbrain/sdk

Official TypeScript SDK for interacting with the RightBrain AI API.

Installation

npm install @rightbrain/sdk
or
yarn add @rightbrain/sdk
or
pnpm add @rightbrain/sdk

Usage

import { BrainClient } from "@rightbrain/sdk"

// Initialize the client
const client = new BrainClient({
  accessToken: "some-oauth-token or apikey",
  baseUrl: "https://api.rightbrain.ai",
  organizationId: "your-org-id",
  projectId: "your-project-id",
})

// List available models
const models = await client.listModels()

// Get model ID by name
const modelId = await client.getModelIdByName("gpt-4")

// Create a new task
const task = await client.createTask({
  name: "My Task",
  description: "Task description",
  system_prompt: "System prompt",
  user_prompt: "User prompt",
  llm_model_id: modelId, // Use UUID from listModels()
  output_format: { response: "string" },
  enabled: true,
  image_required: false,
})

// Run a task
const response = await client.runTask<InputType, OutputType>({
  id: "task-id",
  input: {
    // task input parameters
    prompt: "Analyze this image",
  },
  files: [file /*  File object */],
})

API Reference

BrainClient

The main client for interacting with the RightBrain API.

Methods

listModels

Returns a list of available LLM models.

listModels(): Promise<LLMModel[]>
getModelIdByName

Looks up a model ID by its name or alias.

getModelIdByName(modelName: string): Promise<string | null>
createTask

Creates a new task with the specified configuration.

createTask(taskData: TaskCreate): Promise<Task>

Constructor Options

OptionTypeDescription
accessTokenstringYour API access token
baseUrlstringThe base URL for the RightBrain API
organizationIdstringYour organization ID
projectIdstringYour project ID

Error Handling

The SDK includes a BrainClientError class for handling API errors:

try {
const response = await client.runTask({id: taskId, inputs: {/*...*/}})
} catch (error) {
if (error instanceof BrainClientError) {
console.error(API Error: ${error.message})
console.error(Status Code: ${error.statusCode})
}
}

TypeScript Support

TypeScript Support

The SDK is written in TypeScript and provides full type definitions. You can leverage type inference for both input and output types when using the methods.

Development

Install dependencies

pnpm install

Build the package

pnpm run build

Run tests

pnpm test

Run type checking

pnpm run type-check

License

MIT

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.8

8 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago