vern-llm 1.7.1 → 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 CHANGED
@@ -13,7 +13,6 @@
13
13
  <p align="center">
14
14
  <a href="https://www.npmjs.com/package/vern-llm"><img src="https://img.shields.io/npm/v/vern-llm.svg" alt="npm version" /></a>
15
15
  <a href="https://www.npmjs.com/package/vern-llm"><img src="https://img.shields.io/npm/dm/vern-llm.svg" alt="npm downloads" /></a>
16
- <a href="https://bundlephobia.com/package/vern-llm"><img src="https://img.shields.io/bundlephobia/minzip/vern-llm.svg" alt="bundle size" /></a>
17
16
  <a href="https://github.com/LakBud/vernLLM/actions/workflows/test.yml"><img src="https://github.com/LakBud/vernLLM/actions/workflows/test.yml/badge.svg" alt="test status" /></a>
18
17
  <a href="https://github.com/LakBud/vernLLM/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/vern-llm.svg" alt="license" /></a>
19
18
  <img src="https://img.shields.io/node/v/vern-llm.svg" alt="node version" />
@@ -22,9 +21,9 @@
22
21
 
23
22
  <p align="center">Production-ready resilience for LLM calls</p>
24
23
 
25
- Retries, timeouts, caching, and circuit breaking behind one typed interface, with adapters for OpenAI-compatible APIs (OpenAI, Groq, and more), Anthropic, Gemini, and Bedrock.
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.
26
25
 
27
- **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.
28
27
 
29
28
  ## Install
30
29
 
@@ -35,8 +34,9 @@ pnpm add vern-llm
35
34
  ## Quick start
36
35
 
37
36
  ```ts
37
+ import Anthropic from '@anthropic-ai/sdk';
38
38
  import OpenAI from 'openai';
39
- import { VernLLM } from 'vern-llm';
39
+ import { fromAnthropic, VernLLM } from 'vern-llm';
40
40
 
41
41
  const llm = new VernLLM({
42
42
  client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
@@ -44,25 +44,57 @@ const llm = new VernLLM({
44
44
  maxRetries: 3,
45
45
  timeoutMs: 10_000,
46
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
+ },
47
56
  });
48
57
 
49
- const result = await llm.call({
50
- systemPrompt: 'Return JSON: { "skills": string[] }',
51
- userContent: 'Extract skills from: ...',
58
+ const getWeather = {
59
+ name: 'get_weather',
60
+ description: 'Gets the current weather for a city',
61
+ parameters: { type: 'object', properties: { city: { type: 'string' } }, required: ['city'] },
62
+ };
63
+
64
+ const { chunks, finalResult } = await llm.cachedCall({
65
+ cacheKey: 'weather-demo-001',
66
+ ttl: 60,
67
+ call: {
68
+ userContent: "What's the weather in New York?",
69
+ tools: [getWeather],
70
+ stream: true,
71
+ },
52
72
  });
73
+
74
+ for await (const chunk of chunks) {
75
+ if (chunk.type === 'text-delta') process.stdout.write(chunk.delta);
76
+ }
77
+
78
+ const result = await finalResult; // cached, retried, and streamed, tool calls included
53
79
  ```
54
80
 
55
81
  ## Why vern-llm?
56
82
 
57
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
58
86
  - **Structured output**: pass a Zod schema, get a typed, validated result back
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
88
+ - **Streaming**: set `stream: true` on any call and get live chunks alongside the same validated result the call would otherwise resolve to
59
89
  - **Provider-native JSON Schema mode**: constrain generation itself, not just validate after the fact
60
- - **Caching**: wrap any call with `cachedCall`/`cachedLLMCall`, bring your own cache adapter
61
- - **Circuit breaker**: trips after repeated failures, recovers automatically once the provider's back
90
+ - **Caching**: wrap any LLM call with `cachedCall`, bring your own cache adapter
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
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
62
94
  - **One interface, every provider**: OpenAI, Groq, Mistral, DeepSeek, Cerebras, Together, Fireworks, Ollama, Anthropic, Gemini, Bedrock, or raw HTTP via `fromFetch`
63
- - **Zero runtime dependencies**: `zod` and provider SDKs are not required dependencies; VernLLM relies on compatible interfaces rather than specific implementations.
95
+ - **Zero runtime dependencies**: `zod` and provider SDKs are not required dependencies; vern-llm relies on compatible interfaces rather than specific implementations.
64
96
 
65
- 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.
66
98
 
67
99
  ## License
68
100