@mistralai/mistralai 1.4.0 → 1.5.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 (201) hide show
  1. package/README.md +6 -1
  2. package/docs/sdks/classifiers/README.md +7 -3
  3. package/docs/sdks/embeddings/README.md +2 -2
  4. package/docs/sdks/ocr/README.md +93 -0
  5. package/examples/README.md +24 -14
  6. package/examples/package-lock.json +199 -7
  7. package/examples/package.json +2 -1
  8. package/examples/src/async_ocr_process_from_file.ts +33 -0
  9. package/examples/src/async_ocr_process_from_url.ts +15 -0
  10. package/examples/src/async_structured_outputs.ts +60 -0
  11. package/examples/test.ts +17 -1
  12. package/extra/structChat.d.ts +19 -0
  13. package/extra/structChat.d.ts.map +1 -0
  14. package/extra/structChat.js +60 -0
  15. package/extra/structChat.js.map +1 -0
  16. package/funcs/classifiersModerateChat.d.ts +1 -1
  17. package/funcs/classifiersModerateChat.d.ts.map +1 -1
  18. package/funcs/classifiersModerateChat.js +1 -1
  19. package/funcs/classifiersModerateChat.js.map +1 -1
  20. package/funcs/ocrProcess.d.ts +13 -0
  21. package/funcs/ocrProcess.d.ts.map +1 -0
  22. package/funcs/ocrProcess.js +98 -0
  23. package/funcs/ocrProcess.js.map +1 -0
  24. package/jsr.json +1 -1
  25. package/lib/config.d.ts +3 -3
  26. package/lib/config.js +3 -3
  27. package/lib/config.js.map +1 -1
  28. package/models/components/assistantmessage.d.ts +3 -0
  29. package/models/components/assistantmessage.d.ts.map +1 -1
  30. package/models/components/assistantmessage.js.map +1 -1
  31. package/models/components/chatcompletionrequest.d.ts +2 -2
  32. package/models/components/chatcompletionrequest.d.ts.map +1 -1
  33. package/models/components/chatcompletionrequest.js +2 -2
  34. package/models/components/chatcompletionrequest.js.map +1 -1
  35. package/models/components/chatcompletionstreamrequest.d.ts +2 -2
  36. package/models/components/chatcompletionstreamrequest.d.ts.map +1 -1
  37. package/models/components/chatcompletionstreamrequest.js +2 -2
  38. package/models/components/chatcompletionstreamrequest.js.map +1 -1
  39. package/models/components/{chatclassificationrequest.d.ts → chatmoderationrequest.d.ts} +31 -29
  40. package/models/components/chatmoderationrequest.d.ts.map +1 -0
  41. package/models/components/{chatclassificationrequest.js → chatmoderationrequest.js} +38 -34
  42. package/models/components/chatmoderationrequest.js.map +1 -0
  43. package/models/components/classificationrequest.d.ts +5 -2
  44. package/models/components/classificationrequest.d.ts.map +1 -1
  45. package/models/components/classificationrequest.js +2 -2
  46. package/models/components/classificationrequest.js.map +1 -1
  47. package/models/components/contentchunk.d.ts +5 -0
  48. package/models/components/contentchunk.d.ts.map +1 -1
  49. package/models/components/contentchunk.js +7 -0
  50. package/models/components/contentchunk.js.map +1 -1
  51. package/models/components/documenturlchunk.d.ts +36 -0
  52. package/models/components/documenturlchunk.d.ts.map +1 -0
  53. package/models/components/documenturlchunk.js +74 -0
  54. package/models/components/documenturlchunk.js.map +1 -0
  55. package/models/components/embeddingrequest.d.ts +3 -8
  56. package/models/components/embeddingrequest.d.ts.map +1 -1
  57. package/models/components/embeddingrequest.js +2 -6
  58. package/models/components/embeddingrequest.js.map +1 -1
  59. package/models/components/fimcompletionrequest.d.ts +2 -2
  60. package/models/components/fimcompletionrequest.d.ts.map +1 -1
  61. package/models/components/fimcompletionrequest.js +2 -2
  62. package/models/components/fimcompletionrequest.js.map +1 -1
  63. package/models/components/fimcompletionstreamrequest.d.ts +2 -2
  64. package/models/components/fimcompletionstreamrequest.d.ts.map +1 -1
  65. package/models/components/fimcompletionstreamrequest.js +2 -2
  66. package/models/components/fimcompletionstreamrequest.js.map +1 -1
  67. package/models/components/index.d.ts +9 -1
  68. package/models/components/index.d.ts.map +1 -1
  69. package/models/components/index.js +9 -1
  70. package/models/components/index.js.map +1 -1
  71. package/models/components/jsonschema.d.ts +39 -0
  72. package/models/components/jsonschema.d.ts.map +1 -0
  73. package/models/components/jsonschema.js +74 -0
  74. package/models/components/jsonschema.js.map +1 -0
  75. package/models/components/ocrimageobject.d.ts +57 -0
  76. package/models/components/ocrimageobject.d.ts.map +1 -0
  77. package/models/components/ocrimageobject.js +86 -0
  78. package/models/components/ocrimageobject.js.map +1 -0
  79. package/models/components/ocrpagedimensions.d.ts +42 -0
  80. package/models/components/ocrpagedimensions.d.ts.map +1 -0
  81. package/models/components/ocrpagedimensions.js +63 -0
  82. package/models/components/ocrpagedimensions.js.map +1 -0
  83. package/models/components/ocrpageobject.d.ts +49 -0
  84. package/models/components/ocrpageobject.d.ts.map +1 -0
  85. package/models/components/ocrpageobject.js +67 -0
  86. package/models/components/ocrpageobject.js.map +1 -0
  87. package/models/components/ocrrequest.d.ts +82 -0
  88. package/models/components/ocrrequest.d.ts.map +1 -0
  89. package/models/components/ocrrequest.js +115 -0
  90. package/models/components/ocrrequest.js.map +1 -0
  91. package/models/components/ocrresponse.d.ts +41 -0
  92. package/models/components/ocrresponse.d.ts.map +1 -0
  93. package/models/components/ocrresponse.js +74 -0
  94. package/models/components/ocrresponse.js.map +1 -0
  95. package/models/components/ocrusageinfo.d.ts +37 -0
  96. package/models/components/ocrusageinfo.d.ts.map +1 -0
  97. package/models/components/ocrusageinfo.js +72 -0
  98. package/models/components/ocrusageinfo.js.map +1 -0
  99. package/models/components/prediction.d.ts +0 -23
  100. package/models/components/prediction.d.ts.map +1 -1
  101. package/models/components/prediction.js +1 -19
  102. package/models/components/prediction.js.map +1 -1
  103. package/models/components/responseformat.d.ts +3 -0
  104. package/models/components/responseformat.d.ts.map +1 -1
  105. package/models/components/responseformat.js +12 -0
  106. package/models/components/responseformat.js.map +1 -1
  107. package/models/components/responseformats.d.ts +3 -0
  108. package/models/components/responseformats.d.ts.map +1 -1
  109. package/models/components/responseformats.js +1 -0
  110. package/models/components/responseformats.js.map +1 -1
  111. package/package.json +2 -2
  112. package/packages/mistralai-azure/FUNCTIONS.md +1 -0
  113. package/packages/mistralai-azure/jsr.json +28 -0
  114. package/packages/mistralai-azure/package-lock.json +3307 -0
  115. package/packages/mistralai-azure/package.json +32 -0
  116. package/packages/mistralai-azure/src/funcs/chatComplete.ts +5 -3
  117. package/packages/mistralai-azure/src/funcs/chatStream.ts +5 -3
  118. package/packages/mistralai-azure/src/lib/config.ts +3 -3
  119. package/packages/mistralai-azure/src/lib/encodings.ts +95 -61
  120. package/packages/mistralai-azure/src/lib/primitives.ts +14 -0
  121. package/packages/mistralai-azure/src/lib/schemas.ts +5 -0
  122. package/packages/mistralai-azure/src/lib/sdks.ts +4 -1
  123. package/packages/mistralai-azure/src/models/components/chatcompletionrequest.ts +10 -0
  124. package/packages/mistralai-azure/src/models/components/chatcompletionstreamrequest.ts +10 -0
  125. package/packages/mistralai-azure/src/models/components/function.ts +4 -0
  126. package/packages/mistralai-azure/src/models/components/index.ts +1 -0
  127. package/packages/mistralai-azure/src/models/components/prediction.ts +93 -0
  128. package/packages/mistralai-azure/src/models/components/toolcall.ts +4 -0
  129. package/packages/mistralai-azure/tsconfig.json +41 -0
  130. package/packages/mistralai-gcp/FUNCTIONS.md +1 -0
  131. package/packages/mistralai-gcp/jsr.json +28 -0
  132. package/packages/mistralai-gcp/package-lock.json +3559 -0
  133. package/packages/mistralai-gcp/package.json +32 -0
  134. package/packages/mistralai-gcp/src/funcs/chatComplete.ts +5 -3
  135. package/packages/mistralai-gcp/src/funcs/chatStream.ts +5 -3
  136. package/packages/mistralai-gcp/src/funcs/fimComplete.ts +5 -3
  137. package/packages/mistralai-gcp/src/funcs/fimStream.ts +5 -3
  138. package/packages/mistralai-gcp/src/lib/config.ts +3 -3
  139. package/packages/mistralai-gcp/src/lib/encodings.ts +95 -61
  140. package/packages/mistralai-gcp/src/lib/primitives.ts +14 -0
  141. package/packages/mistralai-gcp/src/lib/schemas.ts +5 -0
  142. package/packages/mistralai-gcp/src/lib/sdks.ts +4 -1
  143. package/packages/mistralai-gcp/src/models/components/chatcompletionrequest.ts +10 -0
  144. package/packages/mistralai-gcp/src/models/components/chatcompletionstreamrequest.ts +10 -0
  145. package/packages/mistralai-gcp/src/models/components/function.ts +4 -0
  146. package/packages/mistralai-gcp/src/models/components/index.ts +1 -0
  147. package/packages/mistralai-gcp/src/models/components/prediction.ts +93 -0
  148. package/packages/mistralai-gcp/src/models/components/toolcall.ts +4 -0
  149. package/packages/mistralai-gcp/tsconfig.json +41 -0
  150. package/sdk/chat.d.ts +17 -0
  151. package/sdk/chat.d.ts.map +1 -1
  152. package/sdk/chat.js +27 -0
  153. package/sdk/chat.js.map +1 -1
  154. package/sdk/classifiers.d.ts +1 -1
  155. package/sdk/classifiers.d.ts.map +1 -1
  156. package/sdk/classifiers.js.map +1 -1
  157. package/sdk/ocr.d.ts +9 -0
  158. package/sdk/ocr.d.ts.map +1 -0
  159. package/sdk/ocr.js +19 -0
  160. package/sdk/ocr.js.map +1 -0
  161. package/sdk/sdk.d.ts +3 -0
  162. package/sdk/sdk.d.ts.map +1 -1
  163. package/sdk/sdk.js +4 -0
  164. package/sdk/sdk.js.map +1 -1
  165. package/src/extra/README.md +52 -0
  166. package/src/extra/structChat.ts +81 -0
  167. package/src/funcs/classifiersModerateChat.ts +2 -2
  168. package/src/funcs/ocrProcess.ts +131 -0
  169. package/src/lib/config.ts +3 -3
  170. package/src/models/components/assistantmessage.ts +3 -0
  171. package/src/models/components/chatcompletionrequest.ts +4 -4
  172. package/src/models/components/chatcompletionstreamrequest.ts +4 -4
  173. package/src/models/components/{chatclassificationrequest.ts → chatmoderationrequest.ts} +53 -47
  174. package/src/models/components/classificationrequest.ts +7 -4
  175. package/src/models/components/contentchunk.ts +20 -2
  176. package/src/models/components/documenturlchunk.ts +88 -0
  177. package/src/models/components/embeddingrequest.ts +5 -14
  178. package/src/models/components/fimcompletionrequest.ts +4 -4
  179. package/src/models/components/fimcompletionstreamrequest.ts +4 -4
  180. package/src/models/components/index.ts +9 -1
  181. package/src/models/components/jsonschema.ts +83 -0
  182. package/src/models/components/ocrimageobject.ts +117 -0
  183. package/src/models/components/ocrpagedimensions.ts +83 -0
  184. package/src/models/components/ocrpageobject.ts +98 -0
  185. package/src/models/components/ocrrequest.ts +183 -0
  186. package/src/models/components/ocrresponse.ts +97 -0
  187. package/src/models/components/ocrusageinfo.ts +83 -0
  188. package/src/models/components/prediction.ts +1 -28
  189. package/src/models/components/responseformat.ts +19 -0
  190. package/src/models/components/responseformats.ts +1 -0
  191. package/src/sdk/chat.ts +53 -0
  192. package/src/sdk/classifiers.ts +1 -1
  193. package/src/sdk/ocr.ts +24 -0
  194. package/src/sdk/sdk.ts +6 -0
  195. package/tests/extra/structChat.test.ts +194 -0
  196. package/tests/jest.config.js +5 -0
  197. package/tests/package-lock.json +3847 -0
  198. package/tests/package.json +17 -0
  199. package/tests/tsconfig.json +16 -0
  200. package/models/components/chatclassificationrequest.d.ts.map +0 -1
  201. package/models/components/chatclassificationrequest.js.map +0 -1
package/README.md CHANGED
@@ -190,11 +190,11 @@ const mistral = new Mistral({
190
190
 
191
191
  async function run() {
192
192
  const result = await mistral.embeddings.create({
193
+ model: "mistral-embed",
193
194
  inputs: [
194
195
  "Embed this sentence.",
195
196
  "As well as this one.",
196
197
  ],
197
- model: "mistral-embed",
198
198
  });
199
199
 
200
200
  // Handle the result
@@ -283,6 +283,10 @@ We have dedicated SDKs for the following providers:
283
283
  * [archive](docs/sdks/models/README.md#archive) - Archive Fine Tuned Model
284
284
  * [unarchive](docs/sdks/models/README.md#unarchive) - Unarchive Fine Tuned Model
285
285
 
286
+ ### [ocr](docs/sdks/ocr/README.md)
287
+
288
+ * [process](docs/sdks/ocr/README.md#process) - OCR
289
+
286
290
  </details>
287
291
  <!-- End Available Resources and Operations [operations] -->
288
292
 
@@ -687,6 +691,7 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
687
691
  - [`modelsRetrieve`](docs/sdks/models/README.md#retrieve) - Retrieve Model
688
692
  - [`modelsUnarchive`](docs/sdks/models/README.md#unarchive) - Unarchive Fine Tuned Model
689
693
  - [`modelsUpdate`](docs/sdks/models/README.md#update) - Update Fine Tuned Model
694
+ - [`ocrProcess`](docs/sdks/ocr/README.md#process) - OCR
690
695
 
691
696
  </details>
692
697
  <!-- End Standalone functions [standalone-funcs] -->
@@ -25,6 +25,7 @@ const mistral = new Mistral({
25
25
 
26
26
  async function run() {
27
27
  const result = await mistral.classifiers.moderate({
28
+ model: "V90",
28
29
  inputs: [
29
30
  "<value>",
30
31
  ],
@@ -53,6 +54,7 @@ const mistral = new MistralCore({
53
54
 
54
55
  async function run() {
55
56
  const res = await classifiersModerate(mistral, {
57
+ model: "V90",
56
58
  inputs: [
57
59
  "<value>",
58
60
  ],
@@ -106,6 +108,7 @@ const mistral = new Mistral({
106
108
 
107
109
  async function run() {
108
110
  const result = await mistral.classifiers.moderateChat({
111
+ model: "Roadster",
109
112
  inputs: [
110
113
  [
111
114
  {
@@ -136,7 +139,7 @@ async function run() {
136
139
  },
137
140
  ],
138
141
  ],
139
- model: "Roadster",
142
+ truncateForContextLength: false,
140
143
  });
141
144
 
142
145
  // Handle the result
@@ -162,6 +165,7 @@ const mistral = new MistralCore({
162
165
 
163
166
  async function run() {
164
167
  const res = await classifiersModerateChat(mistral, {
168
+ model: "Roadster",
165
169
  inputs: [
166
170
  [
167
171
  {
@@ -192,7 +196,7 @@ async function run() {
192
196
  },
193
197
  ],
194
198
  ],
195
- model: "Roadster",
199
+ truncateForContextLength: false,
196
200
  });
197
201
 
198
202
  if (!res.ok) {
@@ -212,7 +216,7 @@ run();
212
216
 
213
217
  | Parameter | Type | Required | Description |
214
218
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
215
- | `request` | [components.ChatClassificationRequest](../../models/components/chatclassificationrequest.md) | :heavy_check_mark: | The request object to use for the request. |
219
+ | `request` | [components.ChatModerationRequest](../../models/components/chatmoderationrequest.md) | :heavy_check_mark: | The request object to use for the request. |
216
220
  | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
217
221
  | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
218
222
  | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
@@ -24,11 +24,11 @@ const mistral = new Mistral({
24
24
 
25
25
  async function run() {
26
26
  const result = await mistral.embeddings.create({
27
+ model: "mistral-embed",
27
28
  inputs: [
28
29
  "Embed this sentence.",
29
30
  "As well as this one.",
30
31
  ],
31
- model: "mistral-embed",
32
32
  });
33
33
 
34
34
  // Handle the result
@@ -54,11 +54,11 @@ const mistral = new MistralCore({
54
54
 
55
55
  async function run() {
56
56
  const res = await embeddingsCreate(mistral, {
57
+ model: "mistral-embed",
57
58
  inputs: [
58
59
  "Embed this sentence.",
59
60
  "As well as this one.",
60
61
  ],
61
- model: "mistral-embed",
62
62
  });
63
63
 
64
64
  if (!res.ok) {
@@ -0,0 +1,93 @@
1
+ # Ocr
2
+ (*ocr*)
3
+
4
+ ## Overview
5
+
6
+ OCR API
7
+
8
+ ### Available Operations
9
+
10
+ * [process](#process) - OCR
11
+
12
+ ## process
13
+
14
+ OCR
15
+
16
+ ### Example Usage
17
+
18
+ ```typescript
19
+ import { Mistral } from "@mistralai/mistralai";
20
+
21
+ const mistral = new Mistral({
22
+ apiKey: process.env["MISTRAL_API_KEY"] ?? "",
23
+ });
24
+
25
+ async function run() {
26
+ const result = await mistral.ocr.process({
27
+ model: "Focus",
28
+ document: {
29
+ documentUrl: "https://dutiful-horst.org",
30
+ },
31
+ });
32
+
33
+ // Handle the result
34
+ console.log(result);
35
+ }
36
+
37
+ run();
38
+ ```
39
+
40
+ ### Standalone function
41
+
42
+ The standalone function version of this method:
43
+
44
+ ```typescript
45
+ import { MistralCore } from "@mistralai/mistralai/core.js";
46
+ import { ocrProcess } from "@mistralai/mistralai/funcs/ocrProcess.js";
47
+
48
+ // Use `MistralCore` for best tree-shaking performance.
49
+ // You can create one instance of it to use across an application.
50
+ const mistral = new MistralCore({
51
+ apiKey: process.env["MISTRAL_API_KEY"] ?? "",
52
+ });
53
+
54
+ async function run() {
55
+ const res = await ocrProcess(mistral, {
56
+ model: "Focus",
57
+ document: {
58
+ documentUrl: "https://dutiful-horst.org",
59
+ },
60
+ });
61
+
62
+ if (!res.ok) {
63
+ throw res.error;
64
+ }
65
+
66
+ const { value: result } = res;
67
+
68
+ // Handle the result
69
+ console.log(result);
70
+ }
71
+
72
+ run();
73
+ ```
74
+
75
+ ### Parameters
76
+
77
+ | Parameter | Type | Required | Description |
78
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
79
+ | `request` | [components.OCRRequest](../../models/components/ocrrequest.md) | :heavy_check_mark: | The request object to use for the request. |
80
+ | `options` | RequestOptions | :heavy_minus_sign: | Used to set various options for making HTTP requests. |
81
+ | `options.fetchOptions` | [RequestInit](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) | :heavy_minus_sign: | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All `Request` options, except `method` and `body`, are allowed. |
82
+ | `options.retries` | [RetryConfig](../../lib/utils/retryconfig.md) | :heavy_minus_sign: | Enables retrying HTTP requests under certain failure conditions. |
83
+
84
+ ### Response
85
+
86
+ **Promise\<[components.OCRResponse](../../models/components/ocrresponse.md)\>**
87
+
88
+ ### Errors
89
+
90
+ | Error Type | Status Code | Content Type |
91
+ | -------------------------- | -------------------------- | -------------------------- |
92
+ | errors.HTTPValidationError | 422 | application/json |
93
+ | errors.SDKError | 4XX, 5XX | \*/\* |
@@ -5,25 +5,35 @@ Below is a guide how to run the examples if you have cloned this repo.
5
5
  ## Prerequisites
6
6
 
7
7
  - Node.js v18+
8
- - `cp .env.template .env` and fill in the fields corresponding to the examples you want to run.
9
8
 
10
- ## Install
9
+ ## How to run the examples locally
11
10
 
12
- - You'll need to run `npm install` in the root of the repository
13
- - You'll need to run `npm install` in `packages/gcp` directory
14
- - You'll need to run `npm install` in `packages/azure` directory
15
- - Finally, you'll need to run `npm install` in this `examples` directory
16
-
17
- ## Run
18
-
19
- ```
20
- npm run script -- ./src/chat_streaming.ts
11
+ ### Install the npm dependencies or the repository and the `examples` directory
12
+ ```properties
13
+ npm install && npm install --prefix examples
21
14
  ```
22
15
 
23
- ## Test
16
+ ### Set your environment variables
17
+ ```properties
18
+ cp examples/.env.template examples/.env
19
+ # Edit your .env file
20
+ ```
24
21
 
25
- The following will run all `examples` directory:
22
+ ### [Dev only] Link the local `mistralai` package
26
23
 
24
+ If you want to use the local `mistralai` package, you can link it to the examples directory. From the repository's root:
25
+ ```properties
26
+ npm run build
27
+ npm link
28
+ (cd examples/src && npm link @mistralai/mistralai)
27
29
  ```
28
- npm run test
30
+
31
+ ### Run the examples
32
+ ```properties
33
+ npm run test --prefix examples
29
34
  ```
35
+
36
+ If you just want to run one example file, you can do so with:
37
+ ```properties
38
+ npm run test --prefix examples -- --files src/stag_async_moderation.ts
39
+ ```
@@ -11,7 +11,8 @@
11
11
  "dependencies": {
12
12
  "@mistralai/mistralai": "file:../",
13
13
  "@mistralai/mistralai-azure": "file:../packages/mistralai-azure",
14
- "@mistralai/mistralai-gcp": "file:../packages/mistralai-gcp"
14
+ "@mistralai/mistralai-gcp": "file:../packages/mistralai-gcp",
15
+ "yargs": "^17.0.0"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@types/node": "^20.11.4",
@@ -22,7 +23,10 @@
22
23
  },
23
24
  "..": {
24
25
  "name": "@mistralai/mistralai",
25
- "version": "1.4.0",
26
+ "version": "1.5.1",
27
+ "dependencies": {
28
+ "zod-to-json-schema": "^3.24.1"
29
+ },
26
30
  "devDependencies": {
27
31
  "@typescript-eslint/eslint-plugin": "^7.7.1",
28
32
  "@typescript-eslint/parser": "^7.7.1",
@@ -38,7 +42,7 @@
38
42
  },
39
43
  "../packages/mistralai-azure": {
40
44
  "name": "@mistralai/mistralai-azure",
41
- "version": "1.3.6",
45
+ "version": "1.4.0",
42
46
  "devDependencies": {
43
47
  "@typescript-eslint/eslint-plugin": "^7.7.1",
44
48
  "@typescript-eslint/parser": "^7.7.1",
@@ -54,7 +58,7 @@
54
58
  },
55
59
  "../packages/mistralai-gcp": {
56
60
  "name": "@mistralai/mistralai-gcp",
57
- "version": "1.3.6",
61
+ "version": "1.4.0",
58
62
  "dependencies": {
59
63
  "google-auth-library": "^9.11.0"
60
64
  },
@@ -573,11 +577,97 @@
573
577
  "balanced-match": "^1.0.0"
574
578
  }
575
579
  },
580
+ "node_modules/cliui": {
581
+ "version": "8.0.1",
582
+ "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
583
+ "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
584
+ "license": "ISC",
585
+ "dependencies": {
586
+ "string-width": "^4.2.0",
587
+ "strip-ansi": "^6.0.1",
588
+ "wrap-ansi": "^7.0.0"
589
+ },
590
+ "engines": {
591
+ "node": ">=12"
592
+ }
593
+ },
594
+ "node_modules/cliui/node_modules/ansi-regex": {
595
+ "version": "5.0.1",
596
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
597
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
598
+ "license": "MIT",
599
+ "engines": {
600
+ "node": ">=8"
601
+ }
602
+ },
603
+ "node_modules/cliui/node_modules/ansi-styles": {
604
+ "version": "4.3.0",
605
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
606
+ "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
607
+ "license": "MIT",
608
+ "dependencies": {
609
+ "color-convert": "^2.0.1"
610
+ },
611
+ "engines": {
612
+ "node": ">=8"
613
+ },
614
+ "funding": {
615
+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"
616
+ }
617
+ },
618
+ "node_modules/cliui/node_modules/emoji-regex": {
619
+ "version": "8.0.0",
620
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
621
+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
622
+ "license": "MIT"
623
+ },
624
+ "node_modules/cliui/node_modules/string-width": {
625
+ "version": "4.2.3",
626
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
627
+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
628
+ "license": "MIT",
629
+ "dependencies": {
630
+ "emoji-regex": "^8.0.0",
631
+ "is-fullwidth-code-point": "^3.0.0",
632
+ "strip-ansi": "^6.0.1"
633
+ },
634
+ "engines": {
635
+ "node": ">=8"
636
+ }
637
+ },
638
+ "node_modules/cliui/node_modules/strip-ansi": {
639
+ "version": "6.0.1",
640
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
641
+ "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
642
+ "license": "MIT",
643
+ "dependencies": {
644
+ "ansi-regex": "^5.0.1"
645
+ },
646
+ "engines": {
647
+ "node": ">=8"
648
+ }
649
+ },
650
+ "node_modules/cliui/node_modules/wrap-ansi": {
651
+ "version": "7.0.0",
652
+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
653
+ "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
654
+ "license": "MIT",
655
+ "dependencies": {
656
+ "ansi-styles": "^4.0.0",
657
+ "string-width": "^4.1.0",
658
+ "strip-ansi": "^6.0.0"
659
+ },
660
+ "engines": {
661
+ "node": ">=10"
662
+ },
663
+ "funding": {
664
+ "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
665
+ }
666
+ },
576
667
  "node_modules/color-convert": {
577
668
  "version": "2.0.1",
578
669
  "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
579
670
  "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
580
- "dev": true,
581
671
  "license": "MIT",
582
672
  "dependencies": {
583
673
  "color-name": "~1.1.4"
@@ -590,7 +680,6 @@
590
680
  "version": "1.1.4",
591
681
  "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
592
682
  "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
593
- "dev": true,
594
683
  "license": "MIT"
595
684
  },
596
685
  "node_modules/cross-spawn": {
@@ -662,6 +751,15 @@
662
751
  "@esbuild/win32-x64": "0.23.1"
663
752
  }
664
753
  },
754
+ "node_modules/escalade": {
755
+ "version": "3.2.0",
756
+ "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
757
+ "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
758
+ "license": "MIT",
759
+ "engines": {
760
+ "node": ">=6"
761
+ }
762
+ },
665
763
  "node_modules/foreground-child": {
666
764
  "version": "3.3.0",
667
765
  "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz",
@@ -694,6 +792,15 @@
694
792
  "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
695
793
  }
696
794
  },
795
+ "node_modules/get-caller-file": {
796
+ "version": "2.0.5",
797
+ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
798
+ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
799
+ "license": "ISC",
800
+ "engines": {
801
+ "node": "6.* || 8.* || >= 10.*"
802
+ }
803
+ },
697
804
  "node_modules/get-tsconfig": {
698
805
  "version": "4.8.1",
699
806
  "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz",
@@ -735,7 +842,6 @@
735
842
  "version": "3.0.0",
736
843
  "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
737
844
  "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
738
- "dev": true,
739
845
  "license": "MIT",
740
846
  "engines": {
741
847
  "node": ">=8"
@@ -853,6 +959,15 @@
853
959
  "url": "https://github.com/prettier/prettier?sponsor=1"
854
960
  }
855
961
  },
962
+ "node_modules/require-directory": {
963
+ "version": "2.1.1",
964
+ "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
965
+ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
966
+ "license": "MIT",
967
+ "engines": {
968
+ "node": ">=0.10.0"
969
+ }
970
+ },
856
971
  "node_modules/resolve-pkg-maps": {
857
972
  "version": "1.0.0",
858
973
  "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
@@ -1143,6 +1258,83 @@
1143
1258
  "engines": {
1144
1259
  "node": ">=8"
1145
1260
  }
1261
+ },
1262
+ "node_modules/y18n": {
1263
+ "version": "5.0.8",
1264
+ "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
1265
+ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
1266
+ "license": "ISC",
1267
+ "engines": {
1268
+ "node": ">=10"
1269
+ }
1270
+ },
1271
+ "node_modules/yargs": {
1272
+ "version": "17.7.2",
1273
+ "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
1274
+ "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
1275
+ "license": "MIT",
1276
+ "dependencies": {
1277
+ "cliui": "^8.0.1",
1278
+ "escalade": "^3.1.1",
1279
+ "get-caller-file": "^2.0.5",
1280
+ "require-directory": "^2.1.1",
1281
+ "string-width": "^4.2.3",
1282
+ "y18n": "^5.0.5",
1283
+ "yargs-parser": "^21.1.1"
1284
+ },
1285
+ "engines": {
1286
+ "node": ">=12"
1287
+ }
1288
+ },
1289
+ "node_modules/yargs-parser": {
1290
+ "version": "21.1.1",
1291
+ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
1292
+ "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
1293
+ "license": "ISC",
1294
+ "engines": {
1295
+ "node": ">=12"
1296
+ }
1297
+ },
1298
+ "node_modules/yargs/node_modules/ansi-regex": {
1299
+ "version": "5.0.1",
1300
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
1301
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
1302
+ "license": "MIT",
1303
+ "engines": {
1304
+ "node": ">=8"
1305
+ }
1306
+ },
1307
+ "node_modules/yargs/node_modules/emoji-regex": {
1308
+ "version": "8.0.0",
1309
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
1310
+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
1311
+ "license": "MIT"
1312
+ },
1313
+ "node_modules/yargs/node_modules/string-width": {
1314
+ "version": "4.2.3",
1315
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
1316
+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
1317
+ "license": "MIT",
1318
+ "dependencies": {
1319
+ "emoji-regex": "^8.0.0",
1320
+ "is-fullwidth-code-point": "^3.0.0",
1321
+ "strip-ansi": "^6.0.1"
1322
+ },
1323
+ "engines": {
1324
+ "node": ">=8"
1325
+ }
1326
+ },
1327
+ "node_modules/yargs/node_modules/strip-ansi": {
1328
+ "version": "6.0.1",
1329
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
1330
+ "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
1331
+ "license": "MIT",
1332
+ "dependencies": {
1333
+ "ansi-regex": "^5.0.1"
1334
+ },
1335
+ "engines": {
1336
+ "node": ">=8"
1337
+ }
1146
1338
  }
1147
1339
  }
1148
1340
  }
@@ -18,7 +18,8 @@
18
18
  "dependencies": {
19
19
  "@mistralai/mistralai": "file:../",
20
20
  "@mistralai/mistralai-azure": "file:../packages/mistralai-azure",
21
- "@mistralai/mistralai-gcp": "file:../packages/mistralai-gcp"
21
+ "@mistralai/mistralai-gcp": "file:../packages/mistralai-gcp",
22
+ "yargs": "^17.0.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "glob": "^11.0.0",
@@ -0,0 +1,33 @@
1
+ import { Mistral } from '@mistralai/mistralai';
2
+ import fs from 'fs';
3
+
4
+ const apiKey = process.env.MISTRAL_API_KEY;
5
+
6
+ const client = new Mistral({ apiKey: apiKey });
7
+
8
+
9
+ const file_path = "/path/to/uploaded_file.pdf"
10
+ const uploaded_file = fs.readFileSync(file_path);
11
+ const uploaded_pdf = await client.files.upload({
12
+ file: {
13
+ fileName: "uploaded_file.pdf",
14
+ content: uploaded_file,
15
+ },
16
+ purpose: "ocr"
17
+ });
18
+
19
+ client.files.retrieve({ fileId: uploaded_pdf.id })
20
+
21
+ const signed_url = client.files.getSignedUrl({ fileId: uploaded_pdf.id })
22
+
23
+
24
+
25
+ const ocrResponse = await client.ocr.process({
26
+ model: "mistral-ocr-latest",
27
+ document: {
28
+ type: "document_url",
29
+ documentUrl: "https://arxiv.org/pdf/2201.04234"
30
+ },
31
+ include_image_base64: true
32
+ });
33
+ console.log("OCR ", ocrResponse);
@@ -0,0 +1,15 @@
1
+ import { Mistral } from '@mistralai/mistralai';
2
+
3
+ const apiKey = process.env.MISTRAL_API_KEY;
4
+ const client = new Mistral({ apiKey: apiKey });
5
+
6
+ const ocrResponse = await client.ocr.process({
7
+ model: "mistral-ocr-latest",
8
+ document: {
9
+ type: "document_url",
10
+ documentUrl: "https://arxiv.org/pdf/2201.04234"
11
+ },
12
+ include_image_base64: true
13
+ });
14
+
15
+ console.log("OCR:", ocrResponse);