Skip to content

Commit 02dfca7

Browse files
authored
fix: update package.json for examples #133
2 parents eaf7cd4 + 54e5275 commit 02dfca7

14 files changed

Lines changed: 121 additions & 85 deletions

.speakeasy/gen.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typescript:
3535
envVarPrefix: MISTRAL
3636
flattenGlobalSecurity: true
3737
flatteningOrder: body-first
38+
generateExamples: true
3839
imports:
3940
option: openapi
4041
paths:

examples/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ Below is a guide how to run the examples if you have cloned this repo.
99
## How to run the examples locally
1010

1111
### Install the npm dependencies or the repository and the `examples` directory
12+
1213
```properties
1314
npm install && npm install --prefix examples
1415
```
1516

1617
### Set your environment variables
18+
1719
```properties
1820
cp examples/.env.template examples/.env
1921
# Edit your .env file
@@ -22,18 +24,21 @@ cp examples/.env.template examples/.env
2224
### [Dev only] Link the local `mistralai` package
2325

2426
If you want to use the local `mistralai` package, you can link it to the examples directory. From the repository's root:
27+
2528
```properties
2629
npm run build
2730
npm link
2831
(cd examples/src && npm link @mistralai/mistralai)
2932
```
3033

3134
### Run the examples
35+
3236
```properties
3337
npm run test --prefix examples
3438
```
3539

3640
If you just want to run one example file, you can do so with:
41+
3742
```properties
3843
npm run test --prefix examples -- --files src/stag_async_moderation.ts
39-
```
44+
```

examples/package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"gcp": "npm run script -- ./src/gcp/async_chat_no_streaming.ts",
1111
"azure": "npm run script -- ./src/azure/async_chat_no_streaming.ts",
1212
"format": "prettier --write .",
13-
"test": "tsx ./test.ts"
13+
"test": "tsx ./test.ts",
14+
"build:examples": "echo 'skipping build examples'"
1415
},
1516
"keywords": [],
1617
"author": "",
@@ -22,9 +23,10 @@
2223
"yargs": "^17.0.0"
2324
},
2425
"devDependencies": {
25-
"glob": "^11.0.0",
2626
"@types/node": "^20.11.4",
27+
"glob": "^11.0.0",
2728
"prettier": "3.3.3",
28-
"tsx": "^4.7.0"
29+
"tsx": "^4.7.0",
30+
"typescript": "^5.9.2"
2931
}
30-
}
32+
}

examples/src/async_audio_transcription_stream.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { Mistral } from "@mistralai/mistralai";
22

33
const apiKey = process.env["MISTRAL_API_KEY"];
44
if (!apiKey) {
5-
throw new Error("missing MISTRAL_API_KEY environment variable");
5+
throw new Error("missing MISTRAL_API_KEY environment variable");
66
}
77

88
const mistral = new Mistral({ apiKey: apiKey });
99

1010
const stream = await mistral.audio.transcriptions.stream({
11-
model: "voxtral-mini-latest",
12-
fileUrl: "https://docs.mistral.ai/audio/bcn_weather.mp3",
11+
model: "voxtral-mini-latest",
12+
fileUrl: "https://docs.mistral.ai/audio/bcn_weather.mp3",
1313
});
1414

1515
for await (const event of stream) {
16-
process.stdout.write(JSON.stringify(event));
17-
process.stdout.write("\n");
16+
process.stdout.write(JSON.stringify(event));
17+
process.stdout.write("\n");
1818
}

examples/src/async_chat_prediction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const chatResponse = await client.chat.complete({
2222
model: "codestral-latest",
2323
messages: [
2424
{ role: "user", content: refactorPrompt },
25-
{ role: "user", content: code }
25+
{ role: "user", content: code },
2626
],
2727
prediction: {
2828
type: "content",
29-
content: code
30-
}
29+
content: code,
30+
},
3131
});
3232

33-
console.log(chatResponse.choices[0].message.content);
33+
console.log(chatResponse.choices[0]?.message.content);

examples/src/async_files.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from "fs";
22
import { Mistral } from "@mistralai/mistralai";
3-
import path from 'path';
3+
import path from "path";
44
import { fileURLToPath } from "url";
55

66
const apiKey = process.env["MISTRAL_API_KEY"];
@@ -19,7 +19,7 @@ const filePath = path.join(__dirname, "file.jsonl");
1919
const blob = new Blob([fs.readFileSync(filePath)], {
2020
type: "application/json",
2121
});
22-
const createdFile = await client.files.upload({ file: blob, });
22+
const createdFile = await client.files.upload({ file: blob });
2323

2424
console.log(createdFile);
2525

examples/src/async_function_calling_streaming.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ stream = await client.chat.stream({
131131
let full_tool_call: ToolCall[] = [];
132132

133133
for await (const event of stream) {
134-
135134
const toolCalls = event.data?.choices[0]?.delta.toolCalls;
136135
if (!toolCalls) {
137136
continue;
@@ -177,4 +176,4 @@ for await (const event of stream) {
177176

178177
process.stdout.write(content);
179178
}
180-
console.log("\ndone")
179+
console.log("\ndone");

examples/src/async_jobs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from "fs";
22
import { Mistral } from "@mistralai/mistralai";
3-
import path from 'path';
3+
import path from "path";
44
import { fileURLToPath } from "url";
55

66
const apiKey = process.env["MISTRAL_API_KEY"];
@@ -39,7 +39,9 @@ const jobs = await mistral.fineTuning.jobs.list();
3939
console.log(jobs);
4040

4141
// Retrieve a job
42-
const retrievedJob = await mistral.fineTuning.jobs.get({ jobId: createdJob.id });
42+
const retrievedJob = await mistral.fineTuning.jobs.get({
43+
jobId: createdJob.id,
44+
});
4345
console.log(retrievedJob);
4446

4547
// Cancel a job
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import { Mistral } from '@mistralai/mistralai';
2-
import fs from 'fs';
3-
import path from 'path';
1+
import { Mistral } from "@mistralai/mistralai";
2+
import fs from "fs";
3+
import path from "path";
44
import { fileURLToPath } from "url";
55

66
const apiKey = process.env.MISTRAL_API_KEY;
77

88
const client = new Mistral({ apiKey: apiKey });
99

10-
1110
// Get the absolute directory path
1211
const __filename = fileURLToPath(import.meta.url);
1312
const __dirname = path.dirname(__filename);
14-
const filePath = path.join(__dirname, "ocr.pdf")
13+
const filePath = path.join(__dirname, "ocr.pdf");
1514

1615
// Upload the file and run ocr
1716
const uploaded_file = fs.readFileSync(filePath);
1817
const uploaded_pdf = await client.files.upload({
19-
file: {
20-
fileName: "uploaded_file.pdf",
21-
content: uploaded_file,
22-
},
23-
purpose: "ocr"
18+
file: {
19+
fileName: "uploaded_file.pdf",
20+
content: uploaded_file,
21+
},
22+
purpose: "ocr",
2423
});
2524

2625
const ocrResponse = await client.ocr.process({
27-
model: "mistral-ocr-latest",
28-
document: {
29-
type: "file",
30-
fileId: uploaded_pdf.id
31-
},
32-
includeImageBase64: true
26+
model: "mistral-ocr-latest",
27+
document: {
28+
type: "file",
29+
fileId: uploaded_pdf.id,
30+
},
31+
includeImageBase64: true,
3332
});
34-
console.log("OCR ", ocrResponse);
33+
console.log("OCR ", ocrResponse);

0 commit comments

Comments
 (0)