open-index/open-npm huggingface dataset:
npm package: @orka-js/replicate
Description: Replicate adapter for OrkaJS
Author: Orka AI
Latest version: 1.0.6

# @orka-js/replicate

Replicate adapter for OrkaJS — run any open-source model hosted on Replicate (Llama 2, SDXL, etc.).

## Installation

```bash
npm install @orka-js/replicate
```

## Quick Start

```typescript
import { ReplicateAdapter } from '@orka-js/replicate'
import { Orka } from '@orka-js/core'

const llm = new ReplicateAdapter({
  apiToken: process.env.REPLICATE_API_TOKEN!,
  model: 'meta/llama-2-70b-chat',
})

const orka = new Orka({ llm })

const response = await orka.chat([
  { role: 'user', content: 'Hello!' }
])
console.log(response.content)
```

## Streaming

```typescript
const stream = await llm.stream([
  { role: 'user', content: 'Write a haiku about the ocean' }
])

for await (const chunk of stream) {
  process.stdout.write(chunk.delta ?? '')
}
```

## Configuration

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `apiToken` | `string` | — | Replicate API token (required) |
| `model` | `string` | — | Model identifier (required), e.g. `'meta/llama-2-70b-chat'` |
| `temperature` | `number` | `0.7` | Sampling temperature |
| `maxTokens` | `number` | — | Max tokens in response |

## Supported Models

Any model available on [replicate.com](https://replicate.com/explore) that supports text generation. Common examples:

| Model | Description |
|-------|-------------|
| `meta/llama-2-70b-chat` | Meta Llama 2 70B |
| `mistralai/mistral-7b-instruct-v0.2` | Mistral 7B |
| Any Replicate model slug | Custom hosted models |

## API

### `ReplicateAdapter`

```typescript
const adapter = new ReplicateAdapter(config)

adapter.chat(messages: ChatMessage[])   // Promise<ChatResponse>
adapter.stream(messages: ChatMessage[]) // AsyncIterable<StreamEvent>
```

Implements: `LLMAdapter`, `StreamingLLMAdapter`

## Related Packages

- [`@orka-js/core`](../core) — Core types and `LLMAdapter` interface
- [`@orka-js/ollama`](../ollama) — Local models with Ollama
- [`orkajs`](../orkajs) — Full bundle
npm package: @orka-js/resilience
Description: Resilience patterns for OrkaJS - retry, fallback, resilient LLM
Author: Orka Team
Latest version: 1.0.8

# @orka-js/resilience

Resilience patterns for OrkaJS — retry, fallback, and token budget enforcement for LLM calls.

## Installation

```bash
npm install @orka-js/resilience
```

## Retry

```typescript
import { withRetry } from '@orka-js/resilience'

const result = await withRetry(
  () => llm.chat(messages),
  { maxRetries: 3, delay: 1000, backoff: 'exponential' }
)
```

## Fallback

```typescript
import { FallbackLLM } from '@orka-js/resilience'
import { OpenAIAdapter } from '@orka-js/openai'
import { AnthropicAdapter } from '@orka-js/anthropic'

const llm = new FallbackLLM([
  new OpenAIAdapter({ apiKey: process.env.OPENAI_API_KEY! }),
  new AnthropicAdapter({ apiKey: process.env.ANTHROPIC_API_KEY! }),
])

// Falls back to Anthropic if OpenAI fails
const response = await llm.chat(messages)
```

## Resilient LLM (Retry + Fallback)

```typescript
import { ResilientLLM } from '@orka-js/resilience'

const llm = new ResilientLLM(primaryLLM, {
  retry: { maxRetries: 2, delay: 500 },
  fallbacks: [fallbackLLM],
})
```

## Budget Enforcement

```typescript
import { BudgetedLLM } from '@orka-js/resilience'

const llm = new BudgetedLLM(baseLLM, {
  maxTokens: 100_000,  // hard token limit
  maxCost: 5.00,       // hard cost limit in USD
})

try {
  await llm.chat(messages)
} catch (err) {
  if (err instanceof BudgetExceededError) {
    console.log('Budget exceeded:', err.reason)
  }
}
```

## API

### `withRetry(fn, options)`

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `maxRetries` | `number` | `3` | Maximum retry attempts |
| `delay` | `number` | `1000` | Base delay in ms |
| `backoff` | `'linear' \| 'exponential'` | `'exponential'` | Delay strategy |

### `FallbackLLM`

```typescript
new FallbackLLM(llms: LLMAdapter[])
// Tries each adapter in order, returns first success
```

### `ResilientLLM`

```typescript
new ResilientLLM(primary: LLMAdapter, config: ResilientLLMConfig)
// Combines retry on primary + fallback to alternates
```

### `BudgetedLLM`

```typescript
new BudgetedLLM(llm: LLMAdapter, config: BudgetConfig)
// Throws BudgetExceededError when limits are hit
```

## Related Packages

- [`@orka-js/core`](../core) — Core types and `LLMAdapter` interface
- [`@orka-js/cache`](../cache) — LLM response caching
- [`@orka-js/orchestration`](../orchestration) — Multi-model routing and load balancing
- [`orkajs`](../orkajs) — Full bundle