vern-llm 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/index.cjs +2022 -1068
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +682 -270
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +682 -270
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2019 -1069
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
<p align="center">Production-ready resilience for LLM calls</p>
|
|
23
23
|
|
|
24
|
-
Retries, timeouts, caching,
|
|
24
|
+
Retries, timeouts, caching, circuit breaking, provider fallback, and client-side rate limiting behind one typed interface, with adapters for OpenAI-compatible APIs (OpenAI, Groq, and more), Anthropic, Gemini, and Bedrock.
|
|
25
25
|
|
|
26
|
-
**Full documentation: [vernllm.vercel.app](https://vernllm.vercel.app)** — installation, structured output, caching, circuit breaker, every adapter, and the complete API reference all live there and are kept up to date. This README is a quick pitch, not the manual.
|
|
26
|
+
**Full documentation: [vernllm.vercel.app](https://vernllm.vercel.app)** — installation, structured output, caching, circuit breaker, provider fallback, rate limiting, observability, every adapter, and the complete API reference all live there and are kept up to date. This README is a quick pitch, not the manual.
|
|
27
27
|
|
|
28
28
|
## Install
|
|
29
29
|
|
|
@@ -34,8 +34,9 @@ pnpm add vern-llm
|
|
|
34
34
|
## Quick start
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
37
38
|
import OpenAI from 'openai';
|
|
38
|
-
import { VernLLM } from 'vern-llm';
|
|
39
|
+
import { fromAnthropic, VernLLM } from 'vern-llm';
|
|
39
40
|
|
|
40
41
|
const llm = new VernLLM({
|
|
41
42
|
client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
|
|
@@ -43,6 +44,15 @@ const llm = new VernLLM({
|
|
|
43
44
|
maxRetries: 3,
|
|
44
45
|
timeoutMs: 10_000,
|
|
45
46
|
circuitBreaker: true,
|
|
47
|
+
rateLimit: { requestsPerMinute: 500, maxConcurrent: 20 },
|
|
48
|
+
fallback: {
|
|
49
|
+
client: fromAnthropic(new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })),
|
|
50
|
+
model: 'claude-sonnet-5',
|
|
51
|
+
circuitBreaker: true,
|
|
52
|
+
},
|
|
53
|
+
onEvent: (event) => {
|
|
54
|
+
if (event.kind === 'fallback') console.warn(`falling over ${event.from} -> ${event.to}`);
|
|
55
|
+
},
|
|
46
56
|
});
|
|
47
57
|
|
|
48
58
|
const getWeather = {
|
|
@@ -71,17 +81,20 @@ const result = await finalResult; // cached, retried, and streamed, tool calls i
|
|
|
71
81
|
## Why vern-llm?
|
|
72
82
|
|
|
73
83
|
- **Retries with backoff**: transient failures retry automatically; validation errors and non-retryable status codes fail fast instead
|
|
84
|
+
- **Provider fallback**: declare an ordered list of backup targets, tried in order after the primary, with no scoring or health-checking, `fallback` on the same constructor
|
|
85
|
+
- **Client-side rate limiting**: queue locally against requests-per-minute, tokens-per-minute, and concurrency ceilings instead of letting the provider reject the call
|
|
74
86
|
- **Structured output**: pass a Zod schema, get a typed, validated result back
|
|
75
87
|
- **Tool calling**: pass `tools`, vern-llm handles retries and validation around them the same as any other call; you run the tools and continue the conversation
|
|
76
88
|
- **Streaming**: set `stream: true` on any call and get live chunks alongside the same validated result the call would otherwise resolve to
|
|
77
89
|
- **Provider-native JSON Schema mode**: constrain generation itself, not just validate after the fact
|
|
78
90
|
- **Caching**: wrap any LLM call with `cachedCall`, bring your own cache adapter
|
|
79
|
-
- **Circuit breaker**: trips after repeated failures, recovers automatically once the provider's back
|
|
91
|
+
- **Circuit breaker**: trips after repeated failures, recovers automatically once the provider's back, independent per fallback target too
|
|
92
|
+
- **Observability**: one `onEvent` stream reports retries, fallovers, circuit transitions, and rate-limit waits
|
|
80
93
|
- **Usage tracking**: `onUsage` and `onUsageFailure` report token spend on success and on failure, so nothing goes unaccounted for when a call fails after the provider already responded
|
|
81
94
|
- **One interface, every provider**: OpenAI, Groq, Mistral, DeepSeek, Cerebras, Together, Fireworks, Ollama, Anthropic, Gemini, Bedrock, or raw HTTP via `fromFetch`
|
|
82
95
|
- **Zero runtime dependencies**: `zod` and provider SDKs are not required dependencies; vern-llm relies on compatible interfaces rather than specific implementations.
|
|
83
96
|
|
|
84
|
-
See the [docs](https://vernllm.vercel.app) for adapter setup, caching, the circuit breaker, and structured output in depth.
|
|
97
|
+
See the [docs](https://vernllm.vercel.app) for adapter setup, caching, the circuit breaker, provider fallback, rate limiting, and structured output in depth.
|
|
85
98
|
|
|
86
99
|
## License
|
|
87
100
|
|