0.1.2 • Published 6 months ago
@rightbrain/sdk v0.1.2
@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/sdkUsage
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
| Option | Type | Description |
|---|---|---|
accessToken | string | Your API access token |
baseUrl | string | The base URL for the RightBrain API |
organizationId | string | Your organization ID |
projectId | string | Your 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 installBuild the package
pnpm run buildRun tests
pnpm testRun type checking
pnpm run type-checkLicense
MIT