@@ -37,7 +37,7 @@ const client = new OpenAI({
37
37
});
38
38
39
39
async function main () {
40
- const chatCompletion = await openai .chat .completions .create ({
40
+ const chatCompletion = await client .chat .completions .create ({
41
41
messages: [{ role: ' user' , content: ' Say this is a test' }],
42
42
model: ' gpt-3.5-turbo' ,
43
43
});
@@ -56,7 +56,7 @@ import OpenAI from 'openai';
56
56
const client = new OpenAI ();
57
57
58
58
async function main() {
59
- const stream = await openai .chat .completions .create ({
59
+ const stream = await client .chat .completions .create ({
60
60
model: ' gpt-4' ,
61
61
messages: [{ role: ' user' , content: ' Say this is a test' }],
62
62
stream: true ,
@@ -89,7 +89,7 @@ async function main() {
89
89
messages: [{ role: ' user' , content: ' Say this is a test' }],
90
90
model: ' gpt-3.5-turbo' ,
91
91
};
92
- const chatCompletion: OpenAI .Chat .ChatCompletion = await openai .chat .completions .create (params );
92
+ const chatCompletion: OpenAI .Chat .ChatCompletion = await client .chat .completions .create (params );
93
93
}
94
94
95
95
main ();
@@ -304,20 +304,20 @@ import OpenAI, { toFile } from 'openai';
304
304
const client = new OpenAI ();
305
305
306
306
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
307
- await openai .files .create ({ file: fs .createReadStream (' input.jsonl' ), purpose: ' fine-tune' });
307
+ await client .files .create ({ file: fs .createReadStream (' input.jsonl' ), purpose: ' fine-tune' });
308
308
309
309
// Or if you have the web `File` API you can pass a `File` instance:
310
- await openai .files .create ({ file: new File ([' my bytes' ], ' input.jsonl' ), purpose: ' fine-tune' });
310
+ await client .files .create ({ file: new File ([' my bytes' ], ' input.jsonl' ), purpose: ' fine-tune' });
311
311
312
312
// You can also pass a `fetch` `Response`:
313
- await openai .files .create ({ file: await fetch (' https://somesite/input.jsonl' ), purpose: ' fine-tune' });
313
+ await client .files .create ({ file: await fetch (' https://somesite/input.jsonl' ), purpose: ' fine-tune' });
314
314
315
315
// Finally, if none of the above are convenient, you can use our `toFile` helper:
316
- await openai .files .create ({
316
+ await client .files .create ({
317
317
file: await toFile (Buffer .from (' my bytes' ), ' input.jsonl' ),
318
318
purpose: ' fine-tune' ,
319
319
});
320
- await openai .files .create ({
320
+ await client .files .create ({
321
321
file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' input.jsonl' ),
322
322
purpose: ' fine-tune' ,
323
323
});
@@ -332,7 +332,7 @@ a subclass of `APIError` will be thrown:
332
332
<!-- prettier-ignore -->
333
333
``` ts
334
334
async function main() {
335
- const job = await openai .fineTuning .jobs
335
+ const job = await client .fineTuning .jobs
336
336
.create ({ model: ' gpt-3.5-turbo' , training_file: ' file-abc123' })
337
337
.catch (async (err ) => {
338
338
if (err instanceof OpenAI .APIError ) {
@@ -404,7 +404,7 @@ const client = new OpenAI({
404
404
});
405
405
406
406
// Or, configure per-request:
407
- await openai .chat .completions .create ({ messages: [{ role: ' user' , content: ' How can I get the name of the current day in Node.js?' }], model: ' gpt-3.5-turbo' }, {
407
+ await client .chat .completions .create ({ messages: [{ role: ' user' , content: ' How can I get the name of the current day in Node.js?' }], model: ' gpt-3.5-turbo' }, {
408
408
maxRetries: 5 ,
409
409
});
410
410
```
@@ -421,7 +421,7 @@ const client = new OpenAI({
421
421
});
422
422
423
423
// Override per-request:
424
- await openai .chat .completions .create ({ messages: [{ role: ' user' , content: ' How can I list all files in a directory using Python?' }], model: ' gpt-3.5-turbo' }, {
424
+ await client .chat .completions .create ({ messages: [{ role: ' user' , content: ' How can I list all files in a directory using Python?' }], model: ' gpt-3.5-turbo' }, {
425
425
timeout: 5 * 1000 ,
426
426
});
427
427
```
@@ -439,7 +439,7 @@ You can use `for await … of` syntax to iterate through items across all pages:
439
439
async function fetchAllFineTuningJobs(params ) {
440
440
const allFineTuningJobs = [];
441
441
// Automatically fetches more pages as needed.
442
- for await (const fineTuningJob of openai .fineTuning .jobs .list ({ limit: 20 })) {
442
+ for await (const fineTuningJob of client .fineTuning .jobs .list ({ limit: 20 })) {
443
443
allFineTuningJobs .push (fineTuningJob );
444
444
}
445
445
return allFineTuningJobs ;
@@ -449,7 +449,7 @@ async function fetchAllFineTuningJobs(params) {
449
449
Alternatively, you can make request a single page at a time:
450
450
451
451
``` ts
452
- let page = await openai .fineTuning .jobs .list ({ limit: 20 });
452
+ let page = await client .fineTuning .jobs .list ({ limit: 20 });
453
453
for (const fineTuningJob of page .data ) {
454
454
console .log (fineTuningJob );
455
455
}
@@ -473,13 +473,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
473
473
``` ts
474
474
const client = new OpenAI ();
475
475
476
- const response = await openai .chat .completions
476
+ const response = await client .chat .completions
477
477
.create ({ messages: [{ role: ' user' , content: ' Say this is a test' }], model: ' gpt-3.5-turbo' })
478
478
.asResponse ();
479
479
console .log (response .headers .get (' X-My-Header' ));
480
480
console .log (response .statusText ); // access the underlying Response object
481
481
482
- const { data : chatCompletion, response : raw } = await openai .chat .completions
482
+ const { data : chatCompletion, response : raw } = await client .chat .completions
483
483
.create ({ messages: [{ role: ' user' , content: ' Say this is a test' }], model: ' gpt-3.5-turbo' })
484
484
.withResponse ();
485
485
console .log (raw .headers .get (' X-My-Header' ));
@@ -587,7 +587,7 @@ const client = new OpenAI({
587
587
});
588
588
589
589
// Override per-request:
590
- await openai .models .list ({
590
+ await client .models .list ({
591
591
httpAgent: new http .Agent ({ keepAlive: false }),
592
592
});
593
593
```
0 commit comments