@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.
@@ -2258,6 +2258,205 @@ var bedrockFactory = {
2258
2258
  create: () => new BedrockAdapter()
2259
2259
  };
2260
2260
 
2261
+ // src/adapters/azure-openai/adapter.ts
2262
+ var import_openai3 = require("openai");
2263
+
2264
+ // src/adapters/azure-openai/manifest.ts
2265
+ var AZURE_OPENAI_KNOWN_MODELS = [
2266
+ {
2267
+ id: "gpt-4o",
2268
+ displayName: "GPT-4o (on Azure)",
2269
+ capabilities: {
2270
+ streaming: true,
2271
+ tools: true,
2272
+ vision: true,
2273
+ systemPrompt: true,
2274
+ maxContextTokens: 128e3
2275
+ }
2276
+ },
2277
+ {
2278
+ id: "gpt-4o-mini",
2279
+ displayName: "GPT-4o mini (on Azure)",
2280
+ capabilities: {
2281
+ streaming: true,
2282
+ tools: true,
2283
+ vision: true,
2284
+ systemPrompt: true,
2285
+ maxContextTokens: 128e3
2286
+ }
2287
+ },
2288
+ {
2289
+ id: "gpt-4-turbo",
2290
+ displayName: "GPT-4 Turbo (on Azure)",
2291
+ capabilities: {
2292
+ streaming: true,
2293
+ tools: true,
2294
+ vision: true,
2295
+ systemPrompt: true,
2296
+ maxContextTokens: 128e3
2297
+ }
2298
+ },
2299
+ {
2300
+ // Azure spells it `gpt-35-turbo` (no dot). Keep their spelling for the id
2301
+ // so capability lookups against deployment names that echo the Azure id
2302
+ // hit.
2303
+ id: "gpt-35-turbo",
2304
+ displayName: "GPT-3.5 Turbo (on Azure)",
2305
+ capabilities: {
2306
+ streaming: true,
2307
+ tools: true,
2308
+ vision: false,
2309
+ systemPrompt: true,
2310
+ maxContextTokens: 16385
2311
+ }
2312
+ },
2313
+ {
2314
+ id: "o1-preview",
2315
+ displayName: "o1 preview \u2014 reasoning (on Azure)",
2316
+ capabilities: {
2317
+ streaming: false,
2318
+ tools: false,
2319
+ vision: false,
2320
+ systemPrompt: false,
2321
+ maxContextTokens: 128e3
2322
+ }
2323
+ },
2324
+ {
2325
+ id: "o1-mini",
2326
+ displayName: "o1 mini \u2014 reasoning (on Azure)",
2327
+ capabilities: {
2328
+ streaming: false,
2329
+ tools: false,
2330
+ vision: false,
2331
+ systemPrompt: false,
2332
+ maxContextTokens: 128e3
2333
+ }
2334
+ }
2335
+ ];
2336
+ var azureOpenAIManifest = {
2337
+ vendor: "azure-openai",
2338
+ displayName: "Azure OpenAI",
2339
+ authKinds: [
2340
+ {
2341
+ kind: "azureOpenAIApiKey",
2342
+ displayName: "API Key",
2343
+ fields: [
2344
+ {
2345
+ name: "apiKey",
2346
+ label: "API Key",
2347
+ type: "password",
2348
+ required: true,
2349
+ help: "Azure OpenAI resource key. Find it in the Azure portal under your OpenAI resource \u2192 Keys and Endpoint."
2350
+ },
2351
+ {
2352
+ name: "endpoint",
2353
+ label: "Endpoint",
2354
+ type: "url",
2355
+ required: true,
2356
+ help: "Resource endpoint URL, e.g. https://my-resource.openai.azure.com. Shown in the Azure portal alongside the keys."
2357
+ },
2358
+ {
2359
+ name: "deployment",
2360
+ label: "Deployment Name",
2361
+ type: "text",
2362
+ required: true,
2363
+ help: "The name you chose for the deployment in Azure AI Studio (NOT the underlying model id \u2014 deployments can be named anything)."
2364
+ },
2365
+ {
2366
+ name: "apiVersion",
2367
+ label: "API Version",
2368
+ type: "text",
2369
+ required: true,
2370
+ default: "2024-10-21",
2371
+ 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."
2372
+ }
2373
+ ]
2374
+ }
2375
+ ],
2376
+ knownModels: AZURE_OPENAI_KNOWN_MODELS,
2377
+ // Azure's list-deployments endpoint is on the control plane (ARM) and
2378
+ // requires AAD credentials the data-plane API key doesn't carry. Return
2379
+ // the curated set from the manifest.
2380
+ supportsModelListing: false,
2381
+ docsUrl: "https://learn.microsoft.com/en-us/azure/ai-services/openai/reference"
2382
+ };
2383
+
2384
+ // src/adapters/azure-openai/adapter.ts
2385
+ var AzureOpenAIAdapter = class {
2386
+ vendor = azureOpenAIManifest.vendor;
2387
+ acceptedAuth = ["azureOpenAIApiKey"];
2388
+ client;
2389
+ init(auth, client) {
2390
+ if (auth.kind !== "azureOpenAIApiKey") {
2391
+ throw new Error(
2392
+ `AzureOpenAIAdapter: unsupported auth kind '${auth.kind}'`
2393
+ );
2394
+ }
2395
+ if (!auth.apiKey) {
2396
+ throw new Error("AzureOpenAIAdapter: apiKey is required");
2397
+ }
2398
+ if (!auth.endpoint) {
2399
+ throw new Error("AzureOpenAIAdapter: endpoint is required");
2400
+ }
2401
+ if (!auth.deployment) {
2402
+ throw new Error("AzureOpenAIAdapter: deployment is required");
2403
+ }
2404
+ if (!auth.apiVersion) {
2405
+ throw new Error("AzureOpenAIAdapter: apiVersion is required");
2406
+ }
2407
+ this.client = new import_openai3.AzureOpenAI({
2408
+ apiKey: auth.apiKey,
2409
+ endpoint: auth.endpoint,
2410
+ apiVersion: auth.apiVersion,
2411
+ deployment: auth.deployment,
2412
+ ...client?.timeout !== void 0 ? { timeout: client.timeout } : {},
2413
+ ...client?.maxRetries !== void 0 ? { maxRetries: client.maxRetries } : {}
2414
+ });
2415
+ }
2416
+ stream(req) {
2417
+ return streamFromOpenAI(this.ensureClient(), req, {
2418
+ knownModels: azureOpenAIManifest.knownModels
2419
+ });
2420
+ }
2421
+ appendAssistantToolCall(history, toolCalls) {
2422
+ return appendOpenAIAssistantToolCall(history, toolCalls);
2423
+ }
2424
+ appendToolResult(history, toolCallId, result) {
2425
+ return appendOpenAIToolResult(history, toolCallId, result);
2426
+ }
2427
+ async listAvailableModels() {
2428
+ return [...azureOpenAIManifest.knownModels];
2429
+ }
2430
+ async testCredential() {
2431
+ const client = this.ensureClient();
2432
+ await client.chat.completions.create({
2433
+ // Azure ignores `model` when a deployment is in the URL, but the SDK
2434
+ // still requires it as a parameter.
2435
+ model: "probe",
2436
+ messages: [{ role: "user", content: "ping" }],
2437
+ max_tokens: 1,
2438
+ stream: false
2439
+ });
2440
+ }
2441
+ async warmup() {
2442
+ }
2443
+ ensureClient() {
2444
+ if (!this.client) {
2445
+ throw new Error(
2446
+ "AzureOpenAIAdapter: init() must be called before stream()/listAvailableModels()"
2447
+ );
2448
+ }
2449
+ return this.client;
2450
+ }
2451
+ };
2452
+
2453
+ // src/adapters/azure-openai/factory.ts
2454
+ var azureOpenAIFactory = {
2455
+ vendor: azureOpenAIManifest.vendor,
2456
+ manifest: azureOpenAIManifest,
2457
+ create: () => new AzureOpenAIAdapter()
2458
+ };
2459
+
2261
2460
  // src/adapters/index.ts
2262
2461
  registerAdapter(openAIFactory);
2263
2462
  registerAdapter(deepseekFactory);
@@ -2266,6 +2465,7 @@ registerAdapter(googleFactory);
2266
2465
  registerAdapter(vertexGeminiFactory);
2267
2466
  registerAdapter(vertexOpenAIFactory);
2268
2467
  registerAdapter(bedrockFactory);
2468
+ registerAdapter(azureOpenAIFactory);
2269
2469
 
2270
2470
  // src/index.ts
2271
2471
  async function createLlm(args) {