@azure-rest/ai-inference 1.0.0-beta.1

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 (154) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +429 -0
  4. package/dist/browser/clientDefinitions.d.ts +29 -0
  5. package/dist/browser/clientDefinitions.d.ts.map +1 -0
  6. package/dist/browser/clientDefinitions.js +4 -0
  7. package/dist/browser/clientDefinitions.js.map +1 -0
  8. package/dist/browser/index.d.ts +10 -0
  9. package/dist/browser/index.d.ts.map +1 -0
  10. package/dist/browser/index.js +12 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/isUnexpected.d.ts +4 -0
  13. package/dist/browser/isUnexpected.d.ts.map +1 -0
  14. package/dist/browser/isUnexpected.js +72 -0
  15. package/dist/browser/isUnexpected.js.map +1 -0
  16. package/dist/browser/logger.d.ts +2 -0
  17. package/dist/browser/logger.d.ts.map +1 -0
  18. package/dist/browser/logger.js +5 -0
  19. package/dist/browser/logger.js.map +1 -0
  20. package/dist/browser/modelClient.d.ts +11 -0
  21. package/dist/browser/modelClient.d.ts.map +1 -0
  22. package/dist/browser/modelClient.js +40 -0
  23. package/dist/browser/modelClient.js.map +1 -0
  24. package/dist/browser/models.d.ts +164 -0
  25. package/dist/browser/models.d.ts.map +1 -0
  26. package/dist/browser/models.js +4 -0
  27. package/dist/browser/models.js.map +1 -0
  28. package/dist/browser/outputModels.d.ts +114 -0
  29. package/dist/browser/outputModels.d.ts.map +1 -0
  30. package/dist/browser/outputModels.js +4 -0
  31. package/dist/browser/outputModels.js.map +1 -0
  32. package/dist/browser/package.json +3 -0
  33. package/dist/browser/parameters.d.ts +33 -0
  34. package/dist/browser/parameters.d.ts.map +1 -0
  35. package/dist/browser/parameters.js +4 -0
  36. package/dist/browser/parameters.js.map +1 -0
  37. package/dist/browser/responses.d.ts +32 -0
  38. package/dist/browser/responses.d.ts.map +1 -0
  39. package/dist/browser/responses.js +4 -0
  40. package/dist/browser/responses.js.map +1 -0
  41. package/dist/commonjs/clientDefinitions.d.ts +29 -0
  42. package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
  43. package/dist/commonjs/clientDefinitions.js +5 -0
  44. package/dist/commonjs/clientDefinitions.js.map +1 -0
  45. package/dist/commonjs/index.d.ts +10 -0
  46. package/dist/commonjs/index.d.ts.map +1 -0
  47. package/dist/commonjs/index.js +15 -0
  48. package/dist/commonjs/index.js.map +1 -0
  49. package/dist/commonjs/isUnexpected.d.ts +4 -0
  50. package/dist/commonjs/isUnexpected.d.ts.map +1 -0
  51. package/dist/commonjs/isUnexpected.js +76 -0
  52. package/dist/commonjs/isUnexpected.js.map +1 -0
  53. package/dist/commonjs/logger.d.ts +2 -0
  54. package/dist/commonjs/logger.d.ts.map +1 -0
  55. package/dist/commonjs/logger.js +8 -0
  56. package/dist/commonjs/logger.js.map +1 -0
  57. package/dist/commonjs/modelClient.d.ts +11 -0
  58. package/dist/commonjs/modelClient.d.ts.map +1 -0
  59. package/dist/commonjs/modelClient.js +43 -0
  60. package/dist/commonjs/modelClient.js.map +1 -0
  61. package/dist/commonjs/models.d.ts +164 -0
  62. package/dist/commonjs/models.d.ts.map +1 -0
  63. package/dist/commonjs/models.js +5 -0
  64. package/dist/commonjs/models.js.map +1 -0
  65. package/dist/commonjs/outputModels.d.ts +114 -0
  66. package/dist/commonjs/outputModels.d.ts.map +1 -0
  67. package/dist/commonjs/outputModels.js +5 -0
  68. package/dist/commonjs/outputModels.js.map +1 -0
  69. package/dist/commonjs/package.json +3 -0
  70. package/dist/commonjs/parameters.d.ts +33 -0
  71. package/dist/commonjs/parameters.d.ts.map +1 -0
  72. package/dist/commonjs/parameters.js +5 -0
  73. package/dist/commonjs/parameters.js.map +1 -0
  74. package/dist/commonjs/responses.d.ts +32 -0
  75. package/dist/commonjs/responses.d.ts.map +1 -0
  76. package/dist/commonjs/responses.js +5 -0
  77. package/dist/commonjs/responses.js.map +1 -0
  78. package/dist/commonjs/tsdoc-metadata.json +11 -0
  79. package/dist/esm/clientDefinitions.d.ts +29 -0
  80. package/dist/esm/clientDefinitions.d.ts.map +1 -0
  81. package/dist/esm/clientDefinitions.js +4 -0
  82. package/dist/esm/clientDefinitions.js.map +1 -0
  83. package/dist/esm/index.d.ts +10 -0
  84. package/dist/esm/index.d.ts.map +1 -0
  85. package/dist/esm/index.js +12 -0
  86. package/dist/esm/index.js.map +1 -0
  87. package/dist/esm/isUnexpected.d.ts +4 -0
  88. package/dist/esm/isUnexpected.d.ts.map +1 -0
  89. package/dist/esm/isUnexpected.js +72 -0
  90. package/dist/esm/isUnexpected.js.map +1 -0
  91. package/dist/esm/logger.d.ts +2 -0
  92. package/dist/esm/logger.d.ts.map +1 -0
  93. package/dist/esm/logger.js +5 -0
  94. package/dist/esm/logger.js.map +1 -0
  95. package/dist/esm/modelClient.d.ts +11 -0
  96. package/dist/esm/modelClient.d.ts.map +1 -0
  97. package/dist/esm/modelClient.js +40 -0
  98. package/dist/esm/modelClient.js.map +1 -0
  99. package/dist/esm/models.d.ts +164 -0
  100. package/dist/esm/models.d.ts.map +1 -0
  101. package/dist/esm/models.js +4 -0
  102. package/dist/esm/models.js.map +1 -0
  103. package/dist/esm/outputModels.d.ts +114 -0
  104. package/dist/esm/outputModels.d.ts.map +1 -0
  105. package/dist/esm/outputModels.js +4 -0
  106. package/dist/esm/outputModels.js.map +1 -0
  107. package/dist/esm/package.json +3 -0
  108. package/dist/esm/parameters.d.ts +33 -0
  109. package/dist/esm/parameters.d.ts.map +1 -0
  110. package/dist/esm/parameters.js +4 -0
  111. package/dist/esm/parameters.js.map +1 -0
  112. package/dist/esm/responses.d.ts +32 -0
  113. package/dist/esm/responses.d.ts.map +1 -0
  114. package/dist/esm/responses.js +4 -0
  115. package/dist/esm/responses.js.map +1 -0
  116. package/dist/react-native/clientDefinitions.d.ts +29 -0
  117. package/dist/react-native/clientDefinitions.d.ts.map +1 -0
  118. package/dist/react-native/clientDefinitions.js +4 -0
  119. package/dist/react-native/clientDefinitions.js.map +1 -0
  120. package/dist/react-native/index.d.ts +10 -0
  121. package/dist/react-native/index.d.ts.map +1 -0
  122. package/dist/react-native/index.js +12 -0
  123. package/dist/react-native/index.js.map +1 -0
  124. package/dist/react-native/isUnexpected.d.ts +4 -0
  125. package/dist/react-native/isUnexpected.d.ts.map +1 -0
  126. package/dist/react-native/isUnexpected.js +72 -0
  127. package/dist/react-native/isUnexpected.js.map +1 -0
  128. package/dist/react-native/logger.d.ts +2 -0
  129. package/dist/react-native/logger.d.ts.map +1 -0
  130. package/dist/react-native/logger.js +5 -0
  131. package/dist/react-native/logger.js.map +1 -0
  132. package/dist/react-native/modelClient.d.ts +11 -0
  133. package/dist/react-native/modelClient.d.ts.map +1 -0
  134. package/dist/react-native/modelClient.js +40 -0
  135. package/dist/react-native/modelClient.js.map +1 -0
  136. package/dist/react-native/models.d.ts +164 -0
  137. package/dist/react-native/models.d.ts.map +1 -0
  138. package/dist/react-native/models.js +4 -0
  139. package/dist/react-native/models.js.map +1 -0
  140. package/dist/react-native/outputModels.d.ts +114 -0
  141. package/dist/react-native/outputModels.d.ts.map +1 -0
  142. package/dist/react-native/outputModels.js +4 -0
  143. package/dist/react-native/outputModels.js.map +1 -0
  144. package/dist/react-native/package.json +3 -0
  145. package/dist/react-native/parameters.d.ts +33 -0
  146. package/dist/react-native/parameters.d.ts.map +1 -0
  147. package/dist/react-native/parameters.js +4 -0
  148. package/dist/react-native/parameters.js.map +1 -0
  149. package/dist/react-native/responses.d.ts +32 -0
  150. package/dist/react-native/responses.d.ts.map +1 -0
  151. package/dist/react-native/responses.js +4 -0
  152. package/dist/react-native/responses.js.map +1 -0
  153. package/package.json +148 -0
  154. package/review/ai-inference.api.md +343 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Release History
2
+
3
+ ## 1.0.0-beta.1 (2024-06-30)
4
+
5
+ ### Features Added
6
+ - This is the initial beta release for the Azure AI Inference SDK, which is a common API supporting Azure AI Inference models.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,429 @@
1
+ # Azure Inference REST client library for JavaScript
2
+
3
+ Inference API for Azure-supported AI models
4
+
5
+ **Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
6
+
7
+ Key links:
8
+
9
+ - [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-inference-rest)
10
+ - [Package (NPM)](https://aka.ms/npm-azure-rest-ai-inference)
11
+ - [API reference documentation](https://aka.ms/AAp1kxa)
12
+ - [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/ai/ai-inference-rest/samples)
13
+
14
+ ## Getting started
15
+
16
+ ```javascript
17
+ import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
18
+ import { AzureKeyCredential } from "@azure/core-auth";
19
+ const client = new ModelClient(
20
+ "https://<Azure Model endpoint>",
21
+ new AzureKeyCredential("<Azure API key>")
22
+ );
23
+
24
+ const response = await client.path("/chat/completions").post({
25
+ body: {
26
+ messages: [
27
+ {role: "user", content: "How many feet are in a mile?"},
28
+ ],
29
+ }
30
+ });
31
+
32
+ if(isUnexpected(response)) {
33
+ throw response.body.error;
34
+ }
35
+ console.log(response.body.choices[0].message.content);
36
+ ```
37
+
38
+ ### Currently supported environments
39
+
40
+ - LTS versions of Node.js
41
+
42
+ ### Prerequisites
43
+
44
+ - You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.
45
+
46
+ ### Install the `@azure-rest/ai-inference` package
47
+
48
+ Install the Azure ModelClient REST client REST client library for JavaScript with `npm`:
49
+
50
+ ```bash
51
+ npm install @azure-rest/ai-inference
52
+ ```
53
+
54
+ ### Create and authenticate a `ModelClient`
55
+ #### Using an API Key from Azure
56
+
57
+ 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:
58
+
59
+ ```bash
60
+ npm install @azure/core-auth
61
+ ```
62
+
63
+ Use the [Azure Portal][azure_portal] to browse to your Model deployment and retrieve an API key.
64
+
65
+ **Note:** Sometimes the API key is referred to as a "subscription key" or "subscription API key."
66
+
67
+ Once you have an API key and endpoint, you can use the `AzureKeyCredential` class to authenticate the client as follows:
68
+
69
+ ```javascript
70
+ import ModelClient from "@azure-rest/ai-inference";
71
+ import { AzureKeyCredential } from "@azure/core-auth";
72
+
73
+ const client = new ModelClient("<endpoint>", new AzureKeyCredential("<API key>"));
74
+ ```
75
+
76
+ #### Using an Azure Active Directory Credential
77
+
78
+ You can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below,
79
+ or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:
80
+
81
+ ```bash
82
+ npm install @azure/identity
83
+ ```
84
+
85
+ Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
86
+
87
+ ```javascript
88
+ import ModelClient from "@azure-rest/ai-inference";
89
+ import { DefaultAzureCredential } from "@azure/identity";
90
+
91
+ const client = new ModelClient("<endpoint>", new DefaultAzureCredential());
92
+ ```
93
+
94
+ ## Key concepts
95
+
96
+ The main concept to understand is [Completions][azure_openai_completions_docs]. Briefly explained, completions provides its functionality in the form of a text prompt, which by using a specific [model](https://learn.microsoft.com/azure/cognitive-services/openai/concepts/models), will then attempt to match the context and patterns, providing an output text. The following code snippet provides a rough overview:
97
+
98
+ ```javascript
99
+ import ModelClient, { isUnexpected } from "@azure-rest/ai-inference";
100
+ import { AzureKeyCredential } from "@azure/core-auth";
101
+
102
+ async function main(){
103
+ const client = new ModelClient(
104
+ "https://your-model-endpoint/",
105
+ new AzureKeyCredential("your-model-api-key"));
106
+
107
+ const response = await client.path("/chat/completions").post({
108
+ body: {
109
+ messages: [
110
+ {role: "user", content: "Hello, world!"},
111
+ ],
112
+ }
113
+ });
114
+
115
+ if(isUnexpected(response)) {
116
+ throw response.body.error;
117
+ }
118
+
119
+ console.log(response.body.choices[0].message.content);
120
+ }
121
+
122
+ main().catch((err) => {
123
+ console.error("The sample encountered an error:", err);
124
+ });
125
+ ```
126
+
127
+ ## Examples
128
+
129
+ ### Generate Chatbot Response
130
+
131
+ Streaming chat with the Inference SDK requires core streaming support; to enable this support, please install the `@azure/core-sse` package:
132
+
133
+ ```bash
134
+ npm install @azure/core-sse
135
+ ```
136
+
137
+ This example authenticates using a DefaultAzureCredential, then generates chat responses to input chat question and messages.
138
+
139
+ ```javascript
140
+ import ModelClient from "@azure-rest/ai-inference";
141
+ import { DefaultAzureCredential } from "@azure/identity";
142
+ import { createSseStream } from "@azure/core-sse";
143
+
144
+ async function main(){
145
+ const endpoint = "https://myaccount.openai.azure.com/";
146
+ const client = new ModelClient(endpoint, new DefaultAzureCredential());
147
+
148
+ const messages = [
149
+ // NOTE: "system" role is not supported on all Azure Models
150
+ { role: "system", content: "You are a helpful assistant. You will talk like a pirate." },
151
+ { role: "user", content: "Can you help me?" },
152
+ { role: "assistant", content: "Arrrr! Of course, me hearty! What can I do for ye?" },
153
+ { role: "user", content: "What's the best way to train a parrot?" },
154
+ ];
155
+
156
+ console.log(`Messages: ${messages.map((m) => m.content).join("\n")}`);
157
+
158
+ const response = await client.path("/chat/completions").post({
159
+ body: {
160
+ messages,
161
+ stream: true,
162
+ max_tokens: 128
163
+ }
164
+ }).asNodeStream();
165
+
166
+ const stream = response.body;
167
+ if (!stream) {
168
+ throw new Error("The response stream is undefined");
169
+ }
170
+
171
+ if (response.status !== "200") {
172
+ throw new Error(`Failed to get chat completions: ${response.body.error}`);
173
+ }
174
+
175
+ const sses = createSseStream(stream);
176
+
177
+ for await (const event of sses) {
178
+ if (event.data === "[DONE]") {
179
+ return;
180
+ }
181
+ for (const choice of (JSON.parse(event.data)).choices) {
182
+ console.log(choice.delta?.content ?? "");
183
+ }
184
+ }
185
+ }
186
+
187
+ main().catch((err) => {
188
+ console.error("The sample encountered an error:", err);
189
+ });
190
+ ```
191
+
192
+ ### Generate Multiple Completions With Subscription Key
193
+
194
+ This example generates text responses to input prompts using an Azure subscription key
195
+
196
+ ```javascript
197
+ import ModelClient from "@azure-rest/ai-inference";
198
+ import { AzureKeyCredential } from "@azure/core-auth";
199
+
200
+ async function main(){
201
+ // Replace with your Model API key
202
+ const key = "YOUR_MODEL_API_KEY";
203
+ const endpoint = "https://your-model-endpoint/";
204
+ const client = new ModelClient(endpoint, new AzureKeyCredential(key));
205
+
206
+ const messages = [
207
+ { role: "user", content: "How are you today?" },
208
+ { role: "user", content: "What is inference in the context of AI?" },
209
+ { role: "user", content: "Why do children love dinosaurs?" },
210
+ { 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
+
214
+ let promptIndex = 0;
215
+ const response = await client.path("/chat/completions").post({
216
+ body: {
217
+ messages
218
+ }
219
+ });
220
+
221
+ if(response.status !== "200") {
222
+ throw response.body.error;
223
+ }
224
+ for (const choice of response.body.choices) {
225
+ const completion = choice.message.content;
226
+ console.log(`Input: ${examplePrompts[promptIndex++]}`);
227
+ console.log(`Chatbot: ${completion}`);
228
+ }
229
+ }
230
+
231
+ main().catch((err) => {
232
+ console.error("The sample encountered an error:", err);
233
+ });
234
+ ```
235
+
236
+ ### Summarize Text with Completion
237
+
238
+ This example generates a summarization of the given input prompt.
239
+
240
+ ```javascript
241
+ import ModelClient from "@azure-rest/ai-inference";
242
+ import { DefaultAzureCredential } from "@azure/identity";
243
+
244
+ async function main(){
245
+ const endpoint = "https://your-model-endpoint/";
246
+ const client = new ModelClient(endpoint, new DefaultAzureCredential());
247
+
248
+ const textToSummarize = `
249
+ Two independent experiments reported their results this morning at CERN, Europe's high-energy physics laboratory near Geneva in Switzerland. Both show convincing evidence of a new boson particle weighing around 125 gigaelectronvolts, which so far fits predictions of the Higgs previously made by theoretical physicists.
250
+
251
+ ""As a layman I would say: 'I think we have it'. Would you agree?"" Rolf-Dieter Heuer, CERN's director-general, asked the packed auditorium. The physicists assembled there burst into applause.
252
+ :`;
253
+
254
+ const summarizationPrompt = [`
255
+ Summarize the following text.
256
+
257
+ Text:
258
+ """"""
259
+ ${textToSummarize}
260
+ """"""
261
+
262
+ Summary:
263
+ `];
264
+
265
+ console.log(`Input: ${summarizationPrompt}`);
266
+
267
+ const response = await client.path("/chat/completions").post({
268
+ body: {
269
+ messages: [
270
+ { role: "user", content: summarizationPrompt }
271
+ ],
272
+ max_tokens: 64
273
+ }
274
+ });
275
+
276
+ if(response.status !== "200") {
277
+ throw response.body.error;
278
+ }
279
+ const completion = response.body.choices[0].message.content;
280
+ console.log(`Summarization: ${completion}`);
281
+ }
282
+
283
+ main().catch((err) => {
284
+ console.error("The sample encountered an error:", err);
285
+ });
286
+ ```
287
+
288
+ ### Use chat tools
289
+
290
+ **Tools** extend chat completions by allowing an assistant to invoke defined functions and other capabilities in the
291
+ process of fulfilling a chat completions request. To use chat tools, start by defining a function tool:
292
+
293
+ ```js
294
+ 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
+ },
308
+ },
309
+ required: ["location"],
310
+ },
311
+ };
312
+ ```
313
+
314
+ With the tool defined, include that new definition in the options for a chat completions request:
315
+
316
+ ```js
317
+ const messages = [{ role: "user", content: "What is the weather like in Boston?" }];
318
+ const tools = [
319
+ {
320
+ type: "function",
321
+ function: getCurrentWeather,
322
+ },
323
+ ];
324
+ const result = await client.path("/chat/completions").post({
325
+ body: {
326
+ messages,
327
+ tools
328
+ }
329
+ });
330
+ ```
331
+
332
+ When the assistant decides that one or more tools should be used, the response message includes one or more "tool
333
+ calls" that must all be resolved via "tool messages" on the subsequent request. This resolution of tool calls into
334
+ new request messages can be thought of as a sort of "callback" for chat completions.
335
+
336
+ ```js
337
+ // Purely for convenience and clarity, this function handles tool call responses.
338
+ 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}`);
349
+ }
350
+ ```
351
+
352
+ To provide tool call resolutions to the assistant to allow the request to continue, provide all prior historical
353
+ context -- including the original system and user messages, the response from the assistant that included the tool
354
+ calls, and the tool messages that resolved each of those tools -- when making a subsequent request.
355
+
356
+ ```js
357
+ const choice = result.choices[0];
358
+ const responseMessage = choice.message;
359
+ if (responseMessage?.role === "assistant") {
360
+ const requestedToolCalls = responseMessage?.toolCalls;
361
+ if (requestedToolCalls?.length) {
362
+ const toolCallResolutionMessages = [
363
+ ...messages,
364
+ responseMessage,
365
+ ...requestedToolCalls.map(applyToolCall),
366
+ ];
367
+ const toolCallResolutionResult = await client.path("/chat/completions").post({
368
+ body: {
369
+ messages: toolCallResolutionMessages
370
+ }
371
+ });
372
+ // continue handling the response as normal
373
+ }
374
+ }
375
+ ```
376
+
377
+ ### Chat with images (using models supporting image chat, such as gpt-4o)
378
+
379
+ Some Azure models allow you to use images as input components into chat completions.
380
+
381
+ To do this, provide distinct content items on the user message(s) for the chat completions request:
382
+
383
+ ```js
384
+ const url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
385
+ const messages = [{
386
+ role: "user", content: [{
387
+ type: "image_url",
388
+ image_url: {
389
+ url,
390
+ detail: "auto"
391
+ }
392
+ }]},
393
+ {role: "user", content: "describe the image"}];
394
+ ```
395
+
396
+ Chat Completions will then proceed as usual, though the model may report the more informative `finish_details` in lieu
397
+ of `finish_reason`:
398
+
399
+ ```js
400
+ const response = await client.path("/chat/completions").post({
401
+ body: {
402
+ messages
403
+ });
404
+ console.log(`Chatbot: ${response.choices[0].message?.content}`);
405
+ ```
406
+
407
+ ## Troubleshooting
408
+
409
+ ### Logging
410
+
411
+ Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
412
+
413
+ ```javascript
414
+ const { setLogLevel } = require("@azure/logger");
415
+
416
+ setLogLevel("info");
417
+ ```
418
+
419
+ 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).
420
+
421
+ <!-- LINKS -->
422
+ [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
423
+ [azure_openai_completions_docs]: https://learn.microsoft.com/azure/cognitive-services/openai/how-to/completions
424
+ [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
425
+ [azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
426
+ [azure_core_auth]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-auth
427
+ [register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
428
+ [azure_cli]: https://docs.microsoft.com/cli/azure
429
+ [azure_portal]: https://portal.azure.com
@@ -0,0 +1,29 @@
1
+ import { GetChatCompletionsParameters, GetModelInfoParameters } from "./parameters.js";
2
+ import { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse } from "./responses.js";
3
+ import { Client, StreamableMethod } from "@azure-rest/core-client";
4
+ export interface GetChatCompletions {
5
+ /**
6
+ * Gets chat completions for the provided chat messages.
7
+ * Completions support a wide variety of tasks and generate text that continues from or "completes"
8
+ * provided prompt data. The method makes a REST API call to the `/chat/completions` route
9
+ * on the given endpoint.
10
+ */
11
+ post(options?: GetChatCompletionsParameters): StreamableMethod<GetChatCompletions200Response | GetChatCompletionsDefaultResponse>;
12
+ }
13
+ export interface GetModelInfo {
14
+ /**
15
+ * Returns information about the AI model.
16
+ * The method makes a REST API call to the `/info` route on the given endpoint.
17
+ */
18
+ get(options?: GetModelInfoParameters): StreamableMethod<GetModelInfo200Response | GetModelInfoDefaultResponse>;
19
+ }
20
+ export interface Routes {
21
+ /** Resource for '/chat/completions' has methods for the following verbs: post */
22
+ (path: "/chat/completions"): GetChatCompletions;
23
+ /** Resource for '/info' has methods for the following verbs: get */
24
+ (path: "/info"): GetModelInfo;
25
+ }
26
+ export type ModelClient = Client & {
27
+ path: Routes;
28
+ };
29
+ //# sourceMappingURL=clientDefinitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientDefinitions.d.ts","sourceRoot":"","sources":["../../src/clientDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC5B,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,CACjB,6BAA6B,GAAG,iCAAiC,CAClE,CAAC;CACH;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,MAAM;IACrB,iFAAiF;IACjF,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC;IAChD,oEAAoE;IACpE,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAAC;CAC/B;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export {};
4
+ //# sourceMappingURL=clientDefinitions.js.map
@@ -0,0 +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} from \"./parameters.js\";\nimport {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\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<\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 */\n get(\n options?: GetModelInfoParameters,\n ): StreamableMethod<GetModelInfo200Response | GetModelInfoDefaultResponse>;\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}\n\nexport type ModelClient = Client & {\n path: Routes;\n};\n"]}
@@ -0,0 +1,10 @@
1
+ import ModelClient from "./modelClient.js";
2
+ export * from "./modelClient.js";
3
+ export * from "./parameters.js";
4
+ export * from "./responses.js";
5
+ export * from "./clientDefinitions.js";
6
+ export * from "./isUnexpected.js";
7
+ export * from "./models.js";
8
+ export * from "./outputModels.js";
9
+ export default ModelClient;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAE3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAElC,eAAe,WAAW,CAAC"}
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import ModelClient from "./modelClient.js";
4
+ export * from "./modelClient.js";
5
+ export * from "./parameters.js";
6
+ export * from "./responses.js";
7
+ export * from "./clientDefinitions.js";
8
+ export * from "./isUnexpected.js";
9
+ export * from "./models.js";
10
+ export * from "./outputModels.js";
11
+ export default ModelClient;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAE3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAElC,eAAe,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport ModelClient from \"./modelClient.js\";\n\nexport * from \"./modelClient.js\";\nexport * from \"./parameters.js\";\nexport * from \"./responses.js\";\nexport * from \"./clientDefinitions.js\";\nexport * from \"./isUnexpected.js\";\nexport * from \"./models.js\";\nexport * from \"./outputModels.js\";\n\nexport default ModelClient;\n"]}
@@ -0,0 +1,4 @@
1
+ import { GetChatCompletions200Response, GetChatCompletionsDefaultResponse, GetModelInfo200Response, GetModelInfoDefaultResponse } from "./responses.js";
2
+ export declare function isUnexpected(response: GetChatCompletions200Response | GetChatCompletionsDefaultResponse): response is GetChatCompletionsDefaultResponse;
3
+ export declare function isUnexpected(response: GetModelInfo200Response | GetModelInfoDefaultResponse): response is GetModelInfoDefaultResponse;
4
+ //# sourceMappingURL=isUnexpected.d.ts.map
@@ -0,0 +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,EAC5B,MAAM,gBAAgB,CAAC;AAOxB,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"}
@@ -0,0 +1,72 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ const responseMap = {
4
+ "POST /chat/completions": ["200"],
5
+ "GET /info": ["200"],
6
+ };
7
+ export function isUnexpected(response) {
8
+ const lroOriginal = response.headers["x-ms-original-url"];
9
+ const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
10
+ const method = response.request.method;
11
+ let pathDetails = responseMap[`${method} ${url.pathname}`];
12
+ if (!pathDetails) {
13
+ pathDetails = getParametrizedPathSuccess(method, url.pathname);
14
+ }
15
+ return !pathDetails.includes(response.status);
16
+ }
17
+ function getParametrizedPathSuccess(method, path) {
18
+ var _a, _b, _c, _d;
19
+ const pathParts = path.split("/");
20
+ // Traverse list to match the longest candidate
21
+ // matchedLen: the length of candidate path
22
+ // matchedValue: the matched status code array
23
+ let matchedLen = -1, matchedValue = [];
24
+ // Iterate the responseMap to find a match
25
+ for (const [key, value] of Object.entries(responseMap)) {
26
+ // Extracting the path from the map key which is in format
27
+ // GET /path/foo
28
+ if (!key.startsWith(method)) {
29
+ continue;
30
+ }
31
+ const candidatePath = getPathFromMapKey(key);
32
+ // Get each part of the url path
33
+ const candidateParts = candidatePath.split("/");
34
+ // track if we have found a match to return the values found.
35
+ let found = true;
36
+ for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
37
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
38
+ ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
39
+ const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
40
+ // If the current part of the candidate is a "template" part
41
+ // Try to use the suffix of pattern to match the path
42
+ // {guid} ==> $
43
+ // {guid}:export ==> :export$
44
+ const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
45
+ if (!isMatched) {
46
+ found = false;
47
+ break;
48
+ }
49
+ continue;
50
+ }
51
+ // If the candidate part is not a template and
52
+ // the parts don't match mark the candidate as not found
53
+ // to move on with the next candidate path.
54
+ if (candidateParts[i] !== pathParts[j]) {
55
+ found = false;
56
+ break;
57
+ }
58
+ }
59
+ // We finished evaluating the current candidate parts
60
+ // Update the matched value if and only if we found the longer pattern
61
+ if (found && candidatePath.length > matchedLen) {
62
+ matchedLen = candidatePath.length;
63
+ matchedValue = value;
64
+ }
65
+ }
66
+ return matchedValue;
67
+ }
68
+ function getPathFromMapKey(mapKey) {
69
+ const pathStart = mapKey.indexOf("/");
70
+ return mapKey.slice(pathStart);
71
+ }
72
+ //# sourceMappingURL=isUnexpected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n GetChatCompletions200Response,\n GetChatCompletionsDefaultResponse,\n GetModelInfo200Response,\n GetModelInfoDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /chat/completions\": [\"200\"],\n \"GET /info\": [\"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:\n | GetChatCompletions200Response\n | GetChatCompletionsDefaultResponse\n | GetModelInfo200Response\n | GetModelInfoDefaultResponse,\n): response is GetChatCompletionsDefaultResponse | GetModelInfoDefaultResponse {\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"]}
@@ -0,0 +1,2 @@
1
+ export declare const logger: import("@azure/logger").AzureLogger;
2
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { createClientLogger } from "@azure/logger";
4
+ export const logger = createClientLogger("ai-inference");
5
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"ai-inference\");\n"]}
@@ -0,0 +1,11 @@
1
+ import { ClientOptions } from "@azure-rest/core-client";
2
+ import { TokenCredential, KeyCredential } from "@azure/core-auth";
3
+ import { ModelClient } from "./clientDefinitions.js";
4
+ /**
5
+ * Initialize a new instance of `ModelClient`
6
+ * @param endpointParam - The parameter endpointParam
7
+ * @param credentials - uniquely identify client credential
8
+ * @param options - the parameter for all optional parameters
9
+ */
10
+ export default function createClient(endpointParam: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): ModelClient;
11
+ //# sourceMappingURL=modelClient.d.ts.map