@azure-rest/ai-inference 1.0.0-beta.3 → 1.0.0-beta.5

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.
Files changed (127) hide show
  1. package/README.md +155 -82
  2. package/dist/browser/clientDefinitions.d.ts +7 -5
  3. package/dist/browser/clientDefinitions.d.ts.map +1 -1
  4. package/dist/browser/clientDefinitions.js.map +1 -1
  5. package/dist/browser/constants.js +1 -1
  6. package/dist/browser/constants.js.map +1 -1
  7. package/dist/browser/isUnexpected.d.ts +1 -1
  8. package/dist/browser/isUnexpected.d.ts.map +1 -1
  9. package/dist/browser/isUnexpected.js +2 -1
  10. package/dist/browser/isUnexpected.js.map +1 -1
  11. package/dist/browser/modelClient.d.ts +3 -3
  12. package/dist/browser/modelClient.d.ts.map +1 -1
  13. package/dist/browser/modelClient.js +1 -1
  14. package/dist/browser/modelClient.js.map +1 -1
  15. package/dist/browser/models.d.ts +43 -10
  16. package/dist/browser/models.d.ts.map +1 -1
  17. package/dist/browser/models.js.map +1 -1
  18. package/dist/browser/outputModels.d.ts +3 -1
  19. package/dist/browser/outputModels.d.ts.map +1 -1
  20. package/dist/browser/outputModels.js.map +1 -1
  21. package/dist/browser/parameters.d.ts +5 -5
  22. package/dist/browser/parameters.d.ts.map +1 -1
  23. package/dist/browser/parameters.js.map +1 -1
  24. package/dist/browser/responses.d.ts +3 -3
  25. package/dist/browser/responses.d.ts.map +1 -1
  26. package/dist/browser/responses.js.map +1 -1
  27. package/dist/browser/tracingHelper.d.ts +3 -3
  28. package/dist/browser/tracingHelper.d.ts.map +1 -1
  29. package/dist/browser/tracingHelper.js.map +1 -1
  30. package/dist/browser/tracingPolicy.d.ts +1 -1
  31. package/dist/browser/tracingPolicy.d.ts.map +1 -1
  32. package/dist/browser/tracingPolicy.js.map +1 -1
  33. package/dist/commonjs/clientDefinitions.d.ts +7 -5
  34. package/dist/commonjs/clientDefinitions.d.ts.map +1 -1
  35. package/dist/commonjs/clientDefinitions.js.map +1 -1
  36. package/dist/commonjs/constants.js +1 -1
  37. package/dist/commonjs/constants.js.map +1 -1
  38. package/dist/commonjs/isUnexpected.d.ts +1 -1
  39. package/dist/commonjs/isUnexpected.d.ts.map +1 -1
  40. package/dist/commonjs/isUnexpected.js +2 -1
  41. package/dist/commonjs/isUnexpected.js.map +1 -1
  42. package/dist/commonjs/modelClient.d.ts +3 -3
  43. package/dist/commonjs/modelClient.d.ts.map +1 -1
  44. package/dist/commonjs/modelClient.js +1 -1
  45. package/dist/commonjs/modelClient.js.map +1 -1
  46. package/dist/commonjs/models.d.ts +43 -10
  47. package/dist/commonjs/models.d.ts.map +1 -1
  48. package/dist/commonjs/models.js.map +1 -1
  49. package/dist/commonjs/outputModels.d.ts +3 -1
  50. package/dist/commonjs/outputModels.d.ts.map +1 -1
  51. package/dist/commonjs/outputModels.js.map +1 -1
  52. package/dist/commonjs/parameters.d.ts +5 -5
  53. package/dist/commonjs/parameters.d.ts.map +1 -1
  54. package/dist/commonjs/parameters.js.map +1 -1
  55. package/dist/commonjs/responses.d.ts +3 -3
  56. package/dist/commonjs/responses.d.ts.map +1 -1
  57. package/dist/commonjs/responses.js.map +1 -1
  58. package/dist/commonjs/tracingHelper.d.ts +3 -3
  59. package/dist/commonjs/tracingHelper.d.ts.map +1 -1
  60. package/dist/commonjs/tracingHelper.js.map +1 -1
  61. package/dist/commonjs/tracingPolicy.d.ts +1 -1
  62. package/dist/commonjs/tracingPolicy.d.ts.map +1 -1
  63. package/dist/commonjs/tracingPolicy.js.map +1 -1
  64. package/dist/commonjs/tsdoc-metadata.json +1 -1
  65. package/dist/esm/clientDefinitions.d.ts +7 -5
  66. package/dist/esm/clientDefinitions.d.ts.map +1 -1
  67. package/dist/esm/clientDefinitions.js.map +1 -1
  68. package/dist/esm/constants.js +1 -1
  69. package/dist/esm/constants.js.map +1 -1
  70. package/dist/esm/isUnexpected.d.ts +1 -1
  71. package/dist/esm/isUnexpected.d.ts.map +1 -1
  72. package/dist/esm/isUnexpected.js +2 -1
  73. package/dist/esm/isUnexpected.js.map +1 -1
  74. package/dist/esm/modelClient.d.ts +3 -3
  75. package/dist/esm/modelClient.d.ts.map +1 -1
  76. package/dist/esm/modelClient.js +1 -1
  77. package/dist/esm/modelClient.js.map +1 -1
  78. package/dist/esm/models.d.ts +43 -10
  79. package/dist/esm/models.d.ts.map +1 -1
  80. package/dist/esm/models.js.map +1 -1
  81. package/dist/esm/outputModels.d.ts +3 -1
  82. package/dist/esm/outputModels.d.ts.map +1 -1
  83. package/dist/esm/outputModels.js.map +1 -1
  84. package/dist/esm/parameters.d.ts +5 -5
  85. package/dist/esm/parameters.d.ts.map +1 -1
  86. package/dist/esm/parameters.js.map +1 -1
  87. package/dist/esm/responses.d.ts +3 -3
  88. package/dist/esm/responses.d.ts.map +1 -1
  89. package/dist/esm/responses.js.map +1 -1
  90. package/dist/esm/tracingHelper.d.ts +3 -3
  91. package/dist/esm/tracingHelper.d.ts.map +1 -1
  92. package/dist/esm/tracingHelper.js.map +1 -1
  93. package/dist/esm/tracingPolicy.d.ts +1 -1
  94. package/dist/esm/tracingPolicy.d.ts.map +1 -1
  95. package/dist/esm/tracingPolicy.js.map +1 -1
  96. package/dist/react-native/clientDefinitions.d.ts +7 -5
  97. package/dist/react-native/clientDefinitions.d.ts.map +1 -1
  98. package/dist/react-native/clientDefinitions.js.map +1 -1
  99. package/dist/react-native/constants.js +1 -1
  100. package/dist/react-native/constants.js.map +1 -1
  101. package/dist/react-native/isUnexpected.d.ts +1 -1
  102. package/dist/react-native/isUnexpected.d.ts.map +1 -1
  103. package/dist/react-native/isUnexpected.js +2 -1
  104. package/dist/react-native/isUnexpected.js.map +1 -1
  105. package/dist/react-native/modelClient.d.ts +3 -3
  106. package/dist/react-native/modelClient.d.ts.map +1 -1
  107. package/dist/react-native/modelClient.js +1 -1
  108. package/dist/react-native/modelClient.js.map +1 -1
  109. package/dist/react-native/models.d.ts +43 -10
  110. package/dist/react-native/models.d.ts.map +1 -1
  111. package/dist/react-native/models.js.map +1 -1
  112. package/dist/react-native/outputModels.d.ts +3 -1
  113. package/dist/react-native/outputModels.d.ts.map +1 -1
  114. package/dist/react-native/outputModels.js.map +1 -1
  115. package/dist/react-native/parameters.d.ts +5 -5
  116. package/dist/react-native/parameters.d.ts.map +1 -1
  117. package/dist/react-native/parameters.js.map +1 -1
  118. package/dist/react-native/responses.d.ts +3 -3
  119. package/dist/react-native/responses.d.ts.map +1 -1
  120. package/dist/react-native/responses.js.map +1 -1
  121. package/dist/react-native/tracingHelper.d.ts +3 -3
  122. package/dist/react-native/tracingHelper.d.ts.map +1 -1
  123. package/dist/react-native/tracingHelper.js.map +1 -1
  124. package/dist/react-native/tracingPolicy.d.ts +1 -1
  125. package/dist/react-native/tracingPolicy.d.ts.map +1 -1
  126. package/dist/react-native/tracingPolicy.js.map +1 -1
  127. package/package.json +12 -12
package/README.md CHANGED
@@ -8,7 +8,7 @@ Key links:
8
8
 
9
9
  - [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-inference-rest)
10
10
  - [Package (NPM)](https://aka.ms/npm-azure-rest-ai-inference)
11
- - [API reference documentation](https://aka.ms/AAp1kxa)
11
+ - [API reference documentation](https://learn.microsoft.com/javascript/api/@azure-rest/ai-inference/)
12
12
  - [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-inference-rest/samples)
13
13
 
14
14
  ## Getting started
@@ -18,18 +18,16 @@ import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
18
18
  import { AzureKeyCredential } from "@azure/core-auth";
19
19
  const client = new ModelClient(
20
20
  "https://<Azure Model endpoint>",
21
- new AzureKeyCredential("<Azure API key>")
21
+ new AzureKeyCredential("<Azure API key>"),
22
22
  );
23
23
 
24
24
  const response = await client.path("/chat/completions").post({
25
25
  body: {
26
- messages: [
27
- {role: "user", content: "How many feet are in a mile?"},
28
- ],
29
- }
26
+ messages: [{ role: "user", content: "How many feet are in a mile?" }],
27
+ },
30
28
  });
31
29
 
32
- if(isUnexpected(response)) {
30
+ if (isUnexpected(response)) {
33
31
  throw response.body.error;
34
32
  }
35
33
  console.log(response.body.choices[0].message.content);
@@ -52,6 +50,7 @@ npm install @azure-rest/ai-inference
52
50
  ```
53
51
 
54
52
  ### Create and authenticate a `ModelClient`
53
+
55
54
  #### Using an API Key from Azure
56
55
 
57
56
  You can authenticate with an Azure API key using the [Azure Core Auth library][azure_core_auth]. To use the AzureKeyCredential provider shown below, please install the `@azure/core-auth` package:
@@ -86,7 +85,7 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica
86
85
 
87
86
  ```javascript
88
87
  import ModelClient from "@azure-rest/ai-inference";
89
- import { DefaultAzureCredential } from "@azure/identity";
88
+ import { DefaultAzureCredential } from "@azure/identity";
90
89
 
91
90
  const client = new ModelClient("<endpoint>", new DefaultAzureCredential());
92
91
  ```
@@ -99,20 +98,19 @@ The main concept to understand is [Completions][azure_openai_completions_docs].
99
98
  import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
100
99
  import { AzureKeyCredential } from "@azure/core-auth";
101
100
 
102
- async function main(){
101
+ async function main() {
103
102
  const client = new ModelClient(
104
- "https://your-model-endpoint/",
105
- new AzureKeyCredential("your-model-api-key"));
103
+ "https://your-model-endpoint/",
104
+ new AzureKeyCredential("your-model-api-key"),
105
+ );
106
106
 
107
107
  const response = await client.path("/chat/completions").post({
108
108
  body: {
109
- messages: [
110
- {role: "user", content: "Hello, world!"},
111
- ],
112
- }
109
+ messages: [{ role: "user", content: "Hello, world!" }],
110
+ },
113
111
  });
114
112
 
115
- if(isUnexpected(response)) {
113
+ if (isUnexpected(response)) {
116
114
  throw response.body.error;
117
115
  }
118
116
 
@@ -141,7 +139,7 @@ import ModelClient from "@azure-rest/ai-inference";
141
139
  import { DefaultAzureCredential } from "@azure/identity";
142
140
  import { createSseStream } from "@azure/core-sse";
143
141
 
144
- async function main(){
142
+ async function main() {
145
143
  const endpoint = "https://myaccount.openai.azure.com/";
146
144
  const client = new ModelClient(endpoint, new DefaultAzureCredential());
147
145
 
@@ -155,13 +153,16 @@ async function main(){
155
153
 
156
154
  console.log(`Messages: ${messages.map((m) => m.content).join("\n")}`);
157
155
 
158
- const response = await client.path("/chat/completions").post({
159
- body: {
160
- messages,
161
- stream: true,
162
- max_tokens: 128
163
- }
164
- }).asNodeStream();
156
+ const response = await client
157
+ .path("/chat/completions")
158
+ .post({
159
+ body: {
160
+ messages,
161
+ stream: true,
162
+ max_tokens: 128,
163
+ },
164
+ })
165
+ .asNodeStream();
165
166
 
166
167
  const stream = response.body;
167
168
  if (!stream) {
@@ -178,7 +179,7 @@ async function main(){
178
179
  if (event.data === "[DONE]") {
179
180
  return;
180
181
  }
181
- for (const choice of (JSON.parse(event.data)).choices) {
182
+ for (const choice of JSON.parse(event.data).choices) {
182
183
  console.log(choice.delta?.content ?? "");
183
184
  }
184
185
  }
@@ -197,7 +198,7 @@ This example generates text responses to input prompts using an Azure subscripti
197
198
  import ModelClient from "@azure-rest/ai-inference";
198
199
  import { AzureKeyCredential } from "@azure/core-auth";
199
200
 
200
- async function main(){
201
+ async function main() {
201
202
  // Replace with your Model API key
202
203
  const key = "YOUR_MODEL_API_KEY";
203
204
  const endpoint = "https://your-model-endpoint/";
@@ -208,17 +209,21 @@ async function main(){
208
209
  { role: "user", content: "What is inference in the context of AI?" },
209
210
  { role: "user", content: "Why do children love dinosaurs?" },
210
211
  { role: "user", content: "Generate a proof of Euler's identity" },
211
- { role: "user", content: "Describe in single words only the good things that come into your mind about your mother." },
212
+ {
213
+ role: "user",
214
+ content:
215
+ "Describe in single words only the good things that come into your mind about your mother.",
216
+ },
212
217
  ];
213
218
 
214
219
  let promptIndex = 0;
215
220
  const response = await client.path("/chat/completions").post({
216
221
  body: {
217
- messages
218
- }
222
+ messages,
223
+ },
219
224
  });
220
225
 
221
- if(response.status !== "200") {
226
+ if (response.status !== "200") {
222
227
  throw response.body.error;
223
228
  }
224
229
  for (const choice of response.body.choices) {
@@ -241,7 +246,7 @@ This example generates a summarization of the given input prompt.
241
246
  import ModelClient from "@azure-rest/ai-inference";
242
247
  import { DefaultAzureCredential } from "@azure/identity";
243
248
 
244
- async function main(){
249
+ async function main() {
245
250
  const endpoint = "https://your-model-endpoint/";
246
251
  const client = new ModelClient(endpoint, new DefaultAzureCredential());
247
252
 
@@ -266,14 +271,12 @@ async function main(){
266
271
 
267
272
  const response = await client.path("/chat/completions").post({
268
273
  body: {
269
- messages: [
270
- { role: "user", content: summarizationPrompt }
271
- ],
272
- max_tokens: 64
273
- }
274
+ messages: [{ role: "user", content: summarizationPrompt }],
275
+ max_tokens: 64,
276
+ },
274
277
  });
275
278
 
276
- if(response.status !== "200") {
279
+ if (response.status !== "200") {
277
280
  throw response.body.error;
278
281
  }
279
282
  const completion = response.body.choices[0].message.content;
@@ -292,23 +295,23 @@ process of fulfilling a chat completions request. To use chat tools, start by de
292
295
 
293
296
  ```js
294
297
  const getCurrentWeather = {
295
- name: "get_current_weather",
296
- description: "Get the current weather in a given location",
297
- parameters: {
298
- type: "object",
299
- properties: {
300
- location: {
301
- type: "string",
302
- description: "The city and state, e.g. San Francisco, CA",
303
- },
304
- unit: {
305
- type: "string",
306
- enum: ["celsius", "fahrenheit"],
307
- },
298
+ name: "get_current_weather",
299
+ description: "Get the current weather in a given location",
300
+ parameters: {
301
+ type: "object",
302
+ properties: {
303
+ location: {
304
+ type: "string",
305
+ description: "The city and state, e.g. San Francisco, CA",
306
+ },
307
+ unit: {
308
+ type: "string",
309
+ enum: ["celsius", "fahrenheit"],
308
310
  },
309
- required: ["location"],
310
311
  },
311
- };
312
+ required: ["location"],
313
+ },
314
+ };
312
315
  ```
313
316
 
314
317
  With the tool defined, include that new definition in the options for a chat completions request:
@@ -324,8 +327,8 @@ const tools = [
324
327
  const result = await client.path("/chat/completions").post({
325
328
  body: {
326
329
  messages,
327
- tools
328
- }
330
+ tools,
331
+ },
329
332
  });
330
333
  ```
331
334
 
@@ -336,16 +339,16 @@ new request messages can be thought of as a sort of "callback" for chat completi
336
339
  ```js
337
340
  // Purely for convenience and clarity, this function handles tool call responses.
338
341
  function applyToolCall({ function: call, id }) {
339
- if (call.name === "get_current_weather") {
340
- const { location, unit } = JSON.parse(call.arguments);
341
- // In a real application, this would be a call to a weather API with location and unit parameters
342
- return {
343
- role: "tool",
344
- content: `The weather in ${location} is 72 degrees ${unit} and sunny.`,
345
- toolCallId: id,
346
- }
347
- }
348
- throw new Error(`Unknown tool call: ${call.name}`);
342
+ if (call.name === "get_current_weather") {
343
+ const { location, unit } = JSON.parse(call.arguments);
344
+ // In a real application, this would be a call to a weather API with location and unit parameters
345
+ return {
346
+ role: "tool",
347
+ content: `The weather in ${location} is 72 degrees ${unit} and sunny.`,
348
+ toolCallId: id,
349
+ };
350
+ }
351
+ throw new Error(`Unknown tool call: ${call.name}`);
349
352
  }
350
353
  ```
351
354
 
@@ -366,15 +369,15 @@ if (responseMessage?.role === "assistant") {
366
369
  ];
367
370
  const toolCallResolutionResult = await client.path("/chat/completions").post({
368
371
  body: {
369
- messages: toolCallResolutionMessages
370
- }
372
+ messages: toolCallResolutionMessages,
373
+ },
371
374
  });
372
375
  // continue handling the response as normal
373
376
  }
374
377
  }
375
378
  ```
376
379
 
377
- ### Chat with images (using models supporting image chat, such as gpt-4o)
380
+ ### Chat with images (using models supporting image chat, such as gpt-4o)
378
381
 
379
382
  Some Azure models allow you to use images as input components into chat completions.
380
383
 
@@ -399,14 +402,14 @@ of `finish_reason`:
399
402
  ```js
400
403
  const response = await client.path("/chat/completions").post({
401
404
  body: {
402
- messages
405
+ messages
403
406
  });
404
407
  console.log(`Chatbot: ${response.choices[0].message?.content}`);
405
408
  ```
406
409
 
407
410
  ### Text Embeddings example
408
411
 
409
- This example demonstrates how to get text embeddings with Entra ID authentication.
412
+ This example demonstrates how to get text embeddings with Entra ID authentication.
410
413
 
411
414
  ```javascript
412
415
  import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
@@ -415,19 +418,21 @@ import { DefaultAzureCredential } from "@azure/identity";
415
418
  const endpoint = "<your_model_endpoint>";
416
419
  const credential = new DefaultAzureCredential();
417
420
 
418
- async function main(){
421
+ async function main() {
419
422
  const client = ModelClient(endpoint, credential);
420
423
  const response = await client.path("/embeddings").post({
421
424
  body: {
422
- input: ["first phrase", "second phrase", "third phrase"]
423
- }
425
+ input: ["first phrase", "second phrase", "third phrase"],
426
+ },
424
427
  });
425
428
 
426
429
  if (isUnexpected(response)) {
427
430
  throw response.body.error;
428
431
  }
429
432
  for (const data of response.body.data) {
430
- console.log(`data length: ${data.length}, [${data[0]}, ${data[1]}, ..., ${data[data.length - 2]}, ${data[data.length - 1]}]`);
433
+ console.log(
434
+ `data length: ${data.length}, [${data[0]}, ${data[1]}, ..., ${data[data.length - 2]}, ${data[data.length - 1]}]`,
435
+ );
431
436
  }
432
437
  }
433
438
 
@@ -446,18 +451,79 @@ data: length=1024, [0.04196167, 0.029083252, ..., -0.0027484894, 0.0073127747]
446
451
 
447
452
  To generate embeddings for additional phrases, simply call `client.path("/embeddings").post` multiple times using the same `client`.
448
453
 
449
- ### Instrumentation
454
+ ### Image Embeddings example
455
+
456
+ This example demonstrates how to get image embeddings with Entra ID authentication.
457
+
458
+ ```javascript
459
+ import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
460
+ import { DefaultAzureCredential } from "@azure/identity";
461
+ import fs from "fs";
462
+
463
+ const endpoint = "<your_model_endpoint>";
464
+ const credential = new DefaultAzureCredential();
465
+
466
+ function getImageDataUrl(imageFile, imageFormat) {
467
+ try {
468
+ const imageBuffer = fs.readFileSync(imageFile);
469
+ const imageBase64 = imageBuffer.toString("base64");
470
+ return `data:image/${imageFormat};base64,${imageBase64}`;
471
+ } catch (error) {
472
+ console.error(`Could not read '${imageFile}'.`);
473
+ console.error("Set the correct path to the image file before running this sample.");
474
+ process.exit(1);
475
+ }
476
+ }
477
+
478
+ async function main() {
479
+ const client = ModelClient(endpoint, credential);
480
+ const image = getImageDataUrl("<image_file>", "<image_format>");
481
+ const response = await client.path("/images/embeddings").post({
482
+ body: {
483
+ input: [{image}],
484
+ },
485
+ });
486
+
487
+ if (isUnexpected(response)) {
488
+ throw response.body.error;
489
+ }
490
+ for (const data of response.body.data) {
491
+ console.log(
492
+ `data length: ${data.length}, [${data[0]}, ${data[1]}, ..., ${data[data.length - 2]}, ${data[data.length - 1]}]`,
493
+ );
494
+ }
495
+ }
496
+
497
+ main().catch((err) => {
498
+ console.error("The sample encountered an error:", err);
499
+ });
500
+ ```
501
+
502
+ The length of the embedding vector depends on the model, but you should see something like this:
503
+
504
+ ```text
505
+ data: length=1024, [0.0013399124, -0.01576233, ..., 0.007843018, 0.000238657]
506
+ data: length=1024, [0.036590576, -0.0059547424, ..., 0.011405945, 0.004863739]
507
+ data: length=1024, [0.04196167, 0.029083252, ..., -0.0027484894, 0.0073127747]
508
+ ```
509
+
510
+ ### Instrumentation
511
+
450
512
  Currently instrumentation is only supported for `Chat Completion without streaming`.
451
513
  To enable instrumentation, it is required to register exporter(s).
452
514
 
453
515
  Here is an example to add console as a exporter:
516
+
454
517
  ```js
455
- import { ConsoleSpanExporter, NodeTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
518
+ import {
519
+ ConsoleSpanExporter,
520
+ NodeTracerProvider,
521
+ SimpleSpanProcessor,
522
+ } from "@opentelemetry/sdk-trace-node";
456
523
 
457
524
  const provider = new NodeTracerProvider();
458
525
  provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
459
526
  provider.register();
460
-
461
527
  ```
462
528
 
463
529
  Here is an example to add application insight to be a exporter:
@@ -477,7 +543,7 @@ if (connectionString) {
477
543
  provider.register();
478
544
  ```
479
545
 
480
- In addition, you need to register to use instrumentation for Azure SDK. You must do this before you import any dependency of `@azure-core-tracing`
546
+ To use instrumentation for Azure SDK, you need to register it before importing any dependencies from `@azure/core-tracing`, such as `@azure-rest/ai-inference`.
481
547
 
482
548
  ```js
483
549
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
@@ -486,12 +552,18 @@ import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentat
486
552
  registerInstrumentations({
487
553
  instrumentations: [createAzureSdkInstrumentation()],
488
554
  });
555
+
556
+ import ModelClient from "@azure-rest/ai-inference";
489
557
  ```
490
558
 
491
559
  Finally when you are making a call for chat completion, you need to include
560
+
492
561
  ```js
493
- tracingOptions: { tracingContext: context.active() }
562
+ tracingOptions: {
563
+ tracingContext: context.active();
564
+ }
494
565
  ```
566
+
495
567
  Here is an example:
496
568
 
497
569
  ```js
@@ -503,7 +575,8 @@ client.path("/chat/completions").post({
503
575
  ```
504
576
 
505
577
  ### Tracing Your Own Functions
506
- Open Telemetry provides `startActiveSpan` to instrument you own code. Here is an example:
578
+
579
+ Open Telemetry provides `startActiveSpan` to instrument you own code. Here is an example:
507
580
 
508
581
  ```js
509
582
  import { trace } from "@opentelemetry/api";
@@ -522,7 +595,6 @@ const getWeatherFunc = (location: string, unit: string): string => {
522
595
  }
523
596
  ```
524
597
 
525
-
526
598
  ## Troubleshooting
527
599
 
528
600
  ### Logging
@@ -538,11 +610,12 @@ setLogLevel("info");
538
610
  For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
539
611
 
540
612
  <!-- LINKS -->
613
+
541
614
  [stream_chat_completion_sample]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/ai/ai-inference-rest/samples/v1-beta/typescript/streamChatCompletions.ts
542
615
  [azure_openai_completions_docs]: https://learn.microsoft.com/azure/cognitive-services/openai/how-to/completions
543
616
  [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
544
617
  [azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
545
618
  [azure_core_auth]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-auth
546
- [register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
547
- [azure_cli]: https://docs.microsoft.com/cli/azure
619
+ [register_aad_app]: https://learn.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
620
+ [azure_cli]: https://learn.microsoft.com/cli/azure
548
621
  [azure_portal]: https://portal.azure.com
@@ -1,6 +1,6 @@
1
- import { GetChatCompletionsParameters, GetModelInfoParameters, GetEmbeddingsParameters, GetImageEmbeddingsParameters } from "./parameters.js";
2
- import { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse, GetEmbeddings200Response, GetEmbeddingsDefaultResponse, GetImageEmbeddings200Response, GetImageEmbeddingsDefaultResponse } from "./responses.js";
3
- import { Client, StreamableMethod } from "@azure-rest/core-client";
1
+ import type { GetChatCompletionsParameters, GetModelInfoParameters, GetEmbeddingsParameters, GetImageEmbeddingsParameters } from "./parameters.js";
2
+ import type { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse, GetEmbeddings200Response, GetEmbeddingsDefaultResponse, GetImageEmbeddings200Response, GetImageEmbeddingsDefaultResponse } from "./responses.js";
3
+ import type { Client, StreamableMethod } from "@azure-rest/core-client";
4
4
  export interface GetChatCompletions {
5
5
  /**
6
6
  * Gets chat completions for the provided chat messages.
@@ -8,12 +8,14 @@ export interface GetChatCompletions {
8
8
  * provided prompt data. The method makes a REST API call to the `/chat/completions` route
9
9
  * on the given endpoint.
10
10
  */
11
- post(options?: GetChatCompletionsParameters): StreamableMethod<GetChatCompletions200Response | GetChatCompletionsDefaultResponse>;
11
+ post(options: GetChatCompletionsParameters): StreamableMethod<GetChatCompletions200Response | GetChatCompletionsDefaultResponse>;
12
12
  }
13
13
  export interface GetModelInfo {
14
14
  /**
15
15
  * Returns information about the AI model.
16
16
  * The method makes a REST API call to the `/info` route on the given endpoint.
17
+ * This method will only work when using Serverless API or Managed Compute endpoint.
18
+ * It will not work for GitHub Models endpoint or Azure OpenAI endpoint.
17
19
  */
18
20
  get(options?: GetModelInfoParameters): StreamableMethod<GetModelInfo200Response | GetModelInfoDefaultResponse>;
19
21
  }
@@ -29,7 +31,7 @@ export interface GetImageEmbeddings {
29
31
  * Return the embedding vectors for given images.
30
32
  * The method makes a REST API call to the `/images/embeddings` route on the given endpoint.
31
33
  */
32
- post(options?: GetImageEmbeddingsParameters): StreamableMethod<GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse>;
34
+ post(options: GetImageEmbeddingsParameters): StreamableMethod<GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse>;
33
35
  }
34
36
  export interface Routes {
35
37
  /** Resource for '/chat/completions' has methods for the following verbs: post */
@@ -1 +1 @@
1
- {"version":3,"file":"clientDefinitions.d.ts","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EAClC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CACF,OAAO,CAAC,EAAE,4BAA4B,GACrC,gBAAgB,CAAC,6BAA6B,GAAG,iCAAiC,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,GAAG,CACD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,gBAAgB,CAAC,uBAAuB,GAAG,2BAA2B,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,CACF,OAAO,CAAC,EAAE,uBAAuB,GAChC,gBAAgB,CAAC,wBAAwB,GAAG,4BAA4B,CAAC,CAAC;CAC9E;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,CACF,OAAO,CAAC,EAAE,4BAA4B,GACrC,gBAAgB,CAAC,6BAA6B,GAAG,iCAAiC,CAAC,CAAC;CACxF;AAED,MAAM,WAAW,MAAM;IACrB,iFAAiF;IACjF,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,oEAAoE;IACpE,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9B,2EAA2E;IAC3E,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CAAC;IACrC,kFAAkF;IAClF,CAAC,IAAI,EAAE,oBAAoB,GAAG,kBAAkB,CAAC;CAClD;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
1
+ {"version":3,"file":"clientDefinitions.d.ts","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EACV,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EAClC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExE,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,IAAI,CACF,OAAO,EAAE,4BAA4B,GACpC,gBAAgB,CACjB,6BAA6B,GAAG,iCAAiC,CAClE,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,GAAG,CACD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,gBAAgB,CAAC,uBAAuB,GAAG,2BAA2B,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,CACF,OAAO,CAAC,EAAE,uBAAuB,GAChC,gBAAgB,CAAC,wBAAwB,GAAG,4BAA4B,CAAC,CAAC;CAC9E;AAED,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,CACF,OAAO,EAAE,4BAA4B,GACpC,gBAAgB,CACjB,6BAA6B,GAAG,iCAAiC,CAClE,CAAC;CACH;AAED,MAAM,WAAW,MAAM;IACrB,iFAAiF;IACjF,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,oEAAoE;IACpE,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9B,2EAA2E;IAC3E,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CAAC;IACrC,kFAAkF;IAClF,CAAC,IAAI,EAAE,oBAAoB,GAAG,kBAAkB,CAAC;CAClD;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n GetChatCompletionsParameters,\n GetModelInfoParameters,\n GetEmbeddingsParameters,\n GetImageEmbeddingsParameters,\n} from \"./parameters.js\";\nimport {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\n GetEmbeddings200Response,\n GetEmbeddingsDefaultResponse,\n GetImageEmbeddings200Response,\n GetImageEmbeddingsDefaultResponse,\n} from \"./responses.js\";\nimport { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface GetChatCompletions {\n /**\n * Gets chat completions for the provided chat messages.\n * Completions support a wide variety of tasks and generate text that continues from or \"completes\"\n * provided prompt data. The method makes a REST API call to the `/chat/completions` route\n * on the given endpoint.\n */\n post(\n options?: GetChatCompletionsParameters,\n ): StreamableMethod<GetChatCompletions200Response | GetChatCompletionsDefaultResponse>;\n}\n\nexport interface GetModelInfo {\n /**\n * Returns information about the AI model.\n * The method makes a REST API call to the `/info` route on the given endpoint.\n */\n get(\n options?: GetModelInfoParameters,\n ): StreamableMethod<GetModelInfo200Response | GetModelInfoDefaultResponse>;\n}\n\nexport interface GetEmbeddings {\n /**\n * Return the embedding vectors for given text prompts.\n * The method makes a REST API call to the `/embeddings` route on the given endpoint.\n */\n post(\n options?: GetEmbeddingsParameters,\n ): StreamableMethod<GetEmbeddings200Response | GetEmbeddingsDefaultResponse>;\n}\n\nexport interface GetImageEmbeddings {\n /**\n * Return the embedding vectors for given images.\n * The method makes a REST API call to the `/images/embeddings` route on the given endpoint.\n */\n post(\n options?: GetImageEmbeddingsParameters,\n ): StreamableMethod<GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse>;\n}\n\nexport interface Routes {\n /** Resource for '/chat/completions' has methods for the following verbs: post */\n (path: \"/chat/completions\"): GetChatCompletions;\n /** Resource for '/info' has methods for the following verbs: get */\n (path: \"/info\"): GetModelInfo;\n /** Resource for '/embeddings' has methods for the following verbs: post */\n (path: \"/embeddings\"): GetEmbeddings;\n /** Resource for '/images/embeddings' has methods for the following verbs: post */\n (path: \"/images/embeddings\"): GetImageEmbeddings;\n}\n\nexport type ModelClient = Client & {\n path: Routes;\n};\n"]}
1
+ {"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetChatCompletionsParameters,\n GetModelInfoParameters,\n GetEmbeddingsParameters,\n GetImageEmbeddingsParameters,\n} from \"./parameters.js\";\nimport type {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\n GetEmbeddings200Response,\n GetEmbeddingsDefaultResponse,\n GetImageEmbeddings200Response,\n GetImageEmbeddingsDefaultResponse,\n} from \"./responses.js\";\nimport type { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface GetChatCompletions {\n /**\n * Gets chat completions for the provided chat messages.\n * Completions support a wide variety of tasks and generate text that continues from or \"completes\"\n * provided prompt data. The method makes a REST API call to the `/chat/completions` route\n * on the given endpoint.\n */\n post(\n options: GetChatCompletionsParameters,\n ): StreamableMethod<\n GetChatCompletions200Response | GetChatCompletionsDefaultResponse\n >;\n}\n\nexport interface GetModelInfo {\n /**\n * Returns information about the AI model.\n * The method makes a REST API call to the `/info` route on the given endpoint.\n * This method will only work when using Serverless API or Managed Compute endpoint.\n * It will not work for GitHub Models endpoint or Azure OpenAI endpoint.\n */\n get(\n options?: GetModelInfoParameters,\n ): StreamableMethod<GetModelInfo200Response | GetModelInfoDefaultResponse>;\n}\n\nexport interface GetEmbeddings {\n /**\n * Return the embedding vectors for given text prompts.\n * The method makes a REST API call to the `/embeddings` route on the given endpoint.\n */\n post(\n options?: GetEmbeddingsParameters,\n ): StreamableMethod<GetEmbeddings200Response | GetEmbeddingsDefaultResponse>;\n}\n\nexport interface GetImageEmbeddings {\n /**\n * Return the embedding vectors for given images.\n * The method makes a REST API call to the `/images/embeddings` route on the given endpoint.\n */\n post(\n options: GetImageEmbeddingsParameters,\n ): StreamableMethod<\n GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse\n >;\n}\n\nexport interface Routes {\n /** Resource for '/chat/completions' has methods for the following verbs: post */\n (path: \"/chat/completions\"): GetChatCompletions;\n /** Resource for '/info' has methods for the following verbs: get */\n (path: \"/info\"): GetModelInfo;\n /** Resource for '/embeddings' has methods for the following verbs: post */\n (path: \"/embeddings\"): GetEmbeddings;\n /** Resource for '/images/embeddings' has methods for the following verbs: post */\n (path: \"/images/embeddings\"): GetImageEmbeddings;\n}\n\nexport type ModelClient = Client & {\n path: Routes;\n};\n"]}
@@ -1,4 +1,4 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- export const SDK_VERSION = "1.0.0-beta.3";
3
+ export const SDK_VERSION = "1.0.0-beta.4";
4
4
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,cAAc,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.3\";\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,cAAc,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"1.0.0-beta.4\";\n"]}
@@ -1,4 +1,4 @@
1
- import { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse, GetEmbeddings200Response, GetEmbeddingsDefaultResponse, GetImageEmbeddings200Response, GetImageEmbeddingsDefaultResponse } from "./responses.js";
1
+ import type { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse, GetEmbeddings200Response, GetEmbeddingsDefaultResponse, GetImageEmbeddings200Response, GetImageEmbeddingsDefaultResponse } from "./responses.js";
2
2
  export declare function isUnexpected(response: GetChatCompletions200Response | GetChatCompletionsDefaultResponse): response is GetChatCompletionsDefaultResponse;
3
3
  export declare function isUnexpected(response: GetModelInfo200Response | GetModelInfoDefaultResponse): response is GetModelInfoDefaultResponse;
4
4
  export declare function isUnexpected(response: GetEmbeddings200Response | GetEmbeddingsDefaultResponse): response is GetEmbeddingsDefaultResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"isUnexpected.d.ts","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EAClC,MAAM,gBAAgB,CAAC;AASxB,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,6BAA6B,GAAG,iCAAiC,GAC1E,QAAQ,IAAI,iCAAiC,CAAC;AACjD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,uBAAuB,GAAG,2BAA2B,GAC9D,QAAQ,IAAI,2BAA2B,CAAC;AAC3C,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,wBAAwB,GAAG,4BAA4B,GAChE,QAAQ,IAAI,4BAA4B,CAAC;AAC5C,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,6BAA6B,GAAG,iCAAiC,GAC1E,QAAQ,IAAI,iCAAiC,CAAC"}
1
+ {"version":3,"file":"isUnexpected.d.ts","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EAClC,MAAM,gBAAgB,CAAC;AASxB,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,6BAA6B,GAAG,iCAAiC,GAC1E,QAAQ,IAAI,iCAAiC,CAAC;AACjD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,uBAAuB,GAAG,2BAA2B,GAC9D,QAAQ,IAAI,2BAA2B,CAAC;AAC3C,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,wBAAwB,GAAG,4BAA4B,GAChE,QAAQ,IAAI,4BAA4B,CAAC;AAC5C,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,6BAA6B,GAAG,iCAAiC,GAC1E,QAAQ,IAAI,iCAAiC,CAAC"}
@@ -36,7 +36,8 @@ function getParametrizedPathSuccess(method, path) {
36
36
  // track if we have found a match to return the values found.
37
37
  let found = true;
38
38
  for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
39
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
39
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
40
+ ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
40
41
  const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
41
42
  // If the current part of the candidate is a "template" part
42
43
  // Try to use the suffix of pattern to match the path
@@ -1 +1 @@
1
- {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,MAAM,WAAW,GAA6B;IAC5C,wBAAwB,EAAE,CAAC,KAAK,CAAC;IACjC,WAAW,EAAE,CAAC,KAAK,CAAC;IACpB,kBAAkB,EAAE,CAAC,KAAK,CAAC;IAC3B,yBAAyB,EAAE,CAAC,KAAK,CAAC;CACnC,CAAC;AAcF,MAAM,UAAU,YAAY,CAC1B,QAQqC;IAMrC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,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,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\n GetEmbeddings200Response,\n GetEmbeddingsDefaultResponse,\n GetImageEmbeddings200Response,\n GetImageEmbeddingsDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /chat/completions\": [\"200\"],\n \"GET /info\": [\"200\"],\n \"POST /embeddings\": [\"200\"],\n \"POST /images/embeddings\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: GetChatCompletions200Response | GetChatCompletionsDefaultResponse,\n): response is GetChatCompletionsDefaultResponse;\nexport function isUnexpected(\n response: GetModelInfo200Response | GetModelInfoDefaultResponse,\n): response is GetModelInfoDefaultResponse;\nexport function isUnexpected(\n response: GetEmbeddings200Response | GetEmbeddingsDefaultResponse,\n): response is GetEmbeddingsDefaultResponse;\nexport function isUnexpected(\n response: GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse,\n): response is GetImageEmbeddingsDefaultResponse;\nexport function isUnexpected(\n response:\n | GetChatCompletions200Response\n | GetChatCompletionsDefaultResponse\n | GetModelInfo200Response\n | GetModelInfoDefaultResponse\n | GetEmbeddings200Response\n | GetEmbeddingsDefaultResponse\n | GetImageEmbeddings200Response\n | GetImageEmbeddingsDefaultResponse,\n): response is\n | GetChatCompletionsDefaultResponse\n | GetModelInfoDefaultResponse\n | GetEmbeddingsDefaultResponse\n | GetImageEmbeddingsDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
1
+ {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,MAAM,WAAW,GAA6B;IAC5C,wBAAwB,EAAE,CAAC,KAAK,CAAC;IACjC,WAAW,EAAE,CAAC,KAAK,CAAC;IACpB,kBAAkB,EAAE,CAAC,KAAK,CAAC;IAC3B,yBAAyB,EAAE,CA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,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\n GetEmbeddings200Response,\n GetEmbeddingsDefaultResponse,\n GetImageEmbeddings200Response,\n GetImageEmbeddingsDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /chat/completions\": [\"200\"],\n \"GET /info\": [\"200\"],\n \"POST /embeddings\": [\"200\"],\n \"POST /images/embeddings\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: GetChatCompletions200Response | GetChatCompletionsDefaultResponse,\n): response is GetChatCompletionsDefaultResponse;\nexport function isUnexpected(\n response: GetModelInfo200Response | GetModelInfoDefaultResponse,\n): response is GetModelInfoDefaultResponse;\nexport function isUnexpected(\n response: GetEmbeddings200Response | GetEmbeddingsDefaultResponse,\n): response is GetEmbeddingsDefaultResponse;\nexport function isUnexpected(\n response: GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse,\n): response is GetImageEmbeddingsDefaultResponse;\nexport function isUnexpected(\n response:\n | GetChatCompletions200Response\n | GetChatCompletionsDefaultResponse\n | GetModelInfo200Response\n | GetModelInfoDefaultResponse\n | GetEmbeddings200Response\n | GetEmbeddingsDefaultResponse\n | GetImageEmbeddings200Response\n | GetImageEmbeddingsDefaultResponse,\n): response is\n | GetChatCompletionsDefaultResponse\n | GetModelInfoDefaultResponse\n | GetEmbeddingsDefaultResponse\n | GetImageEmbeddingsDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (\n let i = candidateParts.length - 1, j = pathParts.length - 1;\n i >= 1 && j >= 1;\n i--, j--\n ) {\n if (\n candidateParts[i]?.startsWith(\"{\") &&\n candidateParts[i]?.indexOf(\"}\") !== -1\n ) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(\n `${candidateParts[i]?.slice(start, end)}`,\n ).test(pathParts[j] || \"\");\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { ClientOptions } from "@azure-rest/core-client";
2
- import { TokenCredential, KeyCredential } from "@azure/core-auth";
3
- import { ModelClient } from "./clientDefinitions.js";
1
+ import type { ClientOptions } from "@azure-rest/core-client";
2
+ import type { TokenCredential, KeyCredential } from "@azure/core-auth";
3
+ import type { ModelClient } from "./clientDefinitions.js";
4
4
  /** The optional parameters for the client */
5
5
  export interface ModelClientOptions extends ClientOptions {
6
6
  /** The api version option of the client */
@@ -1 +1 @@
1
- {"version":3,"file":"modelClient.d.ts","sourceRoot":"","sources":["../../src/modelClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAmB,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,6CAA6C;AAC7C,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,eAAe,GAAG,aAAa,EAC5C,EAAE,UAAiC,EAAE,GAAG,OAAO,EAAE,GAAE,kBAAuB,GACzE,WAAW,CAwDb"}
1
+ {"version":3,"file":"modelClient.d.ts","sourceRoot":"","sources":["../../src/modelClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,6CAA6C;AAC7C,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,eAAe,GAAG,aAAa,EAC5C,EAAE,UAAiC,EAAE,GAAG,OAAO,EAAE,GAAE,kBAAuB,GACzE,WAAW,CAwDb"}
@@ -15,7 +15,7 @@ export default function createClient(endpointParam, credentials, _a = {}) {
15
15
  var _b, _c, _d, _e, _f, _g, _h, _j;
16
16
  var { apiVersion = "2024-05-01-preview" } = _a, options = __rest(_a, ["apiVersion"]);
17
17
  const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`;
18
- const userAgentInfo = `azsdk-js-ai-inference/1.0.0-beta.2`;
18
+ const userAgentInfo = `azsdk-js-ai-inference/1.0.0-beta.3`;
19
19
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
20
20
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
21
21
  : `${userAgentInfo}`;