@azure-rest/ai-inference 1.0.0-alpha.20241111.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 (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -0
  3. package/dist/browser/clientDefinitions.d.ts +47 -0
  4. package/dist/browser/clientDefinitions.d.ts.map +1 -0
  5. package/dist/browser/clientDefinitions.js +4 -0
  6. package/dist/browser/clientDefinitions.js.map +1 -0
  7. package/dist/browser/constants.d.ts +2 -0
  8. package/dist/browser/constants.d.ts.map +1 -0
  9. package/dist/browser/constants.js +4 -0
  10. package/dist/browser/constants.js.map +1 -0
  11. package/dist/browser/index.d.ts +10 -0
  12. package/dist/browser/index.d.ts.map +1 -0
  13. package/dist/browser/index.js +12 -0
  14. package/dist/browser/index.js.map +1 -0
  15. package/dist/browser/isUnexpected.d.ts +6 -0
  16. package/dist/browser/isUnexpected.d.ts.map +1 -0
  17. package/dist/browser/isUnexpected.js +73 -0
  18. package/dist/browser/isUnexpected.js.map +1 -0
  19. package/dist/browser/logger.d.ts +2 -0
  20. package/dist/browser/logger.d.ts.map +1 -0
  21. package/dist/browser/logger.js +5 -0
  22. package/dist/browser/logger.js.map +1 -0
  23. package/dist/browser/modelClient.d.ts +16 -0
  24. package/dist/browser/modelClient.d.ts.map +1 -0
  25. package/dist/browser/modelClient.js +61 -0
  26. package/dist/browser/modelClient.js.map +1 -0
  27. package/dist/browser/models.d.ts +179 -0
  28. package/dist/browser/models.d.ts.map +1 -0
  29. package/dist/browser/models.js +4 -0
  30. package/dist/browser/models.js.map +1 -0
  31. package/dist/browser/outputModels.d.ts +140 -0
  32. package/dist/browser/outputModels.d.ts.map +1 -0
  33. package/dist/browser/outputModels.js +4 -0
  34. package/dist/browser/outputModels.js.map +1 -0
  35. package/dist/browser/package.json +3 -0
  36. package/dist/browser/parameters.d.ts +82 -0
  37. package/dist/browser/parameters.d.ts.map +1 -0
  38. package/dist/browser/parameters.js +4 -0
  39. package/dist/browser/parameters.js.map +1 -0
  40. package/dist/browser/responses.d.ts +60 -0
  41. package/dist/browser/responses.d.ts.map +1 -0
  42. package/dist/browser/responses.js +4 -0
  43. package/dist/browser/responses.js.map +1 -0
  44. package/dist/browser/tracingHelper.d.ts +9 -0
  45. package/dist/browser/tracingHelper.d.ts.map +1 -0
  46. package/dist/browser/tracingHelper.js +198 -0
  47. package/dist/browser/tracingHelper.js.map +1 -0
  48. package/dist/browser/tracingPolicy.d.ts +12 -0
  49. package/dist/browser/tracingPolicy.d.ts.map +1 -0
  50. package/dist/browser/tracingPolicy.js +68 -0
  51. package/dist/browser/tracingPolicy.js.map +1 -0
  52. package/dist/commonjs/clientDefinitions.d.ts +47 -0
  53. package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
  54. package/dist/commonjs/clientDefinitions.js +5 -0
  55. package/dist/commonjs/clientDefinitions.js.map +1 -0
  56. package/dist/commonjs/constants.d.ts +2 -0
  57. package/dist/commonjs/constants.d.ts.map +1 -0
  58. package/dist/commonjs/constants.js +7 -0
  59. package/dist/commonjs/constants.js.map +1 -0
  60. package/dist/commonjs/index.d.ts +10 -0
  61. package/dist/commonjs/index.d.ts.map +1 -0
  62. package/dist/commonjs/index.js +15 -0
  63. package/dist/commonjs/index.js.map +1 -0
  64. package/dist/commonjs/isUnexpected.d.ts +6 -0
  65. package/dist/commonjs/isUnexpected.d.ts.map +1 -0
  66. package/dist/commonjs/isUnexpected.js +76 -0
  67. package/dist/commonjs/isUnexpected.js.map +1 -0
  68. package/dist/commonjs/logger.d.ts +2 -0
  69. package/dist/commonjs/logger.d.ts.map +1 -0
  70. package/dist/commonjs/logger.js +8 -0
  71. package/dist/commonjs/logger.js.map +1 -0
  72. package/dist/commonjs/modelClient.d.ts +16 -0
  73. package/dist/commonjs/modelClient.d.ts.map +1 -0
  74. package/dist/commonjs/modelClient.js +64 -0
  75. package/dist/commonjs/modelClient.js.map +1 -0
  76. package/dist/commonjs/models.d.ts +179 -0
  77. package/dist/commonjs/models.d.ts.map +1 -0
  78. package/dist/commonjs/models.js +5 -0
  79. package/dist/commonjs/models.js.map +1 -0
  80. package/dist/commonjs/outputModels.d.ts +140 -0
  81. package/dist/commonjs/outputModels.d.ts.map +1 -0
  82. package/dist/commonjs/outputModels.js +5 -0
  83. package/dist/commonjs/outputModels.js.map +1 -0
  84. package/dist/commonjs/package.json +3 -0
  85. package/dist/commonjs/parameters.d.ts +82 -0
  86. package/dist/commonjs/parameters.d.ts.map +1 -0
  87. package/dist/commonjs/parameters.js +5 -0
  88. package/dist/commonjs/parameters.js.map +1 -0
  89. package/dist/commonjs/responses.d.ts +60 -0
  90. package/dist/commonjs/responses.d.ts.map +1 -0
  91. package/dist/commonjs/responses.js +5 -0
  92. package/dist/commonjs/responses.js.map +1 -0
  93. package/dist/commonjs/tracingHelper.d.ts +9 -0
  94. package/dist/commonjs/tracingHelper.d.ts.map +1 -0
  95. package/dist/commonjs/tracingHelper.js +205 -0
  96. package/dist/commonjs/tracingHelper.js.map +1 -0
  97. package/dist/commonjs/tracingPolicy.d.ts +12 -0
  98. package/dist/commonjs/tracingPolicy.d.ts.map +1 -0
  99. package/dist/commonjs/tracingPolicy.js +72 -0
  100. package/dist/commonjs/tracingPolicy.js.map +1 -0
  101. package/dist/commonjs/tsdoc-metadata.json +11 -0
  102. package/dist/esm/clientDefinitions.d.ts +47 -0
  103. package/dist/esm/clientDefinitions.d.ts.map +1 -0
  104. package/dist/esm/clientDefinitions.js +4 -0
  105. package/dist/esm/clientDefinitions.js.map +1 -0
  106. package/dist/esm/constants.d.ts +2 -0
  107. package/dist/esm/constants.d.ts.map +1 -0
  108. package/dist/esm/constants.js +4 -0
  109. package/dist/esm/constants.js.map +1 -0
  110. package/dist/esm/index.d.ts +10 -0
  111. package/dist/esm/index.d.ts.map +1 -0
  112. package/dist/esm/index.js +12 -0
  113. package/dist/esm/index.js.map +1 -0
  114. package/dist/esm/isUnexpected.d.ts +6 -0
  115. package/dist/esm/isUnexpected.d.ts.map +1 -0
  116. package/dist/esm/isUnexpected.js +73 -0
  117. package/dist/esm/isUnexpected.js.map +1 -0
  118. package/dist/esm/logger.d.ts +2 -0
  119. package/dist/esm/logger.d.ts.map +1 -0
  120. package/dist/esm/logger.js +5 -0
  121. package/dist/esm/logger.js.map +1 -0
  122. package/dist/esm/modelClient.d.ts +16 -0
  123. package/dist/esm/modelClient.d.ts.map +1 -0
  124. package/dist/esm/modelClient.js +61 -0
  125. package/dist/esm/modelClient.js.map +1 -0
  126. package/dist/esm/models.d.ts +179 -0
  127. package/dist/esm/models.d.ts.map +1 -0
  128. package/dist/esm/models.js +4 -0
  129. package/dist/esm/models.js.map +1 -0
  130. package/dist/esm/outputModels.d.ts +140 -0
  131. package/dist/esm/outputModels.d.ts.map +1 -0
  132. package/dist/esm/outputModels.js +4 -0
  133. package/dist/esm/outputModels.js.map +1 -0
  134. package/dist/esm/package.json +3 -0
  135. package/dist/esm/parameters.d.ts +82 -0
  136. package/dist/esm/parameters.d.ts.map +1 -0
  137. package/dist/esm/parameters.js +4 -0
  138. package/dist/esm/parameters.js.map +1 -0
  139. package/dist/esm/responses.d.ts +60 -0
  140. package/dist/esm/responses.d.ts.map +1 -0
  141. package/dist/esm/responses.js +4 -0
  142. package/dist/esm/responses.js.map +1 -0
  143. package/dist/esm/tracingHelper.d.ts +9 -0
  144. package/dist/esm/tracingHelper.d.ts.map +1 -0
  145. package/dist/esm/tracingHelper.js +198 -0
  146. package/dist/esm/tracingHelper.js.map +1 -0
  147. package/dist/esm/tracingPolicy.d.ts +12 -0
  148. package/dist/esm/tracingPolicy.d.ts.map +1 -0
  149. package/dist/esm/tracingPolicy.js +68 -0
  150. package/dist/esm/tracingPolicy.js.map +1 -0
  151. package/dist/react-native/clientDefinitions.d.ts +47 -0
  152. package/dist/react-native/clientDefinitions.d.ts.map +1 -0
  153. package/dist/react-native/clientDefinitions.js +4 -0
  154. package/dist/react-native/clientDefinitions.js.map +1 -0
  155. package/dist/react-native/constants.d.ts +2 -0
  156. package/dist/react-native/constants.d.ts.map +1 -0
  157. package/dist/react-native/constants.js +4 -0
  158. package/dist/react-native/constants.js.map +1 -0
  159. package/dist/react-native/index.d.ts +10 -0
  160. package/dist/react-native/index.d.ts.map +1 -0
  161. package/dist/react-native/index.js +12 -0
  162. package/dist/react-native/index.js.map +1 -0
  163. package/dist/react-native/isUnexpected.d.ts +6 -0
  164. package/dist/react-native/isUnexpected.d.ts.map +1 -0
  165. package/dist/react-native/isUnexpected.js +73 -0
  166. package/dist/react-native/isUnexpected.js.map +1 -0
  167. package/dist/react-native/logger.d.ts +2 -0
  168. package/dist/react-native/logger.d.ts.map +1 -0
  169. package/dist/react-native/logger.js +5 -0
  170. package/dist/react-native/logger.js.map +1 -0
  171. package/dist/react-native/modelClient.d.ts +16 -0
  172. package/dist/react-native/modelClient.d.ts.map +1 -0
  173. package/dist/react-native/modelClient.js +61 -0
  174. package/dist/react-native/modelClient.js.map +1 -0
  175. package/dist/react-native/models.d.ts +179 -0
  176. package/dist/react-native/models.d.ts.map +1 -0
  177. package/dist/react-native/models.js +4 -0
  178. package/dist/react-native/models.js.map +1 -0
  179. package/dist/react-native/outputModels.d.ts +140 -0
  180. package/dist/react-native/outputModels.d.ts.map +1 -0
  181. package/dist/react-native/outputModels.js +4 -0
  182. package/dist/react-native/outputModels.js.map +1 -0
  183. package/dist/react-native/package.json +3 -0
  184. package/dist/react-native/parameters.d.ts +82 -0
  185. package/dist/react-native/parameters.d.ts.map +1 -0
  186. package/dist/react-native/parameters.js +4 -0
  187. package/dist/react-native/parameters.js.map +1 -0
  188. package/dist/react-native/responses.d.ts +60 -0
  189. package/dist/react-native/responses.d.ts.map +1 -0
  190. package/dist/react-native/responses.js +4 -0
  191. package/dist/react-native/responses.js.map +1 -0
  192. package/dist/react-native/tracingHelper.d.ts +9 -0
  193. package/dist/react-native/tracingHelper.d.ts.map +1 -0
  194. package/dist/react-native/tracingHelper.js +198 -0
  195. package/dist/react-native/tracingHelper.js.map +1 -0
  196. package/dist/react-native/tracingPolicy.d.ts +12 -0
  197. package/dist/react-native/tracingPolicy.d.ts.map +1 -0
  198. package/dist/react-native/tracingPolicy.js +68 -0
  199. package/dist/react-native/tracingPolicy.js.map +1 -0
  200. package/package.json +141 -0
@@ -0,0 +1,82 @@
1
+ import type { RawHttpHeadersInput } from "@azure/core-rest-pipeline";
2
+ import type { RequestParameters } from "@azure-rest/core-client";
3
+ import type { ExtraParameters, ChatRequestMessage, ChatCompletionsResponseFormat, ChatCompletionsToolDefinition, ChatCompletionsToolSelectionPreset, ChatCompletionsNamedToolSelection, EmbeddingEncodingFormat, EmbeddingInputType, ImageEmbeddingInput } from "./models.js";
4
+ export interface GetChatCompletionsHeaders {
5
+ /**
6
+ * Controls what happens if extra parameters, undefined by the REST API,
7
+ * are passed in the JSON request payload.
8
+ * This sets the HTTP request header `extra-parameters`.
9
+ *
10
+ * Possible values: "error", "drop", "pass-through"
11
+ */
12
+ "extra-parameters"?: ExtraParameters;
13
+ }
14
+ export interface GetChatCompletionsBodyParam {
15
+ body?: {
16
+ messages: Array<ChatRequestMessage>;
17
+ frequency_penalty?: number;
18
+ stream?: boolean;
19
+ presence_penalty?: number;
20
+ temperature?: number;
21
+ top_p?: number;
22
+ max_tokens?: number;
23
+ response_format?: ChatCompletionsResponseFormat;
24
+ stop?: string[];
25
+ tools?: Array<ChatCompletionsToolDefinition>;
26
+ tool_choice?: ChatCompletionsToolSelectionPreset | ChatCompletionsNamedToolSelection;
27
+ seed?: number;
28
+ model?: string;
29
+ };
30
+ }
31
+ export interface GetChatCompletionsHeaderParam {
32
+ headers?: RawHttpHeadersInput & GetChatCompletionsHeaders;
33
+ }
34
+ export type GetChatCompletionsParameters = GetChatCompletionsHeaderParam & GetChatCompletionsBodyParam & RequestParameters;
35
+ export type GetModelInfoParameters = RequestParameters;
36
+ export interface GetEmbeddingsHeaders {
37
+ /**
38
+ * Controls what happens if extra parameters, undefined by the REST API,
39
+ * are passed in the JSON request payload.
40
+ * This sets the HTTP request header `extra-parameters`.
41
+ *
42
+ * Possible values: "error", "drop", "pass-through"
43
+ */
44
+ "extra-parameters"?: ExtraParameters;
45
+ }
46
+ export interface GetEmbeddingsBodyParam {
47
+ body?: {
48
+ input: string[];
49
+ dimensions?: number;
50
+ encoding_format?: EmbeddingEncodingFormat;
51
+ input_type?: EmbeddingInputType;
52
+ model?: string;
53
+ };
54
+ }
55
+ export interface GetEmbeddingsHeaderParam {
56
+ headers?: RawHttpHeadersInput & GetEmbeddingsHeaders;
57
+ }
58
+ export type GetEmbeddingsParameters = GetEmbeddingsHeaderParam & GetEmbeddingsBodyParam & RequestParameters;
59
+ export interface GetImageEmbeddingsHeaders {
60
+ /**
61
+ * Controls what happens if extra parameters, undefined by the REST API,
62
+ * are passed in the JSON request payload.
63
+ * This sets the HTTP request header `extra-parameters`.
64
+ *
65
+ * Possible values: "error", "drop", "pass-through"
66
+ */
67
+ "extra-parameters"?: ExtraParameters;
68
+ }
69
+ export interface GetImageEmbeddingsBodyParam {
70
+ body?: {
71
+ input: Array<ImageEmbeddingInput>;
72
+ dimensions?: number;
73
+ encoding_format?: EmbeddingEncodingFormat;
74
+ input_type?: EmbeddingInputType;
75
+ model?: string;
76
+ };
77
+ }
78
+ export interface GetImageEmbeddingsHeaderParam {
79
+ headers?: RawHttpHeadersInput & GetImageEmbeddingsHeaders;
80
+ }
81
+ export type GetImageEmbeddingsParameters = GetImageEmbeddingsHeaderParam & GetImageEmbeddingsBodyParam & RequestParameters;
82
+ //# sourceMappingURL=parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.d.ts","sourceRoot":"","sources":["../../src/parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,6BAA6B,EAC7B,6BA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AE,uBAAuB,CAAC;QAC1C,UAAU,CAAC,EAAE,kBAAkB,CAAC;QAChC,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,mBAAmB,GAAG,oBAAoB,CAAC;CACtD;AAED,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAC5D,sBAAsB,GACtB,iBAAiB,CAAC;AAEpB,MAAM,WAAW,yBAAyB;IACxC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,eAAe,CAAC;CACtC;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,CAAC,EAAE;QACL,KAAK,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAClC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,CAAC,EAAE,uBAAuB,CAAC;QAC1C,UAAU,CAAC,EAAE,kBAAkB,CAAC;QAChC,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,6BAA6B;IAC5C,OAAO,CAAC,EAAE,mBAAmB,GAAG,yBAAyB,CAAC;CAC3D;AAED,MAAM,MAAM,4BAA4B,GAAG,6BAA6B,GACtE,2BAA2B,GAC3B,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../src/parameters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RawHttpHeadersInput } from \"@azure/core-rest-pipeline\";\nimport type { RequestParameters } from \"@azure-rest/core-client\";\nimport type {\n ExtraParameters,\n ChatRequestMessage,\n ChatCompletionsResponseFormat,\n ChatCompletionsToolDefinition,\n ChatCompletionsToolSelectionPreset,\n ChatCompletionsNamedToolSelection,\n EmbeddingEncodingFormat,\n EmbeddingInputType,\n ImageEmbeddingInput,\n} from \"./models.js\";\n\nexport interface GetChatCompletionsHeaders {\n /**\n * Controls what happens if extra parameters, undefined by the REST API,\n * are passed in the JSON request payload.\n * This sets the HTTP request header `extra-parameters`.\n *\n * Possible values: \"error\", \"drop\", \"pass-through\"\n */\n \"extra-parameters\"?: ExtraParameters;\n}\n\nexport interface GetChatCompletionsBodyParam {\n body?: {\n messages: Array<ChatRequestMessage>;\n frequency_penalty?: number;\n stream?: boolean;\n presence_penalty?: number;\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n response_format?: ChatCompletionsResponseFormat;\n stop?: string[];\n tools?: Array<ChatCompletionsToolDefinition>;\n tool_choice?: ChatCompletionsToolSelectionPreset | ChatCompletionsNamedToolSelection;\n seed?: number;\n model?: string;\n };\n}\n\nexport interface GetChatCompletionsHeaderParam {\n headers?: RawHttpHeadersInput & GetChatCompletionsHeaders;\n}\n\nexport type GetChatCompletionsParameters = GetChatCompletionsHeaderParam &\n GetChatCompletionsBodyParam &\n RequestParameters;\nexport type GetModelInfoParameters = RequestParameters;\n\nexport interface GetEmbeddingsHeaders {\n /**\n * Controls what happens if extra parameters, undefined by the REST API,\n * are passed in the JSON request payload.\n * This sets the HTTP request header `extra-parameters`.\n *\n * Possible values: \"error\", \"drop\", \"pass-through\"\n */\n \"extra-parameters\"?: ExtraParameters;\n}\n\nexport interface GetEmbeddingsBodyParam {\n body?: {\n input: string[];\n dimensions?: number;\n encoding_format?: EmbeddingEncodingFormat;\n input_type?: EmbeddingInputType;\n model?: string;\n };\n}\n\nexport interface GetEmbeddingsHeaderParam {\n headers?: RawHttpHeadersInput & GetEmbeddingsHeaders;\n}\n\nexport type GetEmbeddingsParameters = GetEmbeddingsHeaderParam &\n GetEmbeddingsBodyParam &\n RequestParameters;\n\nexport interface GetImageEmbeddingsHeaders {\n /**\n * Controls what happens if extra parameters, undefined by the REST API,\n * are passed in the JSON request payload.\n * This sets the HTTP request header `extra-parameters`.\n *\n * Possible values: \"error\", \"drop\", \"pass-through\"\n */\n \"extra-parameters\"?: ExtraParameters;\n}\n\nexport interface GetImageEmbeddingsBodyParam {\n body?: {\n input: Array<ImageEmbeddingInput>;\n dimensions?: number;\n encoding_format?: EmbeddingEncodingFormat;\n input_type?: EmbeddingInputType;\n model?: string;\n };\n}\n\nexport interface GetImageEmbeddingsHeaderParam {\n headers?: RawHttpHeadersInput & GetImageEmbeddingsHeaders;\n}\n\nexport type GetImageEmbeddingsParameters = GetImageEmbeddingsHeaderParam &\n GetImageEmbeddingsBodyParam &\n RequestParameters;\n"]}
@@ -0,0 +1,60 @@
1
+ import type { RawHttpHeaders } from "@azure/core-rest-pipeline";
2
+ import type { HttpResponse, ErrorResponse } from "@azure-rest/core-client";
3
+ import type { ChatCompletionsOutput, ModelInfoOutput, EmbeddingsResultOutput } from "./outputModels.js";
4
+ /** The request has succeeded. */
5
+ export interface GetChatCompletions200Response extends HttpResponse {
6
+ status: "200";
7
+ body: ChatCompletionsOutput;
8
+ }
9
+ export interface GetChatCompletionsDefaultHeaders {
10
+ /** String error code indicating what went wrong. */
11
+ "x-ms-error-code"?: string;
12
+ }
13
+ export interface GetChatCompletionsDefaultResponse extends HttpResponse {
14
+ status: string;
15
+ body: ErrorResponse;
16
+ headers: RawHttpHeaders & GetChatCompletionsDefaultHeaders;
17
+ }
18
+ /** The request has succeeded. */
19
+ export interface GetModelInfo200Response extends HttpResponse {
20
+ status: "200";
21
+ body: ModelInfoOutput;
22
+ }
23
+ export interface GetModelInfoDefaultHeaders {
24
+ /** String error code indicating what went wrong. */
25
+ "x-ms-error-code"?: string;
26
+ }
27
+ export interface GetModelInfoDefaultResponse extends HttpResponse {
28
+ status: string;
29
+ body: ErrorResponse;
30
+ headers: RawHttpHeaders & GetModelInfoDefaultHeaders;
31
+ }
32
+ /** The request has succeeded. */
33
+ export interface GetEmbeddings200Response extends HttpResponse {
34
+ status: "200";
35
+ body: EmbeddingsResultOutput;
36
+ }
37
+ export interface GetEmbeddingsDefaultHeaders {
38
+ /** String error code indicating what went wrong. */
39
+ "x-ms-error-code"?: string;
40
+ }
41
+ export interface GetEmbeddingsDefaultResponse extends HttpResponse {
42
+ status: string;
43
+ body: ErrorResponse;
44
+ headers: RawHttpHeaders & GetEmbeddingsDefaultHeaders;
45
+ }
46
+ /** The request has succeeded. */
47
+ export interface GetImageEmbeddings200Response extends HttpResponse {
48
+ status: "200";
49
+ body: EmbeddingsResultOutput;
50
+ }
51
+ export interface GetImageEmbeddingsDefaultHeaders {
52
+ /** String error code indicating what went wrong. */
53
+ "x-ms-error-code"?: string;
54
+ }
55
+ export interface GetImageEmbeddingsDefaultResponse extends HttpResponse {
56
+ status: string;
57
+ body: ErrorResponse;
58
+ headers: RawHttpHeaders & GetImageEmbeddingsDefaultHeaders;
59
+ }
60
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/responses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAE3B,iCAAiC;AACjC,MAAM,WAAW,6BAA8B,SAAQ,YAAY;IACjE,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,qBAAqB,CAAC;CAC7B;AAED,MAAM,WAAW,gCAAgC;IAC/C,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iCAAkC,SAAQ,YAAY;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,cAAc,GAAG,gCAAgC,CAAC;CAC5D;AAED,iCAAiC;AACjC,MAAM,WAAW,uBAAwB,SAAQ,YAAY;IAC3D,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;CACvB;AAED,MAAM,WAAW,0BAA0B;IACzC,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA4B,SAAQ,YAAY;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,cAAc,GAAG,0BAA0B,CAAC;CACtD;AAED,iCAAiC;AACjC,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC5D,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,MAAM,WAAW,2BAA2B;IAC1C,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,4BAA6B,SAAQ,YAAY;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,cAAc,GAAG,2BAA2B,CAAC;CACvD;AAED,iCAAiC;AACjC,MAAM,WAAW,6BAA8B,SAAQ,YAAY;IACjE,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,MAAM,WAAW,gCAAgC;IAC/C,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iCAAkC,SAAQ,YAAY;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,cAAc,GAAG,gCAAgC,CAAC;CAC5D"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/responses.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RawHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport type { HttpResponse, ErrorResponse } from \"@azure-rest/core-client\";\nimport type {\n ChatCompletionsOutput,\n ModelInfoOutput,\n EmbeddingsResultOutput,\n} from \"./outputModels.js\";\n\n/** The request has succeeded. */\nexport interface GetChatCompletions200Response extends HttpResponse {\n status: \"200\";\n body: ChatCompletionsOutput;\n}\n\nexport interface GetChatCompletionsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface GetChatCompletionsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & GetChatCompletionsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface GetModelInfo200Response extends HttpResponse {\n status: \"200\";\n body: ModelInfoOutput;\n}\n\nexport interface GetModelInfoDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface GetModelInfoDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & GetModelInfoDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface GetEmbeddings200Response extends HttpResponse {\n status: \"200\";\n body: EmbeddingsResultOutput;\n}\n\nexport interface GetEmbeddingsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface GetEmbeddingsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & GetEmbeddingsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface GetImageEmbeddings200Response extends HttpResponse {\n status: \"200\";\n body: EmbeddingsResultOutput;\n}\n\nexport interface GetImageEmbeddingsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface GetImageEmbeddingsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & GetImageEmbeddingsDefaultHeaders;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { TracingSpan } from "@azure/core-tracing";
2
+ import type { GetChatCompletionsBodyParam } from "./parameters.js";
3
+ import type { PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline";
4
+ export declare function getRequestBody(request: PipelineRequest): GetChatCompletionsBodyParam;
5
+ export declare function getSpanName(request: PipelineRequest): string;
6
+ export declare function onStartTracing(span: TracingSpan, request: PipelineRequest, url: string): void;
7
+ export declare function tryProcessResponse(span: TracingSpan, response?: PipelineResponse): void;
8
+ export declare function tryProcessError(span: TracingSpan, error: unknown): void;
9
+ //# sourceMappingURL=tracingHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingHelper.d.ts","sourceRoot":"","sources":["../../src/tracingHelper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAanE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AA0BnF,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,2BAA2B,CAEpF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAG5D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CA6B7F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,IAAI,CA4BvF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAKvE"}
@@ -0,0 +1,198 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { isError } from "@azure/core-util";
4
+ const INFERENCE_GEN_AI_SYSTEM_NAME = "az.ai.inference";
5
+ const isContentRecordingEnabled = () => envVarToBoolean("AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED");
6
+ var TracingAttributesEnum;
7
+ (function (TracingAttributesEnum) {
8
+ TracingAttributesEnum["Operation_Name"] = "gen_ai.operation.name";
9
+ TracingAttributesEnum["Request_Model"] = "gen_ai.request.model";
10
+ TracingAttributesEnum["System"] = "gen_ai.system";
11
+ TracingAttributesEnum["Error_Type"] = "error.type";
12
+ TracingAttributesEnum["Server_Port"] = "server.port";
13
+ TracingAttributesEnum["Request_Frequency_Penalty"] = "gen_ai.request.frequency_penalty";
14
+ TracingAttributesEnum["Request_Max_Tokens"] = "gen_ai.request.max_tokens";
15
+ TracingAttributesEnum["Request_Presence_Penalty"] = "gen_ai.request.presence_penalty";
16
+ TracingAttributesEnum["Request_Stop_Sequences"] = "gen_ai.request.stop_sequences";
17
+ TracingAttributesEnum["Request_Temperature"] = "gen_ai.request.temperature";
18
+ TracingAttributesEnum["Request_Top_P"] = "gen_ai.request.top_p";
19
+ TracingAttributesEnum["Response_Finish_Reasons"] = "gen_ai.response.finish_reasons";
20
+ TracingAttributesEnum["Response_Id"] = "gen_ai.response.id";
21
+ TracingAttributesEnum["Response_Model"] = "gen_ai.response.model";
22
+ TracingAttributesEnum["Usage_Input_Tokens"] = "gen_ai.usage.input_tokens";
23
+ TracingAttributesEnum["Usage_Output_Tokens"] = "gen_ai.usage.output_tokens";
24
+ TracingAttributesEnum["Server_Address"] = "server.address";
25
+ })(TracingAttributesEnum || (TracingAttributesEnum = {}));
26
+ export function getRequestBody(request) {
27
+ return { body: JSON.parse(request.body) };
28
+ }
29
+ export function getSpanName(request) {
30
+ var _a;
31
+ const { body } = getRequestBody(request);
32
+ return `chat ${(_a = body === null || body === void 0 ? void 0 : body.model) !== null && _a !== void 0 ? _a : ""}`.trim();
33
+ }
34
+ export function onStartTracing(span, request, url) {
35
+ if (!span.isRecording()) {
36
+ return;
37
+ }
38
+ const urlObj = new URL(url);
39
+ const port = Number(urlObj.port) || (urlObj.protocol === "https:" ? undefined : 80);
40
+ if (port) {
41
+ span.setAttribute(TracingAttributesEnum.Server_Port, port);
42
+ }
43
+ span.setAttribute(TracingAttributesEnum.Server_Address, urlObj.hostname);
44
+ span.setAttribute(TracingAttributesEnum.Operation_Name, "chat");
45
+ span.setAttribute(TracingAttributesEnum.System, "az.ai.inference");
46
+ const { body } = getRequestBody(request);
47
+ if (!body)
48
+ return;
49
+ span.setAttribute(TracingAttributesEnum.Request_Model, body.model);
50
+ span.setAttribute(TracingAttributesEnum.Request_Frequency_Penalty, body.frequency_penalty);
51
+ span.setAttribute(TracingAttributesEnum.Request_Max_Tokens, body.max_tokens);
52
+ span.setAttribute(TracingAttributesEnum.Request_Presence_Penalty, body.presence_penalty);
53
+ span.setAttribute(TracingAttributesEnum.Request_Stop_Sequences, body.stop);
54
+ span.setAttribute(TracingAttributesEnum.Request_Temperature, body.temperature);
55
+ span.setAttribute(TracingAttributesEnum.Request_Top_P, body.top_p);
56
+ if (body.messages) {
57
+ addRequestChatMessageEvent(span, body.messages);
58
+ }
59
+ }
60
+ export function tryProcessResponse(span, response) {
61
+ var _a, _b, _c;
62
+ if (!span.isRecording()) {
63
+ return;
64
+ }
65
+ if (response === null || response === void 0 ? void 0 : response.bodyAsText) {
66
+ const body = JSON.parse(response.bodyAsText);
67
+ if ((_a = body.error) !== null && _a !== void 0 ? _a : body.message) {
68
+ span.setAttribute(TracingAttributesEnum.Error_Type, `${(_b = body.status) !== null && _b !== void 0 ? _b : body.statusCode}`);
69
+ span.setStatus({
70
+ status: "error",
71
+ error: (_c = body.error) !== null && _c !== void 0 ? _c : body.message, // message is not in the schema of the response, but it can present if there is crediential error
72
+ });
73
+ }
74
+ span.setAttribute(TracingAttributesEnum.Response_Id, body.id);
75
+ span.setAttribute(TracingAttributesEnum.Response_Model, body.model);
76
+ if (body.choices) {
77
+ span.setAttribute(TracingAttributesEnum.Response_Finish_Reasons, body.choices.map((choice) => choice.finish_reason).join(","));
78
+ }
79
+ if (body.usage) {
80
+ span.setAttribute(TracingAttributesEnum.Usage_Input_Tokens, body.usage.prompt_tokens);
81
+ span.setAttribute(TracingAttributesEnum.Usage_Output_Tokens, body.usage.completion_tokens);
82
+ }
83
+ addResponseChatMessageEvent(span, body);
84
+ }
85
+ }
86
+ export function tryProcessError(span, error) {
87
+ span.setStatus({
88
+ status: "error",
89
+ error: isError(error) ? error : undefined,
90
+ });
91
+ }
92
+ /*
93
+ * Add event to span. Sample:
94
+ {
95
+ name: 'gen_ai.user.message',
96
+ attributes: {
97
+ 'gen_ai.system': 'INFERENCE_GEN_AI_SYSTEM_NAME',
98
+ 'gen_ai.event.content': `{"role":"user","content":"What's the weather like in Boston?"}`
99
+ },
100
+ time: [ 1725666879, 622695900 ],
101
+ droppedAttributesCount: 0
102
+ },
103
+ */
104
+ function addRequestChatMessageEvent(span, messages) {
105
+ messages.forEach((message) => {
106
+ var _a;
107
+ if (message.role) {
108
+ const content = {};
109
+ const chatMsg = message;
110
+ if (chatMsg.content) {
111
+ content.content = chatMsg.content;
112
+ }
113
+ if (!isContentRecordingEnabled()) {
114
+ content.content = "";
115
+ }
116
+ const assistantMsg = message;
117
+ if (assistantMsg.tool_calls) {
118
+ content.tool_calls = assistantMsg.tool_calls;
119
+ if (!isContentRecordingEnabled()) {
120
+ const toolCalls = JSON.parse(JSON.stringify(content.tool_calls));
121
+ toolCalls.forEach((toolCall) => {
122
+ if (toolCall.function.arguments) {
123
+ toolCall.function.arguments = "";
124
+ }
125
+ toolCall.function.name = "";
126
+ });
127
+ content.tool_calls = toolCalls;
128
+ }
129
+ }
130
+ const toolMsg = message;
131
+ if (toolMsg.tool_call_id) {
132
+ content.id = toolMsg.tool_call_id;
133
+ }
134
+ (_a = span.addEvent) === null || _a === void 0 ? void 0 : _a.call(span, `gen_ai.${message.role}.message`, {
135
+ attributes: {
136
+ "gen_ai.system": INFERENCE_GEN_AI_SYSTEM_NAME,
137
+ "gen_ai.event.content": JSON.stringify(content),
138
+ },
139
+ });
140
+ }
141
+ });
142
+ }
143
+ /*
144
+ * Add event to span. Sample:
145
+ {
146
+ name: 'gen_ai.choice',
147
+ attributes: {
148
+ 'gen_ai.system': 'INFERENCE_GEN_AI_SYSTEM_NAME',
149
+ 'gen_ai.event.content': '{"finish_reason":"tool_calls","index":0,"message":{"content":""}}'
150
+ },
151
+ time: [ 1725666881, 780608000 ],
152
+ droppedAttributesCount: 0
153
+ }
154
+ */
155
+ function addResponseChatMessageEvent(span, body) {
156
+ var _a;
157
+ if (!span.addEvent) {
158
+ return;
159
+ }
160
+ (_a = body === null || body === void 0 ? void 0 : body.choices) === null || _a === void 0 ? void 0 : _a.forEach((choice) => {
161
+ var _a;
162
+ let message = {};
163
+ if (choice.message.content) {
164
+ message.content = choice.message.content;
165
+ }
166
+ if (choice.message.tool_calls) {
167
+ message.toolCalls = choice.message.tool_calls;
168
+ }
169
+ if (!isContentRecordingEnabled()) {
170
+ message = JSON.parse(JSON.stringify(message));
171
+ message.content = "";
172
+ if (message.toolCalls) {
173
+ message.toolCalls.forEach((toolCall) => {
174
+ if (toolCall.function.arguments) {
175
+ toolCall.function.arguments = "";
176
+ }
177
+ toolCall.function.name = "";
178
+ });
179
+ }
180
+ }
181
+ const response = {
182
+ finish_reason: choice.finish_reason,
183
+ index: choice.index,
184
+ message,
185
+ };
186
+ const attributes = {
187
+ "gen_ai.system": INFERENCE_GEN_AI_SYSTEM_NAME,
188
+ "gen_ai.event.content": JSON.stringify(response),
189
+ };
190
+ (_a = span.addEvent) === null || _a === void 0 ? void 0 : _a.call(span, "gen_ai.choice", { attributes });
191
+ });
192
+ }
193
+ function envVarToBoolean(key) {
194
+ var _a;
195
+ const value = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env[key.toLowerCase()];
196
+ return value !== "false" && value !== "0" && Boolean(value);
197
+ }
198
+ //# sourceMappingURL=tracingHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingHelper.js","sourceRoot":"","sources":["../../src/tracingHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAelC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AACvD,MAAM,yBAAyB,GAAG,GAAG,EAAE,CACrC,eAAe,CAAC,gDAAgD,CAAC,CAAC;AAEpE,IAAK,qBAkBJ;AAlBD,WAAK,qBAAqB;IACxB,iEAAwC,CAAA;IACxC,+DAAsC,CAAA;IACtC,iDAAwB,CAAA;IACxB,kDAAyB,CAAA;IACzB,oDAA2B,CAAA;IAC3B,uFAA8D,CAAA;IAC9D,yEAAgD,CAAA;IAChD,qFAA4D,CAAA;IAC5D,iFAAwD,CAAA;IACxD,2EAAkD,CAAA;IAClD,+DAAsC,CAAA;IACtC,mFAA0D,CAAA;IAC1D,2DAAkC,CAAA;IAClC,iEAAwC,CAAA;IACxC,yEAAgD,CAAA;IAChD,2EAAkD,CAAA;IAClD,0DAAiC,CAAA;AACnC,CAAC,EAlBI,qBAAqB,KAArB,qBAAqB,QAkBzB;AAED,MAAM,UAAU,cAAc,CAAC,OAAwB;IACrD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAc,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAwB;;IAClD,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,QAAQ,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAiB,EAAE,OAAwB,EAAE,GAAW;IACrF,IAAI,CAAC,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WAAW,EAAE,CAAC,CAAC;IACjE,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TracingSpan } from \"@azure/core-tracing\";\nimport type { GetChatCompletionsBodyParam } from \"./parameters.js\";\nimport type {\n ChatRequestAssistantMessage,\n ChatRequestMessage,\n ChatRequestSystemMessage,\n ChatRequestToolMessage,\n} from \"./models.js\";\nimport type {\n ChatChoiceOutput,\n ChatCompletionsOutput,\n ChatCompletionsToolCallOutput,\n} from \"./outputModels.js\";\nimport { isError } from \"@azure/core-util\";\nimport type { PipelineRequest, PipelineResponse } from \"@azure/core-rest-pipeline\";\n\nconst INFERENCE_GEN_AI_SYSTEM_NAME = \"az.ai.inference\";\nconst isContentRecordingEnabled = () =>\n envVarToBoolean(\"AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED\");\n\nenum TracingAttributesEnum {\n Operation_Name = \"gen_ai.operation.name\",\n Request_Model = \"gen_ai.request.model\",\n System = \"gen_ai.system\",\n Error_Type = \"error.type\",\n Server_Port = \"server.port\",\n Request_Frequency_Penalty = \"gen_ai.request.frequency_penalty\",\n Request_Max_Tokens = \"gen_ai.request.max_tokens\",\n Request_Presence_Penalty = \"gen_ai.request.presence_penalty\",\n Request_Stop_Sequences = \"gen_ai.request.stop_sequences\",\n Request_Temperature = \"gen_ai.request.temperature\",\n Request_Top_P = \"gen_ai.request.top_p\",\n Response_Finish_Reasons = \"gen_ai.response.finish_reasons\",\n Response_Id = \"gen_ai.response.id\",\n Response_Model = \"gen_ai.response.model\",\n Usage_Input_Tokens = \"gen_ai.usage.input_tokens\",\n Usage_Output_Tokens = \"gen_ai.usage.output_tokens\",\n Server_Address = \"server.address\",\n}\n\nexport function getRequestBody(request: PipelineRequest): GetChatCompletionsBodyParam {\n return { body: JSON.parse(request.body as string) };\n}\n\nexport function getSpanName(request: PipelineRequest): string {\n const { body } = getRequestBody(request);\n return `chat ${body?.model ?? \"\"}`.trim();\n}\n\nexport function onStartTracing(span: TracingSpan, request: PipelineRequest, url: string): void {\n if (!span.isRecording()) {\n return;\n }\n\n const urlObj = new URL(url);\n const port = Number(urlObj.port) || (urlObj.protocol === \"https:\" ? undefined : 80);\n\n if (port) {\n span.setAttribute(TracingAttributesEnum.Server_Port, port);\n }\n span.setAttribute(TracingAttributesEnum.Server_Address, urlObj.hostname);\n span.setAttribute(TracingAttributesEnum.Operation_Name, \"chat\");\n span.setAttribute(TracingAttributesEnum.System, \"az.ai.inference\");\n\n const { body } = getRequestBody(request);\n if (!body) return;\n\n span.setAttribute(TracingAttributesEnum.Request_Model, body.model);\n span.setAttribute(TracingAttributesEnum.Request_Frequency_Penalty, body.frequency_penalty);\n span.setAttribute(TracingAttributesEnum.Request_Max_Tokens, body.max_tokens);\n span.setAttribute(TracingAttributesEnum.Request_Presence_Penalty, body.presence_penalty);\n span.setAttribute(TracingAttributesEnum.Request_Stop_Sequences, body.stop);\n span.setAttribute(TracingAttributesEnum.Request_Temperature, body.temperature);\n span.setAttribute(TracingAttributesEnum.Request_Top_P, body.top_p);\n\n if (body.messages) {\n addRequestChatMessageEvent(span, body.messages);\n }\n}\n\nexport function tryProcessResponse(span: TracingSpan, response?: PipelineResponse): void {\n if (!span.isRecording()) {\n return;\n }\n\n if (response?.bodyAsText) {\n const body: any = JSON.parse(response.bodyAsText);\n if (body.error ?? body.message) {\n span.setAttribute(TracingAttributesEnum.Error_Type, `${body.status ?? body.statusCode}`);\n span.setStatus({\n status: \"error\",\n error: body.error ?? body.message, // message is not in the schema of the response, but it can present if there is crediential error\n });\n }\n span.setAttribute(TracingAttributesEnum.Response_Id, body.id);\n span.setAttribute(TracingAttributesEnum.Response_Model, body.model);\n if (body.choices) {\n span.setAttribute(\n TracingAttributesEnum.Response_Finish_Reasons,\n body.choices.map((choice: ChatChoiceOutput) => choice.finish_reason).join(\",\"),\n );\n }\n if (body.usage) {\n span.setAttribute(TracingAttributesEnum.Usage_Input_Tokens, body.usage.prompt_tokens);\n span.setAttribute(TracingAttributesEnum.Usage_Output_Tokens, body.usage.completion_tokens);\n }\n addResponseChatMessageEvent(span, body);\n }\n}\n\nexport function tryProcessError(span: TracingSpan, error: unknown): void {\n span.setStatus({\n status: \"error\",\n error: isError(error) ? error : undefined,\n });\n}\n\n/*\n* Add event to span. Sample:\n {\n name: 'gen_ai.user.message',\n attributes: {\n 'gen_ai.system': 'INFERENCE_GEN_AI_SYSTEM_NAME',\n 'gen_ai.event.content': `{\"role\":\"user\",\"content\":\"What's the weather like in Boston?\"}` \n },\n time: [ 1725666879, 622695900 ],\n droppedAttributesCount: 0\n },\n*/\nfunction addRequestChatMessageEvent(span: TracingSpan, messages: Array<ChatRequestMessage>): void {\n messages.forEach((message: any) => {\n if (message.role) {\n const content: {\n content?: string;\n tool_calls?: Array<ChatCompletionsToolCallOutput>;\n id?: string;\n } = {};\n\n const chatMsg = message as ChatRequestSystemMessage;\n if (chatMsg.content) {\n content.content = chatMsg.content;\n }\n if (!isContentRecordingEnabled()) {\n content.content = \"\";\n }\n\n const assistantMsg = message as ChatRequestAssistantMessage;\n if (assistantMsg.tool_calls) {\n content.tool_calls = assistantMsg.tool_calls;\n if (!isContentRecordingEnabled()) {\n const toolCalls: Array<ChatCompletionsToolCallOutput> = JSON.parse(\n JSON.stringify(content.tool_calls),\n );\n toolCalls.forEach((toolCall) => {\n if (toolCall.function.arguments) {\n toolCall.function.arguments = \"\";\n }\n toolCall.function.name = \"\";\n });\n content.tool_calls = toolCalls;\n }\n }\n\n const toolMsg: ChatRequestToolMessage = message;\n if (toolMsg.tool_call_id) {\n content.id = toolMsg.tool_call_id;\n }\n\n span.addEvent?.(`gen_ai.${message.role}.message`, {\n attributes: {\n \"gen_ai.system\": INFERENCE_GEN_AI_SYSTEM_NAME,\n \"gen_ai.event.content\": JSON.stringify(content),\n },\n });\n }\n });\n}\n\n/*\n* Add event to span. Sample:\n{\n name: 'gen_ai.choice',\n attributes: {\n 'gen_ai.system': 'INFERENCE_GEN_AI_SYSTEM_NAME',\n 'gen_ai.event.content': '{\"finish_reason\":\"tool_calls\",\"index\":0,\"message\":{\"content\":\"\"}}'\n },\n time: [ 1725666881, 780608000 ],\n droppedAttributesCount: 0\n} \n*/\nfunction addResponseChatMessageEvent(span: TracingSpan, body: ChatCompletionsOutput): void {\n if (!span.addEvent) {\n return;\n }\n\n body?.choices?.forEach((choice: ChatChoiceOutput) => {\n let message: { content?: string; toolCalls?: Array<ChatCompletionsToolCallOutput> } = {};\n\n if (choice.message.content) {\n message.content = choice.message.content;\n }\n if (choice.message.tool_calls) {\n message.toolCalls = choice.message.tool_calls;\n }\n\n if (!isContentRecordingEnabled()) {\n message = JSON.parse(JSON.stringify(message));\n message.content = \"\";\n if (message.toolCalls) {\n message.toolCalls.forEach((toolCall) => {\n if (toolCall.function.arguments) {\n toolCall.function.arguments = \"\";\n }\n toolCall.function.name = \"\";\n });\n }\n }\n\n const response = {\n finish_reason: choice.finish_reason,\n index: choice.index,\n message,\n };\n const attributes = {\n \"gen_ai.system\": INFERENCE_GEN_AI_SYSTEM_NAME,\n \"gen_ai.event.content\": JSON.stringify(response),\n };\n\n span.addEvent?.(\"gen_ai.choice\", { attributes });\n });\n}\n\nfunction envVarToBoolean(key: string): boolean {\n const value = process.env[key] ?? process.env[key.toLowerCase()];\n return value !== \"false\" && value !== \"0\" && Boolean(value);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { PipelinePolicy } from "@azure/core-rest-pipeline";
2
+ /**
3
+ * The programmatic identifier of the tracingPolicy.
4
+ */
5
+ export declare const tracingPolicyName = "inferenceTracingPolicy";
6
+ /**
7
+ * A simple policy to create OpenTelemetry Spans for each request made by the pipeline
8
+ * that has SpanOptions with a parent.
9
+ * Requests made without a parent Span will not be recorded.
10
+ */
11
+ export declare function tracingPolicy(): PipelinePolicy;
12
+ //# sourceMappingURL=tracingPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingPolicy.d.ts","sourceRoot":"","sources":["../../src/tracingPolicy.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,cAAc,EAIf,MAAM,2BAA2B,CAAC;AAGnC;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,cAAc,CAyC9C"}
@@ -0,0 +1,68 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { createTracingClient, } from "@azure/core-tracing";
4
+ import { logger } from "./logger.js";
5
+ import { getErrorMessage } from "@azure/core-util";
6
+ import { tryProcessResponse, onStartTracing, tryProcessError, getSpanName, getRequestBody, } from "./tracingHelper.js";
7
+ import { SDK_VERSION } from "./constants.js";
8
+ /**
9
+ * The programmatic identifier of the tracingPolicy.
10
+ */
11
+ export const tracingPolicyName = "inferenceTracingPolicy";
12
+ /**
13
+ * A simple policy to create OpenTelemetry Spans for each request made by the pipeline
14
+ * that has SpanOptions with a parent.
15
+ * Requests made without a parent Span will not be recorded.
16
+ */
17
+ export function tracingPolicy() {
18
+ const tracingClient = createTracingClient({
19
+ namespace: "Microsoft.CognitiveServices",
20
+ packageName: "@azure/ai-inference-rest",
21
+ packageVersion: SDK_VERSION,
22
+ });
23
+ return {
24
+ name: tracingPolicyName,
25
+ async sendRequest(request, next) {
26
+ var _a, _b, _c, _d;
27
+ const url = new URL(request.url);
28
+ if (!tracingClient ||
29
+ !url.href.endsWith("/chat/completions") ||
30
+ ((_b = (_a = getRequestBody(request)) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.stream)) {
31
+ return next(request);
32
+ }
33
+ const { span, tracingContext } = (_c = tryCreateSpan(tracingClient, request)) !== null && _c !== void 0 ? _c : {};
34
+ if (!span || !tracingContext) {
35
+ return next(request);
36
+ }
37
+ try {
38
+ (_d = request.tracingOptions) !== null && _d !== void 0 ? _d : (request.tracingOptions = {});
39
+ request.tracingOptions.tracingContext = tracingContext;
40
+ onStartTracing(span, request, request.url);
41
+ const response = await tracingClient.withContext(tracingContext, next, request);
42
+ tryProcessResponse(span, response);
43
+ return response;
44
+ }
45
+ catch (err) {
46
+ tryProcessError(span, err);
47
+ throw err;
48
+ }
49
+ finally {
50
+ span.end();
51
+ }
52
+ },
53
+ };
54
+ }
55
+ function tryCreateSpan(tracingClient, request) {
56
+ try {
57
+ // As per spec, we do not need to differentiate between HTTP and HTTPS in span name.
58
+ const { span, updatedOptions } = tracingClient.startSpan(getSpanName(request), { tracingOptions: request.tracingOptions }, {
59
+ spanKind: "client",
60
+ });
61
+ return { span, tracingContext: updatedOptions.tracingOptions.tracingContext };
62
+ }
63
+ catch (e) {
64
+ logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);
65
+ return undefined;
66
+ }
67
+ }
68
+ //# sourceMappingURL=tracingPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingPolicy.js","sourceRoot":"","sources":["../../src/tracingPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAIL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,aAAa,GAAG,mBAAmB,CAAC;QACxC,SAAS,EAAE,6BAA6B;QACxC,WAAW,EAAE,0BAA0B;QACvC,cAAc,EAA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QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CACpB,aAA4B,EAC5B,OAAwB;IAExB,IAAI,CAAC;QACH,oFAAoF;QACpF,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,SAAS,CACtD,WAAW,CAAC,OAAO,CAAC,EACpB,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,EAC1C;YACE,QAAQ,EAAE,QAAQ;SACnB,CACF,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,cAAc,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC;IAChF,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,MAAM,CAAC,OAAO,CAAC,qDAAqD,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC1F,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n type TracingClient,\n type TracingContext,\n type TracingSpan,\n createTracingClient,\n} from \"@azure/core-tracing\";\nimport { logger } from \"./logger.js\";\nimport { getErrorMessage } from \"@azure/core-util\";\nimport {\n tryProcessResponse,\n onStartTracing,\n tryProcessError,\n getSpanName,\n getRequestBody,\n} from \"./tracingHelper.js\";\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport { SDK_VERSION } from \"./constants.js\";\n\n/**\n * The programmatic identifier of the tracingPolicy.\n */\nexport const tracingPolicyName = \"inferenceTracingPolicy\";\n\n/**\n * A simple policy to create OpenTelemetry Spans for each request made by the pipeline\n * that has SpanOptions with a parent.\n * Requests made without a parent Span will not be recorded.\n */\nexport function tracingPolicy(): PipelinePolicy {\n const tracingClient = createTracingClient({\n namespace: \"Microsoft.CognitiveServices\",\n packageName: \"@azure/ai-inference-rest\",\n packageVersion: SDK_VERSION,\n });\n\n return {\n name: tracingPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const url = new URL(request.url);\n if (\n !tracingClient ||\n !url.href.endsWith(\"/chat/completions\") ||\n getRequestBody(request)?.body?.stream\n ) {\n return next(request);\n }\n\n const { span, tracingContext } = tryCreateSpan(tracingClient, request) ?? {};\n\n if (!span || !tracingContext) {\n return next(request);\n }\n\n try {\n request.tracingOptions ??= {};\n request.tracingOptions.tracingContext = tracingContext;\n\n onStartTracing(span, request, request.url);\n const response = await tracingClient.withContext(tracingContext, next, request);\n tryProcessResponse(span, response);\n return response;\n } catch (err: any) {\n tryProcessError(span, err);\n throw err;\n } finally {\n span.end();\n }\n },\n };\n}\n\nfunction tryCreateSpan(\n tracingClient: TracingClient,\n request: PipelineRequest,\n): { span: TracingSpan; tracingContext: TracingContext } | undefined {\n try {\n // As per spec, we do not need to differentiate between HTTP and HTTPS in span name.\n const { span, updatedOptions } = tracingClient.startSpan(\n getSpanName(request),\n { tracingOptions: request.tracingOptions },\n {\n spanKind: \"client\",\n },\n );\n\n return { span, tracingContext: updatedOptions.tracingOptions.tracingContext };\n } catch (e: any) {\n logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n"]}
@@ -0,0 +1,47 @@
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
+ 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 GetEmbeddings {
21
+ /**
22
+ * Return the embedding vectors for given text prompts.
23
+ * The method makes a REST API call to the `/embeddings` route on the given endpoint.
24
+ */
25
+ post(options?: GetEmbeddingsParameters): StreamableMethod<GetEmbeddings200Response | GetEmbeddingsDefaultResponse>;
26
+ }
27
+ export interface GetImageEmbeddings {
28
+ /**
29
+ * Return the embedding vectors for given images.
30
+ * The method makes a REST API call to the `/images/embeddings` route on the given endpoint.
31
+ */
32
+ post(options?: GetImageEmbeddingsParameters): StreamableMethod<GetImageEmbeddings200Response | GetImageEmbeddingsDefaultResponse>;
33
+ }
34
+ export interface Routes {
35
+ /** Resource for '/chat/completions' has methods for the following verbs: post */
36
+ (path: "/chat/completions"): GetChatCompletions;
37
+ /** Resource for '/info' has methods for the following verbs: get */
38
+ (path: "/info"): GetModelInfo;
39
+ /** Resource for '/embeddings' has methods for the following verbs: post */
40
+ (path: "/embeddings"): GetEmbeddings;
41
+ /** Resource for '/images/embeddings' has methods for the following verbs: post */
42
+ (path: "/images/embeddings"): GetImageEmbeddings;
43
+ }
44
+ export type ModelClient = Client & {
45
+ path: Routes;
46
+ };
47
+ //# sourceMappingURL=clientDefinitions.d.ts.map
@@ -0,0 +1 @@
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,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"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ //# 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 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<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"]}
@@ -0,0 +1,2 @@
1
+ export declare const SDK_VERSION: string;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,EAAE,MAAuB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.SDK_VERSION = void 0;
6
+ exports.SDK_VERSION = "1.0.0-beta.4";
7
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAErB,QAAA,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"]}
@@ -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