adk-llm-bridge 0.3.0 → 0.3.2
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 +212 -26
- package/dist/config.d.ts +4 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/core/base-provider-llm.d.ts +1 -1
- package/dist/core/base-provider-llm.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/openai-compatible-llm.d.ts +2 -2
- package/dist/core/openai-compatible-llm.d.ts.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -2
- package/dist/index.js.map +71 -12
- package/dist/providers/ai-gateway/ai-gateway-llm.d.ts +0 -7
- package/dist/providers/ai-gateway/ai-gateway-llm.d.ts.map +1 -1
- package/dist/providers/ai-gateway/factory.d.ts +1 -1
- package/dist/providers/ai-gateway/factory.d.ts.map +1 -1
- package/dist/providers/ai-gateway/index.d.ts +1 -1
- package/dist/providers/ai-gateway/index.d.ts.map +1 -1
- package/dist/providers/ai-gateway/register.d.ts.map +1 -1
- package/dist/providers/anthropic/anthropic-llm.d.ts +98 -0
- package/dist/providers/anthropic/anthropic-llm.d.ts.map +1 -0
- package/dist/providers/anthropic/constants.d.ts +34 -0
- package/dist/providers/anthropic/constants.d.ts.map +1 -0
- package/dist/providers/anthropic/converters/request.d.ts +51 -0
- package/dist/providers/anthropic/converters/request.d.ts.map +1 -0
- package/dist/providers/anthropic/converters/response.d.ts +63 -0
- package/dist/providers/anthropic/converters/response.d.ts.map +1 -0
- package/dist/providers/anthropic/factory.d.ts +60 -0
- package/dist/providers/anthropic/factory.d.ts.map +1 -0
- package/dist/providers/anthropic/index.d.ts +33 -0
- package/dist/providers/anthropic/index.d.ts.map +1 -0
- package/dist/providers/anthropic/register.d.ts +65 -0
- package/dist/providers/anthropic/register.d.ts.map +1 -0
- package/dist/providers/custom/custom-llm.d.ts +121 -0
- package/dist/providers/custom/custom-llm.d.ts.map +1 -0
- package/dist/providers/custom/factory.d.ts +145 -0
- package/dist/providers/custom/factory.d.ts.map +1 -0
- package/dist/providers/custom/index.d.ts +35 -0
- package/dist/providers/custom/index.d.ts.map +1 -0
- package/dist/providers/index.d.ts +17 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/openai/constants.d.ts +32 -0
- package/dist/providers/openai/constants.d.ts.map +1 -0
- package/dist/providers/openai/factory.d.ts +61 -0
- package/dist/providers/openai/factory.d.ts.map +1 -0
- package/dist/providers/openai/index.d.ts +29 -0
- package/dist/providers/openai/index.d.ts.map +1 -0
- package/dist/providers/openai/openai-llm.d.ts +69 -0
- package/dist/providers/openai/openai-llm.d.ts.map +1 -0
- package/dist/providers/openai/register.d.ts +65 -0
- package/dist/providers/openai/register.d.ts.map +1 -0
- package/dist/providers/openrouter/factory.d.ts +1 -1
- package/dist/providers/openrouter/factory.d.ts.map +1 -1
- package/dist/providers/openrouter/index.d.ts +2 -2
- package/dist/providers/openrouter/index.d.ts.map +1 -1
- package/dist/providers/openrouter/openrouter-llm.d.ts +0 -7
- package/dist/providers/openrouter/openrouter-llm.d.ts.map +1 -1
- package/dist/providers/openrouter/register.d.ts.map +1 -1
- package/dist/providers/xai/constants.d.ts +28 -0
- package/dist/providers/xai/constants.d.ts.map +1 -0
- package/dist/providers/xai/factory.d.ts +54 -0
- package/dist/providers/xai/factory.d.ts.map +1 -0
- package/dist/providers/xai/index.d.ts +29 -0
- package/dist/providers/xai/index.d.ts.map +1 -0
- package/dist/providers/xai/register.d.ts +64 -0
- package/dist/providers/xai/register.d.ts.map +1 -0
- package/dist/providers/xai/xai-llm.d.ts +66 -0
- package/dist/providers/xai/xai-llm.d.ts.map +1 -0
- package/dist/types.d.ts +249 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Google ADK TypeScript comes with built-in Gemini support. This lightweight bridg
|
|
|
11
11
|
|
|
12
12
|
### Key Benefits
|
|
13
13
|
|
|
14
|
-
- **Minimal** — ~
|
|
14
|
+
- **Minimal** — ~10KB bundle (~3KB gzipped), single dependency (`openai`)
|
|
15
15
|
- **Simple** — 3 lines to integrate any model
|
|
16
16
|
- **Secure** — No complex dependency tree, just the battle-tested OpenAI SDK
|
|
17
17
|
- **Compatible** — Works with any OpenAI-compatible API (AI Gateway, OpenRouter, etc.)
|
|
@@ -22,6 +22,10 @@ Google ADK TypeScript comes with built-in Gemini support. This lightweight bridg
|
|
|
22
22
|
|----------|--------|----------|
|
|
23
23
|
| **[Vercel AI Gateway](https://vercel.com/ai-gateway)** | 100+ models (Claude, GPT, Llama, Gemini, etc.) | Simple, fast |
|
|
24
24
|
| **[OpenRouter](https://openrouter.ai/)** | 100+ models | Provider routing, fallbacks, price optimization |
|
|
25
|
+
| **[OpenAI](https://openai.com/)** | GPT-4, o1, o3, etc. | Direct API access |
|
|
26
|
+
| **[Anthropic](https://anthropic.com/)** | Claude models | Direct API access |
|
|
27
|
+
| **[xAI](https://x.ai/)** | Grok models | Direct API access |
|
|
28
|
+
| **Custom (OpenAI-compatible)** | Any model | Ollama, vLLM, Azure OpenAI, LM Studio, etc. |
|
|
25
29
|
|
|
26
30
|
## How It Works
|
|
27
31
|
|
|
@@ -34,13 +38,21 @@ flowchart LR
|
|
|
34
38
|
subgraph adk-llm-bridge
|
|
35
39
|
B --> C[AIGatewayLlm]
|
|
36
40
|
B --> D[OpenRouterLlm]
|
|
41
|
+
B --> E[OpenAILlm]
|
|
42
|
+
B --> F[AnthropicLlm]
|
|
43
|
+
B --> G[XAILlm]
|
|
44
|
+
B --> H[CustomLlm]
|
|
37
45
|
end
|
|
38
46
|
|
|
39
|
-
C -->
|
|
40
|
-
D -->
|
|
47
|
+
C --> I[Vercel AI Gateway]
|
|
48
|
+
D --> J[OpenRouter]
|
|
49
|
+
E --> K[OpenAI API]
|
|
50
|
+
F --> L[Anthropic API]
|
|
51
|
+
G --> M[xAI API]
|
|
52
|
+
H --> N[Any OpenAI-compatible API]
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
I --> O[100+ Models]
|
|
55
|
+
J --> O
|
|
44
56
|
```
|
|
45
57
|
|
|
46
58
|
The package converts ADK's internal request format to OpenAI-compatible format, sends it through your chosen gateway, and converts the response back to ADK format.
|
|
@@ -71,7 +83,7 @@ LLMRegistry.register(AIGatewayLlm); // 2. Register
|
|
|
71
83
|
|
|
72
84
|
const agent = new LlmAgent({ // 3. Use any model
|
|
73
85
|
name: 'assistant',
|
|
74
|
-
model: 'anthropic/claude-sonnet-4
|
|
86
|
+
model: 'anthropic/claude-sonnet-4', // Claude, GPT, Llama, etc.
|
|
75
87
|
instruction: 'You are a helpful assistant.',
|
|
76
88
|
});
|
|
77
89
|
```
|
|
@@ -88,7 +100,54 @@ LLMRegistry.register(OpenRouterLlm);
|
|
|
88
100
|
|
|
89
101
|
const agent = new LlmAgent({
|
|
90
102
|
name: 'assistant',
|
|
91
|
-
model: 'anthropic/claude-sonnet-4
|
|
103
|
+
model: 'anthropic/claude-sonnet-4',
|
|
104
|
+
instruction: 'You are a helpful assistant.',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### With Direct Providers (OpenAI, Anthropic, xAI)
|
|
109
|
+
|
|
110
|
+
Use direct API access without a gateway:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { LlmAgent } from '@google/adk';
|
|
114
|
+
import { OpenAI, Anthropic, XAI } from 'adk-llm-bridge';
|
|
115
|
+
|
|
116
|
+
// OpenAI (uses OPENAI_API_KEY env var)
|
|
117
|
+
const openaiAgent = new LlmAgent({
|
|
118
|
+
name: 'assistant',
|
|
119
|
+
model: OpenAI('gpt-4.1'),
|
|
120
|
+
instruction: 'You are a helpful assistant.',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Anthropic (uses ANTHROPIC_API_KEY env var)
|
|
124
|
+
const claudeAgent = new LlmAgent({
|
|
125
|
+
name: 'assistant',
|
|
126
|
+
model: Anthropic('claude-sonnet-4-5'),
|
|
127
|
+
instruction: 'You are a helpful assistant.',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// xAI (uses XAI_API_KEY env var)
|
|
131
|
+
const grokAgent = new LlmAgent({
|
|
132
|
+
name: 'assistant',
|
|
133
|
+
model: XAI('grok-3'),
|
|
134
|
+
instruction: 'You are a helpful assistant.',
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### With Custom Provider (Ollama, vLLM, Azure, etc.)
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { LlmAgent } from '@google/adk';
|
|
142
|
+
import { createCustomLlm } from 'adk-llm-bridge';
|
|
143
|
+
|
|
144
|
+
const agent = new LlmAgent({
|
|
145
|
+
name: 'assistant',
|
|
146
|
+
model: createCustomLlm({
|
|
147
|
+
name: 'ollama',
|
|
148
|
+
model: 'llama3',
|
|
149
|
+
baseURL: 'http://localhost:11434/v1',
|
|
150
|
+
}),
|
|
92
151
|
instruction: 'You are a helpful assistant.',
|
|
93
152
|
});
|
|
94
153
|
```
|
|
@@ -110,10 +169,23 @@ OPENROUTER_SITE_URL=https://your-site.com # optional, for ranking
|
|
|
110
169
|
OPENROUTER_APP_NAME=Your App Name # optional, for ranking
|
|
111
170
|
```
|
|
112
171
|
|
|
172
|
+
**Direct Providers:**
|
|
173
|
+
```bash
|
|
174
|
+
OPENAI_API_KEY=your-openai-key
|
|
175
|
+
ANTHROPIC_API_KEY=your-anthropic-key
|
|
176
|
+
XAI_API_KEY=your-xai-key
|
|
177
|
+
```
|
|
178
|
+
|
|
113
179
|
### Programmatic Configuration
|
|
114
180
|
|
|
115
181
|
```typescript
|
|
116
|
-
import {
|
|
182
|
+
import {
|
|
183
|
+
registerAIGateway,
|
|
184
|
+
registerOpenRouter,
|
|
185
|
+
registerOpenAI,
|
|
186
|
+
registerAnthropic,
|
|
187
|
+
registerXAI,
|
|
188
|
+
} from 'adk-llm-bridge';
|
|
117
189
|
|
|
118
190
|
// AI Gateway
|
|
119
191
|
registerAIGateway({
|
|
@@ -127,25 +199,30 @@ registerOpenRouter({
|
|
|
127
199
|
siteUrl: 'https://your-site.com',
|
|
128
200
|
appName: 'Your App',
|
|
129
201
|
});
|
|
202
|
+
|
|
203
|
+
// Direct providers
|
|
204
|
+
registerOpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
205
|
+
registerAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
206
|
+
registerXAI({ apiKey: process.env.XAI_API_KEY });
|
|
130
207
|
```
|
|
131
208
|
|
|
132
209
|
### Factory Functions (Per-Agent Config)
|
|
133
210
|
|
|
134
211
|
```typescript
|
|
135
212
|
import { LlmAgent } from '@google/adk';
|
|
136
|
-
import { AIGateway, OpenRouter } from 'adk-llm-bridge';
|
|
213
|
+
import { AIGateway, OpenRouter, OpenAI, Anthropic, XAI, Custom } from 'adk-llm-bridge';
|
|
137
214
|
|
|
138
215
|
// AI Gateway
|
|
139
216
|
const agent1 = new LlmAgent({
|
|
140
217
|
name: 'assistant',
|
|
141
|
-
model: AIGateway('anthropic/claude-sonnet-4
|
|
218
|
+
model: AIGateway('anthropic/claude-sonnet-4', { timeout: 30000 }),
|
|
142
219
|
instruction: 'You are helpful.',
|
|
143
220
|
});
|
|
144
221
|
|
|
145
222
|
// OpenRouter with provider routing
|
|
146
223
|
const agent2 = new LlmAgent({
|
|
147
224
|
name: 'fast-assistant',
|
|
148
|
-
model: OpenRouter('anthropic/claude-sonnet-4
|
|
225
|
+
model: OpenRouter('anthropic/claude-sonnet-4', {
|
|
149
226
|
provider: {
|
|
150
227
|
sort: 'latency',
|
|
151
228
|
allow_fallbacks: true,
|
|
@@ -153,6 +230,32 @@ const agent2 = new LlmAgent({
|
|
|
153
230
|
}),
|
|
154
231
|
instruction: 'You are helpful.',
|
|
155
232
|
});
|
|
233
|
+
|
|
234
|
+
// Direct providers
|
|
235
|
+
const agent3 = new LlmAgent({
|
|
236
|
+
name: 'openai-assistant',
|
|
237
|
+
model: OpenAI('gpt-4.1'),
|
|
238
|
+
instruction: 'You are helpful.',
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const agent4 = new LlmAgent({
|
|
242
|
+
name: 'claude-assistant',
|
|
243
|
+
model: Anthropic('claude-sonnet-4-5', { maxTokens: 8192 }),
|
|
244
|
+
instruction: 'You are helpful.',
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const agent5 = new LlmAgent({
|
|
248
|
+
name: 'grok-assistant',
|
|
249
|
+
model: XAI('grok-3'),
|
|
250
|
+
instruction: 'You are helpful.',
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Custom provider (Ollama, vLLM, etc.)
|
|
254
|
+
const agent6 = new LlmAgent({
|
|
255
|
+
name: 'local-assistant',
|
|
256
|
+
model: Custom('llama3', { baseURL: 'http://localhost:11434/v1' }),
|
|
257
|
+
instruction: 'You are helpful.',
|
|
258
|
+
});
|
|
156
259
|
```
|
|
157
260
|
|
|
158
261
|
## OpenRouter Features
|
|
@@ -162,7 +265,7 @@ OpenRouter provides additional features not available in AI Gateway:
|
|
|
162
265
|
```typescript
|
|
163
266
|
import { OpenRouter } from 'adk-llm-bridge';
|
|
164
267
|
|
|
165
|
-
const llm = OpenRouter('anthropic/claude-sonnet-4
|
|
268
|
+
const llm = OpenRouter('anthropic/claude-sonnet-4', {
|
|
166
269
|
// Ranking headers (improves your rate limits)
|
|
167
270
|
siteUrl: 'https://your-site.com',
|
|
168
271
|
appName: 'Your App',
|
|
@@ -182,26 +285,26 @@ const llm = OpenRouter('anthropic/claude-sonnet-4.5', {
|
|
|
182
285
|
Use the `provider/model` format:
|
|
183
286
|
|
|
184
287
|
```
|
|
185
|
-
anthropic/claude-
|
|
186
|
-
openai/gpt-5
|
|
187
|
-
google/gemini-3-
|
|
188
|
-
meta/llama-
|
|
288
|
+
anthropic/claude-sonnet-4
|
|
289
|
+
openai/gpt-5
|
|
290
|
+
google/gemini-3-flash
|
|
291
|
+
meta/llama-4-maverick
|
|
189
292
|
mistral/mistral-large-3
|
|
190
293
|
xai/grok-4.1
|
|
191
|
-
deepseek/deepseek-
|
|
294
|
+
deepseek/deepseek-chat
|
|
192
295
|
```
|
|
193
296
|
|
|
194
297
|
### Popular Models
|
|
195
298
|
|
|
196
299
|
| Provider | Models |
|
|
197
300
|
|----------|--------|
|
|
198
|
-
| Anthropic | `anthropic/claude-sonnet-4
|
|
199
|
-
| OpenAI | `openai/gpt-5
|
|
200
|
-
| Google | `google/gemini-3-
|
|
201
|
-
| Meta | `meta/llama-
|
|
202
|
-
| Mistral | `mistral/mistral-large-3`, `mistral/
|
|
203
|
-
| xAI | `xai/grok-4.1`, `xai/grok-4
|
|
204
|
-
| DeepSeek | `deepseek/deepseek-
|
|
301
|
+
| Anthropic | `anthropic/claude-sonnet-4`, `anthropic/claude-opus-4.5` |
|
|
302
|
+
| OpenAI | `openai/gpt-5`, `openai/gpt-5-mini`, `openai/o3` |
|
|
303
|
+
| Google | `google/gemini-3-flash`, `google/gemini-3-pro`, `google/gemini-2.5-pro` |
|
|
304
|
+
| Meta | `meta/llama-4-maverick`, `meta/llama-4-scout`, `meta/llama-3.3-70b-instruct` |
|
|
305
|
+
| Mistral | `mistral/mistral-large-3`, `mistral/ministral-3-14b` |
|
|
306
|
+
| xAI | `xai/grok-4.1`, `xai/grok-4`, `xai/grok-3` |
|
|
307
|
+
| DeepSeek | `deepseek/deepseek-chat`, `deepseek/deepseek-reasoner` |
|
|
205
308
|
|
|
206
309
|
Browse all models:
|
|
207
310
|
- [Vercel AI Gateway Models](https://vercel.com/ai-gateway/models)
|
|
@@ -238,7 +341,7 @@ const getWeather = new FunctionTool({
|
|
|
238
341
|
|
|
239
342
|
const agent = new LlmAgent({
|
|
240
343
|
name: 'weather-assistant',
|
|
241
|
-
model: 'anthropic/claude-sonnet-4
|
|
344
|
+
model: 'anthropic/claude-sonnet-4',
|
|
242
345
|
instruction: 'You help users check the weather.',
|
|
243
346
|
tools: [getWeather],
|
|
244
347
|
});
|
|
@@ -259,7 +362,7 @@ LLMRegistry.register(OpenRouterLlm);
|
|
|
259
362
|
|
|
260
363
|
export const rootAgent = new LlmAgent({
|
|
261
364
|
name: 'assistant',
|
|
262
|
-
model: 'anthropic/claude-sonnet-4
|
|
365
|
+
model: 'anthropic/claude-sonnet-4',
|
|
263
366
|
instruction: 'You are helpful.',
|
|
264
367
|
});
|
|
265
368
|
```
|
|
@@ -277,6 +380,10 @@ bunx @google/adk-devtools web
|
|
|
277
380
|
|-------|-------------|
|
|
278
381
|
| `AIGatewayLlm` | LLM class for Vercel AI Gateway |
|
|
279
382
|
| `OpenRouterLlm` | LLM class for OpenRouter |
|
|
383
|
+
| `OpenAILlm` | LLM class for OpenAI API (gpt-*, o1-*, o3-*) |
|
|
384
|
+
| `AnthropicLlm` | LLM class for Anthropic API (claude-*) |
|
|
385
|
+
| `XAILlm` | LLM class for xAI API (grok-*) |
|
|
386
|
+
| `CustomLlm` | LLM class for any compatible API |
|
|
280
387
|
|
|
281
388
|
### Factory Functions
|
|
282
389
|
|
|
@@ -284,6 +391,11 @@ bunx @google/adk-devtools web
|
|
|
284
391
|
|----------|-------------|
|
|
285
392
|
| `AIGateway(model, options?)` | Create AI Gateway LLM instance |
|
|
286
393
|
| `OpenRouter(model, options?)` | Create OpenRouter LLM instance |
|
|
394
|
+
| `OpenAI(model, options?)` | Create OpenAI LLM instance |
|
|
395
|
+
| `Anthropic(model, options?)` | Create Anthropic LLM instance |
|
|
396
|
+
| `XAI(model, options?)` | Create xAI LLM instance |
|
|
397
|
+
| `createCustomLlm(config)` | Create custom LLM instance |
|
|
398
|
+
| `Custom(model, options)` | Shorthand for `createCustomLlm` |
|
|
287
399
|
|
|
288
400
|
### Registration Functions
|
|
289
401
|
|
|
@@ -291,6 +403,9 @@ bunx @google/adk-devtools web
|
|
|
291
403
|
|----------|-------------|
|
|
292
404
|
| `registerAIGateway(options?)` | Register AIGatewayLlm with LLMRegistry |
|
|
293
405
|
| `registerOpenRouter(options?)` | Register OpenRouterLlm with LLMRegistry |
|
|
406
|
+
| `registerOpenAI(options?)` | Register OpenAILlm with LLMRegistry |
|
|
407
|
+
| `registerAnthropic(options?)` | Register AnthropicLlm with LLMRegistry |
|
|
408
|
+
| `registerXAI(options?)` | Register XAILlm with LLMRegistry |
|
|
294
409
|
|
|
295
410
|
### Configuration Options
|
|
296
411
|
|
|
@@ -315,6 +430,77 @@ bunx @google/adk-devtools web
|
|
|
315
430
|
| `timeout` | `number` | `60000` | Request timeout (ms) |
|
|
316
431
|
| `maxRetries` | `number` | `2` | Max retry attempts |
|
|
317
432
|
|
|
433
|
+
**OpenAI / OpenAILlm:**
|
|
434
|
+
|
|
435
|
+
| Option | Type | Default | Description |
|
|
436
|
+
|--------|------|---------|-------------|
|
|
437
|
+
| `apiKey` | `string` | `process.env.OPENAI_API_KEY` | API key |
|
|
438
|
+
| `organization` | `string` | `process.env.OPENAI_ORGANIZATION` | Organization ID |
|
|
439
|
+
| `project` | `string` | `process.env.OPENAI_PROJECT` | Project ID |
|
|
440
|
+
| `timeout` | `number` | `60000` | Request timeout (ms) |
|
|
441
|
+
| `maxRetries` | `number` | `2` | Max retry attempts |
|
|
442
|
+
|
|
443
|
+
**Anthropic / AnthropicLlm:**
|
|
444
|
+
|
|
445
|
+
| Option | Type | Default | Description |
|
|
446
|
+
|--------|------|---------|-------------|
|
|
447
|
+
| `apiKey` | `string` | `process.env.ANTHROPIC_API_KEY` | API key |
|
|
448
|
+
| `maxTokens` | `number` | `4096` | Max tokens in response |
|
|
449
|
+
| `timeout` | `number` | `60000` | Request timeout (ms) |
|
|
450
|
+
| `maxRetries` | `number` | `2` | Max retry attempts |
|
|
451
|
+
|
|
452
|
+
**XAI / XAILlm:**
|
|
453
|
+
|
|
454
|
+
| Option | Type | Default | Description |
|
|
455
|
+
|--------|------|---------|-------------|
|
|
456
|
+
| `apiKey` | `string` | `process.env.XAI_API_KEY` | API key |
|
|
457
|
+
| `timeout` | `number` | `60000` | Request timeout (ms) |
|
|
458
|
+
| `maxRetries` | `number` | `2` | Max retry attempts |
|
|
459
|
+
|
|
460
|
+
**createCustomLlm / Custom:**
|
|
461
|
+
|
|
462
|
+
| Option | Type | Default | Description |
|
|
463
|
+
|--------|------|---------|-------------|
|
|
464
|
+
| `model` | `string` | - | Model name (required) |
|
|
465
|
+
| `baseURL` | `string` | - | API base URL (required) |
|
|
466
|
+
| `name` | `string` | `"custom"` | Provider name for logs/errors |
|
|
467
|
+
| `apiKey` | `string` | - | API key for authentication |
|
|
468
|
+
| `headers` | `Record<string, string>` | - | Additional HTTP headers |
|
|
469
|
+
| `queryParams` | `Record<string, string>` | - | Query parameters for all requests |
|
|
470
|
+
| `providerOptions` | `Record<string, unknown>` | - | Additional options for request body |
|
|
471
|
+
| `timeout` | `number` | `60000` | Request timeout (ms) |
|
|
472
|
+
| `maxRetries` | `number` | `2` | Max retry attempts |
|
|
473
|
+
|
|
474
|
+
### Custom Provider Examples
|
|
475
|
+
|
|
476
|
+
**Ollama (local):**
|
|
477
|
+
```typescript
|
|
478
|
+
const llm = createCustomLlm({
|
|
479
|
+
name: 'ollama',
|
|
480
|
+
baseURL: 'http://localhost:11434/v1',
|
|
481
|
+
model: 'llama3',
|
|
482
|
+
});
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
**Azure OpenAI:**
|
|
486
|
+
```typescript
|
|
487
|
+
const llm = createCustomLlm({
|
|
488
|
+
name: 'azure',
|
|
489
|
+
baseURL: 'https://{resource}.openai.azure.com/openai/deployments/{deployment}',
|
|
490
|
+
model: 'gpt-4',
|
|
491
|
+
headers: { 'api-key': process.env.AZURE_API_KEY },
|
|
492
|
+
queryParams: { 'api-version': '2024-02-01' },
|
|
493
|
+
});
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**vLLM / LM Studio:**
|
|
497
|
+
```typescript
|
|
498
|
+
const llm = createCustomLlm({
|
|
499
|
+
baseURL: 'http://localhost:8000/v1',
|
|
500
|
+
model: 'meta-llama/Llama-3-8b',
|
|
501
|
+
});
|
|
502
|
+
```
|
|
503
|
+
|
|
318
504
|
## Examples
|
|
319
505
|
|
|
320
506
|
See the [examples](./examples) directory:
|
package/dist/config.d.ts
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* });
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
import type {
|
|
37
|
+
import type { AnthropicRegisterOptions, OpenAIRegisterOptions, OpenRouterRegisterOptions, RegisterOptions, XAIRegisterOptions } from "./types";
|
|
38
38
|
/**
|
|
39
39
|
* Mapping of provider identifiers to their configuration types.
|
|
40
40
|
*
|
|
@@ -43,6 +43,9 @@ import type { RegisterOptions, OpenRouterRegisterOptions } from "./types";
|
|
|
43
43
|
type ProviderConfigMap = {
|
|
44
44
|
"ai-gateway": RegisterOptions;
|
|
45
45
|
openrouter: OpenRouterRegisterOptions;
|
|
46
|
+
openai: OpenAIRegisterOptions;
|
|
47
|
+
xai: XAIRegisterOptions;
|
|
48
|
+
anthropic: AnthropicRegisterOptions;
|
|
46
49
|
};
|
|
47
50
|
/**
|
|
48
51
|
* Valid provider type identifiers.
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,eAAe,CAAC;IAC9B,UAAU,EAAE,yBAAyB,CAAC;IACtC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,GAAG,EAAE,kBAAkB,CAAC;IACxB,SAAS,EAAE,wBAAwB,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,KAAK,YAAY,GAAG,MAAM,iBAAiB,CAAC;AAU5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,YAAY,EACtD,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,IAAI,CAEN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,YAAY,EACtD,QAAQ,EAAE,CAAC,GACV,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAE5C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAEhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAItC;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAExD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI,QAAQ,CAAC,eAAe,CAAC,CAErD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module core/base-provider-llm
|
|
13
13
|
*/
|
|
14
|
+
import type { BaseLlmConnection, LlmRequest, LlmResponse } from "@google/adk";
|
|
14
15
|
import { BaseLlm } from "@google/adk";
|
|
15
|
-
import type { LlmRequest, LlmResponse, BaseLlmConnection } from "@google/adk";
|
|
16
16
|
import type { BaseProviderConfig } from "../types";
|
|
17
17
|
declare const BASE_MODEL_SYMBOL: unique symbol;
|
|
18
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-provider-llm.d.ts","sourceRoot":"","sources":["../../src/core/base-provider-llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"base-provider-llm.d.ts","sourceRoot":"","sources":["../../src/core/base-provider-llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKnD,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,8BAAsB,eAAgB,SAAQ,OAAO;IAEnD,SAAiB,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC;IAE3C;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAE9C;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;IAKtC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,oBAAoB,CAC3B,UAAU,EAAE,UAAU,EACtB,MAAM,CAAC,EAAE,OAAO,GACf,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC;IAEpC;;;;;;;;;OASG;IACG,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAMxD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;CAe3E"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export { BaseProviderLlm } from "./base-provider-llm";
|
|
39
|
-
export { OpenAICompatibleLlm } from "./openai-compatible-llm";
|
|
40
39
|
export type { OpenAIClientConfig } from "./openai-compatible-llm";
|
|
40
|
+
export { OpenAICompatibleLlm } from "./openai-compatible-llm";
|
|
41
41
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module core/openai-compatible-llm
|
|
13
13
|
*/
|
|
14
|
-
import OpenAI from "openai";
|
|
15
14
|
import type { LlmRequest, LlmResponse } from "@google/adk";
|
|
16
|
-
import
|
|
15
|
+
import OpenAI from "openai";
|
|
17
16
|
import type { BaseProviderConfig } from "../types";
|
|
17
|
+
import { BaseProviderLlm } from "./base-provider-llm";
|
|
18
18
|
/**
|
|
19
19
|
* Configuration for the underlying OpenAI client.
|
|
20
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-compatible-llm.d.ts","sourceRoot":"","sources":["../../src/core/openai-compatible-llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"openai-compatible-llm.d.ts","sourceRoot":"","sources":["../../src/core/openai-compatible-llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,8BAAsB,mBAAoB,SAAQ,eAAe;IAC/D;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAElC;;;;;OAKG;gBACS,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB;IAWxE;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,MAAM;IAE3C;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,yBAAyB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI9D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACI,oBAAoB,CACzB,UAAU,EAAE,UAAU,EACtB,MAAM,UAAQ,GACb,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC;IAcpC;;;;;;;;OAQG;YACW,cAAc;IAa5B;;;;;;;;OAQG;YACY,cAAc;CAoB9B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
* @see {@link https://google.github.io/adk-docs/|Google ADK Documentation}
|
|
59
59
|
*/
|
|
60
60
|
export { BaseProviderLlm } from "./core/base-provider-llm";
|
|
61
|
-
export { OpenAICompatibleLlm } from "./core/openai-compatible-llm";
|
|
62
61
|
export type { OpenAIClientConfig } from "./core/openai-compatible-llm";
|
|
63
|
-
export {
|
|
64
|
-
export { AIGateway } from "./providers/ai-gateway";
|
|
65
|
-
export {
|
|
66
|
-
export {
|
|
67
|
-
export {
|
|
68
|
-
export {
|
|
69
|
-
export
|
|
70
|
-
export {
|
|
71
|
-
export {
|
|
62
|
+
export { OpenAICompatibleLlm } from "./core/openai-compatible-llm";
|
|
63
|
+
export { AIGateway, AIGatewayLlm, isAIGatewayRegistered, registerAIGateway, } from "./providers/ai-gateway";
|
|
64
|
+
export { isOpenRouterRegistered, OpenRouter, OpenRouterLlm, registerOpenRouter, } from "./providers/openrouter";
|
|
65
|
+
export { isOpenAIRegistered, OpenAI, OpenAILlm, registerOpenAI, } from "./providers/openai";
|
|
66
|
+
export { isXAIRegistered, registerXAI, XAI, XAILlm } from "./providers/xai";
|
|
67
|
+
export { Anthropic, AnthropicLlm, isAnthropicRegistered, registerAnthropic, } from "./providers/anthropic";
|
|
68
|
+
export { Custom, CustomLlm, type CustomLlmProviderConfig, createCustomLlm, } from "./providers/custom";
|
|
69
|
+
export type { AIGatewayConfig, AnthropicProviderConfig, AnthropicRegisterOptions, BaseProviderConfig, CustomLlmConfig, OpenAIProviderConfig, OpenAIRegisterOptions, OpenRouterConfig, OpenRouterProviderPreferences, OpenRouterRegisterOptions, RegisterOptions, StreamAccumulator, StreamChunkResult, ToolCallAccumulator, XAIProviderConfig, XAIRegisterOptions, } from "./types";
|
|
70
|
+
export { DEFAULT_BASE_URL, MODEL_PATTERNS, OPENROUTER_BASE_URL, OPENROUTER_MODEL_PATTERNS, PROVIDER_IDS, } from "./constants";
|
|
71
|
+
export { getConfig, getProviderConfig, resetAllConfigs, resetConfig, resetProviderConfig, setConfig, setProviderConfig, } from "./config";
|
|
72
72
|
export { convertRequest } from "./converters/request";
|
|
73
73
|
export { convertResponse, convertStreamChunk, createStreamAccumulator, } from "./converters/response";
|
|
74
74
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAMnE,OAAO,EACL,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,SAAS,EACT,cAAc,GACf,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM5E,OAAO,EACL,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACL,MAAM,EACN,SAAS,EACT,KAAK,uBAAuB,EAC5B,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAM5B,YAAY,EAEV,eAAe,EAEf,uBAAuB,EACvB,wBAAwB,EAExB,kBAAkB,EAElB,eAAe,EAEf,oBAAoB,EACpB,qBAAqB,EAErB,gBAAgB,EAChB,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAEjB,mBAAmB,EAEnB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,YAAY,GACb,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,mBAAmB,EAEnB,SAAS,EAET,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAMlB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC"}
|