@jambonz/llm 0.3.4 → 0.4.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.
@@ -1,4 +1,4 @@
1
- import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-4d2QrlAe.cjs';
1
+ import { b as AdapterFactory, e as AuthKind, A as AuthSpec, L as LlmAdapter, d as ApiKeyAuth, h as ClientOptions, P as PromptRequest, m as LlmEvent, M as Message, p as ToolCallEvent, o as ModelInfo, c as AdapterManifest } from '../types-DxknK0Rc.cjs';
2
2
 
3
3
  /**
4
4
  * Named scenarios the harness must be able to stage. Each scenario configures
@@ -1,4 +1,4 @@
1
- import { a as AdapterFactory, d as AuthKind, A as AuthSpec, L as LlmAdapter, c as ApiKeyAuth, g as ClientOptions, P as PromptRequest, l as LlmEvent, M as Message, o as ToolCallEvent, n as ModelInfo, b as AdapterManifest } from '../types-4d2QrlAe.js';
1
+ import { b as AdapterFactory, e as AuthKind, A as AuthSpec, L as LlmAdapter, d as ApiKeyAuth, h as ClientOptions, P as PromptRequest, m as LlmEvent, M as Message, p as ToolCallEvent, o as ModelInfo, c as AdapterManifest } from '../types-DxknK0Rc.js';
2
2
 
3
3
  /**
4
4
  * Named scenarios the harness must be able to stage. Each scenario configures
@@ -2225,6 +2225,205 @@ var bedrockFactory = {
2225
2225
  create: () => new BedrockAdapter()
2226
2226
  };
2227
2227
 
2228
+ // src/adapters/azure-openai/adapter.ts
2229
+ import { AzureOpenAI } from "openai";
2230
+
2231
+ // src/adapters/azure-openai/manifest.ts
2232
+ var AZURE_OPENAI_KNOWN_MODELS = [
2233
+ {
2234
+ id: "gpt-4o",
2235
+ displayName: "GPT-4o (on Azure)",
2236
+ capabilities: {
2237
+ streaming: true,
2238
+ tools: true,
2239
+ vision: true,
2240
+ systemPrompt: true,
2241
+ maxContextTokens: 128e3
2242
+ }
2243
+ },
2244
+ {
2245
+ id: "gpt-4o-mini",
2246
+ displayName: "GPT-4o mini (on Azure)",
2247
+ capabilities: {
2248
+ streaming: true,
2249
+ tools: true,
2250
+ vision: true,
2251
+ systemPrompt: true,
2252
+ maxContextTokens: 128e3
2253
+ }
2254
+ },
2255
+ {
2256
+ id: "gpt-4-turbo",
2257
+ displayName: "GPT-4 Turbo (on Azure)",
2258
+ capabilities: {
2259
+ streaming: true,
2260
+ tools: true,
2261
+ vision: true,
2262
+ systemPrompt: true,
2263
+ maxContextTokens: 128e3
2264
+ }
2265
+ },
2266
+ {
2267
+ // Azure spells it `gpt-35-turbo` (no dot). Keep their spelling for the id
2268
+ // so capability lookups against deployment names that echo the Azure id
2269
+ // hit.
2270
+ id: "gpt-35-turbo",
2271
+ displayName: "GPT-3.5 Turbo (on Azure)",
2272
+ capabilities: {
2273
+ streaming: true,
2274
+ tools: true,
2275
+ vision: false,
2276
+ systemPrompt: true,
2277
+ maxContextTokens: 16385
2278
+ }
2279
+ },
2280
+ {
2281
+ id: "o1-preview",
2282
+ displayName: "o1 preview \u2014 reasoning (on Azure)",
2283
+ capabilities: {
2284
+ streaming: false,
2285
+ tools: false,
2286
+ vision: false,
2287
+ systemPrompt: false,
2288
+ maxContextTokens: 128e3
2289
+ }
2290
+ },
2291
+ {
2292
+ id: "o1-mini",
2293
+ displayName: "o1 mini \u2014 reasoning (on Azure)",
2294
+ capabilities: {
2295
+ streaming: false,
2296
+ tools: false,
2297
+ vision: false,
2298
+ systemPrompt: false,
2299
+ maxContextTokens: 128e3
2300
+ }
2301
+ }
2302
+ ];
2303
+ var azureOpenAIManifest = {
2304
+ vendor: "azure-openai",
2305
+ displayName: "Azure OpenAI",
2306
+ authKinds: [
2307
+ {
2308
+ kind: "azureOpenAIApiKey",
2309
+ displayName: "API Key",
2310
+ fields: [
2311
+ {
2312
+ name: "apiKey",
2313
+ label: "API Key",
2314
+ type: "password",
2315
+ required: true,
2316
+ help: "Azure OpenAI resource key. Find it in the Azure portal under your OpenAI resource \u2192 Keys and Endpoint."
2317
+ },
2318
+ {
2319
+ name: "endpoint",
2320
+ label: "Endpoint",
2321
+ type: "url",
2322
+ required: true,
2323
+ help: "Resource endpoint URL, e.g. https://my-resource.openai.azure.com. Shown in the Azure portal alongside the keys."
2324
+ },
2325
+ {
2326
+ name: "deployment",
2327
+ label: "Deployment Name",
2328
+ type: "text",
2329
+ required: true,
2330
+ help: "The name you chose for the deployment in Azure AI Studio (NOT the underlying model id \u2014 deployments can be named anything)."
2331
+ },
2332
+ {
2333
+ name: "apiVersion",
2334
+ label: "API Version",
2335
+ type: "text",
2336
+ required: true,
2337
+ default: "2024-10-21",
2338
+ help: "Data-plane api-version, e.g. 2024-10-21. Microsoft rolls these frequently; see Azure OpenAI API reference docs for the current stable GA version."
2339
+ }
2340
+ ]
2341
+ }
2342
+ ],
2343
+ knownModels: AZURE_OPENAI_KNOWN_MODELS,
2344
+ // Azure's list-deployments endpoint is on the control plane (ARM) and
2345
+ // requires AAD credentials the data-plane API key doesn't carry. Return
2346
+ // the curated set from the manifest.
2347
+ supportsModelListing: false,
2348
+ docsUrl: "https://learn.microsoft.com/en-us/azure/ai-services/openai/reference"
2349
+ };
2350
+
2351
+ // src/adapters/azure-openai/adapter.ts
2352
+ var AzureOpenAIAdapter = class {
2353
+ vendor = azureOpenAIManifest.vendor;
2354
+ acceptedAuth = ["azureOpenAIApiKey"];
2355
+ client;
2356
+ init(auth, client) {
2357
+ if (auth.kind !== "azureOpenAIApiKey") {
2358
+ throw new Error(
2359
+ `AzureOpenAIAdapter: unsupported auth kind '${auth.kind}'`
2360
+ );
2361
+ }
2362
+ if (!auth.apiKey) {
2363
+ throw new Error("AzureOpenAIAdapter: apiKey is required");
2364
+ }
2365
+ if (!auth.endpoint) {
2366
+ throw new Error("AzureOpenAIAdapter: endpoint is required");
2367
+ }
2368
+ if (!auth.deployment) {
2369
+ throw new Error("AzureOpenAIAdapter: deployment is required");
2370
+ }
2371
+ if (!auth.apiVersion) {
2372
+ throw new Error("AzureOpenAIAdapter: apiVersion is required");
2373
+ }
2374
+ this.client = new AzureOpenAI({
2375
+ apiKey: auth.apiKey,
2376
+ endpoint: auth.endpoint,
2377
+ apiVersion: auth.apiVersion,
2378
+ deployment: auth.deployment,
2379
+ ...client?.timeout !== void 0 ? { timeout: client.timeout } : {},
2380
+ ...client?.maxRetries !== void 0 ? { maxRetries: client.maxRetries } : {}
2381
+ });
2382
+ }
2383
+ stream(req) {
2384
+ return streamFromOpenAI(this.ensureClient(), req, {
2385
+ knownModels: azureOpenAIManifest.knownModels
2386
+ });
2387
+ }
2388
+ appendAssistantToolCall(history, toolCalls) {
2389
+ return appendOpenAIAssistantToolCall(history, toolCalls);
2390
+ }
2391
+ appendToolResult(history, toolCallId, result) {
2392
+ return appendOpenAIToolResult(history, toolCallId, result);
2393
+ }
2394
+ async listAvailableModels() {
2395
+ return [...azureOpenAIManifest.knownModels];
2396
+ }
2397
+ async testCredential() {
2398
+ const client = this.ensureClient();
2399
+ await client.chat.completions.create({
2400
+ // Azure ignores `model` when a deployment is in the URL, but the SDK
2401
+ // still requires it as a parameter.
2402
+ model: "probe",
2403
+ messages: [{ role: "user", content: "ping" }],
2404
+ max_tokens: 1,
2405
+ stream: false
2406
+ });
2407
+ }
2408
+ async warmup() {
2409
+ }
2410
+ ensureClient() {
2411
+ if (!this.client) {
2412
+ throw new Error(
2413
+ "AzureOpenAIAdapter: init() must be called before stream()/listAvailableModels()"
2414
+ );
2415
+ }
2416
+ return this.client;
2417
+ }
2418
+ };
2419
+
2420
+ // src/adapters/azure-openai/factory.ts
2421
+ var azureOpenAIFactory = {
2422
+ vendor: azureOpenAIManifest.vendor,
2423
+ manifest: azureOpenAIManifest,
2424
+ create: () => new AzureOpenAIAdapter()
2425
+ };
2426
+
2228
2427
  // src/adapters/index.ts
2229
2428
  registerAdapter(openAIFactory);
2230
2429
  registerAdapter(deepseekFactory);
@@ -2233,6 +2432,7 @@ registerAdapter(googleFactory);
2233
2432
  registerAdapter(vertexGeminiFactory);
2234
2433
  registerAdapter(vertexOpenAIFactory);
2235
2434
  registerAdapter(bedrockFactory);
2435
+ registerAdapter(azureOpenAIFactory);
2236
2436
 
2237
2437
  // src/index.ts
2238
2438
  async function createLlm(args) {