From f696b2a11399efbc5b4b17dc9d0f287dc3ba5e1a Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 26 Jul 2024 12:01:07 +0000 Subject: [PATCH] chore(docs): fix incorrect client var names (#955) --- README.md | 32 +++++++++---------- tests/api-resources/audio/speech.test.ts | 4 +-- .../audio/transcriptions.test.ts | 6 ++-- .../api-resources/audio/translations.test.ts | 6 ++-- tests/api-resources/batches.test.ts | 20 ++++++------ tests/api-resources/beta/assistants.test.ts | 22 ++++++------- .../beta/threads/messages.test.ts | 22 ++++++------- .../beta/threads/runs/runs.test.ts | 26 +++++++-------- .../beta/threads/runs/steps.test.ts | 12 +++---- .../beta/threads/threads.test.ts | 22 ++++++------- .../beta/vector-stores/file-batches.test.ts | 20 ++++++------ .../beta/vector-stores/files.test.ts | 20 ++++++------ .../beta/vector-stores/vector-stores.test.ts | 20 ++++++------ tests/api-resources/chat/completions.test.ts | 6 ++-- tests/api-resources/completions.test.ts | 6 ++-- tests/api-resources/embeddings.test.ts | 6 ++-- tests/api-resources/files.test.ts | 26 +++++++-------- .../fine-tuning/jobs/checkpoints.test.ts | 8 ++--- .../fine-tuning/jobs/jobs.test.ts | 26 +++++++-------- tests/api-resources/images.test.ts | 14 ++++---- tests/api-resources/models.test.ts | 14 ++++---- tests/api-resources/moderations.test.ts | 6 ++-- tests/api-resources/uploads/parts.test.ts | 6 ++-- tests/api-resources/uploads/uploads.test.ts | 14 ++++---- 24 files changed, 182 insertions(+), 182 deletions(-) diff --git a/README.md b/README.md index 06629fdda..88c132a4f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ const client = new OpenAI({ }); async function main() { - const chatCompletion = await openai.chat.completions.create({ + const chatCompletion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo', }); @@ -56,7 +56,7 @@ import OpenAI from 'openai'; const client = new OpenAI(); async function main() { - const stream = await openai.chat.completions.create({ + const stream = await client.chat.completions.create({ model: 'gpt-4', messages: [{ role: 'user', content: 'Say this is a test' }], stream: true, @@ -89,7 +89,7 @@ async function main() { messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo', }; - const chatCompletion: OpenAI.Chat.ChatCompletion = await openai.chat.completions.create(params); + const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params); } main(); @@ -304,20 +304,20 @@ import OpenAI, { toFile } from 'openai'; const client = new OpenAI(); // If you have access to Node `fs` we recommend using `fs.createReadStream()`: -await openai.files.create({ file: fs.createReadStream('input.jsonl'), purpose: 'fine-tune' }); +await client.files.create({ file: fs.createReadStream('input.jsonl'), purpose: 'fine-tune' }); // Or if you have the web `File` API you can pass a `File` instance: -await openai.files.create({ file: new File(['my bytes'], 'input.jsonl'), purpose: 'fine-tune' }); +await client.files.create({ file: new File(['my bytes'], 'input.jsonl'), purpose: 'fine-tune' }); // You can also pass a `fetch` `Response`: -await openai.files.create({ file: await fetch('https://somesite/input.jsonl'), purpose: 'fine-tune' }); +await client.files.create({ file: await fetch('https://somesite/input.jsonl'), purpose: 'fine-tune' }); // Finally, if none of the above are convenient, you can use our `toFile` helper: -await openai.files.create({ +await client.files.create({ file: await toFile(Buffer.from('my bytes'), 'input.jsonl'), purpose: 'fine-tune', }); -await openai.files.create({ +await client.files.create({ file: await toFile(new Uint8Array([0, 1, 2]), 'input.jsonl'), purpose: 'fine-tune', }); @@ -332,7 +332,7 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const job = await openai.fineTuning.jobs + const job = await client.fineTuning.jobs .create({ model: 'gpt-3.5-turbo', training_file: 'file-abc123' }) .catch(async (err) => { if (err instanceof OpenAI.APIError) { @@ -404,7 +404,7 @@ const client = new OpenAI({ }); // Or, configure per-request: -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' }, { +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' }, { maxRetries: 5, }); ``` @@ -421,7 +421,7 @@ const client = new OpenAI({ }); // Override per-request: -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' }, { +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' }, { timeout: 5 * 1000, }); ``` @@ -439,7 +439,7 @@ You can use `for await … of` syntax to iterate through items across all pages: async function fetchAllFineTuningJobs(params) { const allFineTuningJobs = []; // Automatically fetches more pages as needed. - for await (const fineTuningJob of openai.fineTuning.jobs.list({ limit: 20 })) { + for await (const fineTuningJob of client.fineTuning.jobs.list({ limit: 20 })) { allFineTuningJobs.push(fineTuningJob); } return allFineTuningJobs; @@ -449,7 +449,7 @@ async function fetchAllFineTuningJobs(params) { Alternatively, you can make request a single page at a time: ```ts -let page = await openai.fineTuning.jobs.list({ limit: 20 }); +let page = await client.fineTuning.jobs.list({ limit: 20 }); for (const fineTuningJob of page.data) { console.log(fineTuningJob); } @@ -473,13 +473,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts const client = new OpenAI(); -const response = await openai.chat.completions +const response = await client.chat.completions .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' }) .asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object -const { data: chatCompletion, response: raw } = await openai.chat.completions +const { data: chatCompletion, response: raw } = await client.chat.completions .create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-3.5-turbo' }) .withResponse(); console.log(raw.headers.get('X-My-Header')); @@ -587,7 +587,7 @@ const client = new OpenAI({ }); // Override per-request: -await openai.models.list({ +await client.models.list({ httpAgent: new http.Agent({ keepAlive: false }), }); ``` diff --git a/tests/api-resources/audio/speech.test.ts b/tests/api-resources/audio/speech.test.ts index 7509c19ca..904d75e5d 100644 --- a/tests/api-resources/audio/speech.test.ts +++ b/tests/api-resources/audio/speech.test.ts @@ -2,7 +2,7 @@ import OpenAI from 'openai'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); @@ -10,7 +10,7 @@ const openai = new OpenAI({ describe('resource speech', () => { // binary tests are currently broken test.skip('create: required and optional params', async () => { - const response = await openai.audio.speech.create({ + const response = await client.audio.speech.create({ input: 'input', model: 'string', voice: 'alloy', diff --git a/tests/api-resources/audio/transcriptions.test.ts b/tests/api-resources/audio/transcriptions.test.ts index 938ddd2b3..ef2797911 100644 --- a/tests/api-resources/audio/transcriptions.test.ts +++ b/tests/api-resources/audio/transcriptions.test.ts @@ -3,14 +3,14 @@ import OpenAI, { toFile } from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource transcriptions', () => { test('create: only required params', async () => { - const responsePromise = openai.audio.transcriptions.create({ + const responsePromise = client.audio.transcriptions.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), model: 'whisper-1', }); @@ -24,7 +24,7 @@ describe('resource transcriptions', () => { }); test('create: required and optional params', async () => { - const response = await openai.audio.transcriptions.create({ + const response = await client.audio.transcriptions.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), model: 'whisper-1', language: 'language', diff --git a/tests/api-resources/audio/translations.test.ts b/tests/api-resources/audio/translations.test.ts index 3f05bc90f..8264a5818 100644 --- a/tests/api-resources/audio/translations.test.ts +++ b/tests/api-resources/audio/translations.test.ts @@ -3,14 +3,14 @@ import OpenAI, { toFile } from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource translations', () => { test('create: only required params', async () => { - const responsePromise = openai.audio.translations.create({ + const responsePromise = client.audio.translations.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), model: 'whisper-1', }); @@ -24,7 +24,7 @@ describe('resource translations', () => { }); test('create: required and optional params', async () => { - const response = await openai.audio.translations.create({ + const response = await client.audio.translations.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), model: 'whisper-1', prompt: 'prompt', diff --git a/tests/api-resources/batches.test.ts b/tests/api-resources/batches.test.ts index 2861298a8..96e200fb9 100644 --- a/tests/api-resources/batches.test.ts +++ b/tests/api-resources/batches.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource batches', () => { test('create: only required params', async () => { - const responsePromise = openai.batches.create({ + const responsePromise = client.batches.create({ completion_window: '24h', endpoint: '/v1/chat/completions', input_file_id: 'input_file_id', @@ -25,7 +25,7 @@ describe('resource batches', () => { }); test('create: required and optional params', async () => { - const response = await openai.batches.create({ + const response = await client.batches.create({ completion_window: '24h', endpoint: '/v1/chat/completions', input_file_id: 'input_file_id', @@ -34,7 +34,7 @@ describe('resource batches', () => { }); test('retrieve', async () => { - const responsePromise = openai.batches.retrieve('batch_id'); + const responsePromise = client.batches.retrieve('batch_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -46,13 +46,13 @@ describe('resource batches', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.batches.retrieve('batch_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.batches.retrieve('batch_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('list', async () => { - const responsePromise = openai.batches.list(); + const responsePromise = client.batches.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -64,7 +64,7 @@ describe('resource batches', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.batches.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.batches.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -72,12 +72,12 @@ describe('resource batches', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.batches.list({ after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }), + client.batches.list({ after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('cancel', async () => { - const responsePromise = openai.batches.cancel('batch_id'); + const responsePromise = client.batches.cancel('batch_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -89,7 +89,7 @@ describe('resource batches', () => { test('cancel: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.batches.cancel('batch_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.batches.cancel('batch_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); diff --git a/tests/api-resources/beta/assistants.test.ts b/tests/api-resources/beta/assistants.test.ts index 44ee2921d..657cd76a6 100644 --- a/tests/api-resources/beta/assistants.test.ts +++ b/tests/api-resources/beta/assistants.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource assistants', () => { test('create: only required params', async () => { - const responsePromise = openai.beta.assistants.create({ model: 'gpt-4-turbo' }); + const responsePromise = client.beta.assistants.create({ model: 'gpt-4-turbo' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,7 +21,7 @@ describe('resource assistants', () => { }); test('create: required and optional params', async () => { - const response = await openai.beta.assistants.create({ + const response = await client.beta.assistants.create({ model: 'gpt-4-turbo', description: 'description', instructions: 'instructions', @@ -44,7 +44,7 @@ describe('resource assistants', () => { }); test('retrieve', async () => { - const responsePromise = openai.beta.assistants.retrieve('assistant_id'); + const responsePromise = client.beta.assistants.retrieve('assistant_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -57,12 +57,12 @@ describe('resource assistants', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.assistants.retrieve('assistant_id', { path: '/_stainless_unknown_path' }), + client.beta.assistants.retrieve('assistant_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('update', async () => { - const responsePromise = openai.beta.assistants.update('assistant_id', {}); + const responsePromise = client.beta.assistants.update('assistant_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -73,7 +73,7 @@ describe('resource assistants', () => { }); test('list', async () => { - const responsePromise = openai.beta.assistants.list(); + const responsePromise = client.beta.assistants.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -85,7 +85,7 @@ describe('resource assistants', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.beta.assistants.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.beta.assistants.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -93,7 +93,7 @@ describe('resource assistants', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.assistants.list( + client.beta.assistants.list( { after: 'after', before: 'before', limit: 0, order: 'asc' }, { path: '/_stainless_unknown_path' }, ), @@ -101,7 +101,7 @@ describe('resource assistants', () => { }); test('del', async () => { - const responsePromise = openai.beta.assistants.del('assistant_id'); + const responsePromise = client.beta.assistants.del('assistant_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -114,7 +114,7 @@ describe('resource assistants', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.assistants.del('assistant_id', { path: '/_stainless_unknown_path' }), + client.beta.assistants.del('assistant_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/beta/threads/messages.test.ts b/tests/api-resources/beta/threads/messages.test.ts index 0f2877af1..bfbcab1cb 100644 --- a/tests/api-resources/beta/threads/messages.test.ts +++ b/tests/api-resources/beta/threads/messages.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource messages', () => { test('create: only required params', async () => { - const responsePromise = openai.beta.threads.messages.create('thread_id', { + const responsePromise = client.beta.threads.messages.create('thread_id', { content: 'string', role: 'user', }); @@ -24,7 +24,7 @@ describe('resource messages', () => { }); test('create: required and optional params', async () => { - const response = await openai.beta.threads.messages.create('thread_id', { + const response = await client.beta.threads.messages.create('thread_id', { content: 'string', role: 'user', attachments: [ @@ -46,7 +46,7 @@ describe('resource messages', () => { }); test('retrieve', async () => { - const responsePromise = openai.beta.threads.messages.retrieve('thread_id', 'message_id'); + const responsePromise = client.beta.threads.messages.retrieve('thread_id', 'message_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -59,12 +59,12 @@ describe('resource messages', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.messages.retrieve('thread_id', 'message_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.messages.retrieve('thread_id', 'message_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('update', async () => { - const responsePromise = openai.beta.threads.messages.update('thread_id', 'message_id', {}); + const responsePromise = client.beta.threads.messages.update('thread_id', 'message_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -75,7 +75,7 @@ describe('resource messages', () => { }); test('list', async () => { - const responsePromise = openai.beta.threads.messages.list('thread_id'); + const responsePromise = client.beta.threads.messages.list('thread_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -88,14 +88,14 @@ describe('resource messages', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.messages.list('thread_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.messages.list('thread_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.messages.list( + client.beta.threads.messages.list( 'thread_id', { after: 'after', before: 'before', limit: 0, order: 'asc', run_id: 'run_id' }, { path: '/_stainless_unknown_path' }, @@ -104,7 +104,7 @@ describe('resource messages', () => { }); test('del', async () => { - const responsePromise = openai.beta.threads.messages.del('thread_id', 'message_id'); + const responsePromise = client.beta.threads.messages.del('thread_id', 'message_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -117,7 +117,7 @@ describe('resource messages', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.messages.del('thread_id', 'message_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.messages.del('thread_id', 'message_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/beta/threads/runs/runs.test.ts b/tests/api-resources/beta/threads/runs/runs.test.ts index b422a9a3f..856eb8662 100644 --- a/tests/api-resources/beta/threads/runs/runs.test.ts +++ b/tests/api-resources/beta/threads/runs/runs.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource runs', () => { test('create: only required params', async () => { - const responsePromise = openai.beta.threads.runs.create('thread_id', { assistant_id: 'assistant_id' }); + const responsePromise = client.beta.threads.runs.create('thread_id', { assistant_id: 'assistant_id' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,7 +21,7 @@ describe('resource runs', () => { }); test('create: required and optional params', async () => { - const response = await openai.beta.threads.runs.create('thread_id', { + const response = await client.beta.threads.runs.create('thread_id', { assistant_id: 'assistant_id', additional_instructions: 'additional_instructions', additional_messages: [ @@ -136,7 +136,7 @@ describe('resource runs', () => { }); test('retrieve', async () => { - const responsePromise = openai.beta.threads.runs.retrieve('thread_id', 'run_id'); + const responsePromise = client.beta.threads.runs.retrieve('thread_id', 'run_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -149,12 +149,12 @@ describe('resource runs', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.retrieve('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.runs.retrieve('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('update', async () => { - const responsePromise = openai.beta.threads.runs.update('thread_id', 'run_id', {}); + const responsePromise = client.beta.threads.runs.update('thread_id', 'run_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -165,7 +165,7 @@ describe('resource runs', () => { }); test('list', async () => { - const responsePromise = openai.beta.threads.runs.list('thread_id'); + const responsePromise = client.beta.threads.runs.list('thread_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -178,14 +178,14 @@ describe('resource runs', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.list('thread_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.runs.list('thread_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.list( + client.beta.threads.runs.list( 'thread_id', { after: 'after', before: 'before', limit: 0, order: 'asc' }, { path: '/_stainless_unknown_path' }, @@ -194,7 +194,7 @@ describe('resource runs', () => { }); test('cancel', async () => { - const responsePromise = openai.beta.threads.runs.cancel('thread_id', 'run_id'); + const responsePromise = client.beta.threads.runs.cancel('thread_id', 'run_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -207,12 +207,12 @@ describe('resource runs', () => { test('cancel: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.cancel('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.runs.cancel('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('submitToolOutputs: only required params', async () => { - const responsePromise = openai.beta.threads.runs.submitToolOutputs('thread_id', 'run_id', { + const responsePromise = client.beta.threads.runs.submitToolOutputs('thread_id', 'run_id', { tool_outputs: [{}, {}, {}], }); const rawResponse = await responsePromise.asResponse(); @@ -225,7 +225,7 @@ describe('resource runs', () => { }); test('submitToolOutputs: required and optional params', async () => { - const response = await openai.beta.threads.runs.submitToolOutputs('thread_id', 'run_id', { + const response = await client.beta.threads.runs.submitToolOutputs('thread_id', 'run_id', { tool_outputs: [ { tool_call_id: 'tool_call_id', output: 'output' }, { tool_call_id: 'tool_call_id', output: 'output' }, diff --git a/tests/api-resources/beta/threads/runs/steps.test.ts b/tests/api-resources/beta/threads/runs/steps.test.ts index 1981d67fd..21487c17b 100644 --- a/tests/api-resources/beta/threads/runs/steps.test.ts +++ b/tests/api-resources/beta/threads/runs/steps.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource steps', () => { test('retrieve', async () => { - const responsePromise = openai.beta.threads.runs.steps.retrieve('thread_id', 'run_id', 'step_id'); + const responsePromise = client.beta.threads.runs.steps.retrieve('thread_id', 'run_id', 'step_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,14 +23,14 @@ describe('resource steps', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.steps.retrieve('thread_id', 'run_id', 'step_id', { + client.beta.threads.runs.steps.retrieve('thread_id', 'run_id', 'step_id', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list', async () => { - const responsePromise = openai.beta.threads.runs.steps.list('thread_id', 'run_id'); + const responsePromise = client.beta.threads.runs.steps.list('thread_id', 'run_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -43,14 +43,14 @@ describe('resource steps', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.steps.list('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.runs.steps.list('thread_id', 'run_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.runs.steps.list( + client.beta.threads.runs.steps.list( 'thread_id', 'run_id', { after: 'after', before: 'before', limit: 0, order: 'asc' }, diff --git a/tests/api-resources/beta/threads/threads.test.ts b/tests/api-resources/beta/threads/threads.test.ts index 0d2d93a61..2a5ebfd82 100644 --- a/tests/api-resources/beta/threads/threads.test.ts +++ b/tests/api-resources/beta/threads/threads.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource threads', () => { test('create', async () => { - const responsePromise = openai.beta.threads.create(); + const responsePromise = client.beta.threads.create(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,7 +22,7 @@ describe('resource threads', () => { test('create: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.beta.threads.create({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.beta.threads.create({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -30,7 +30,7 @@ describe('resource threads', () => { test('create: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.create( + client.beta.threads.create( { messages: [ { @@ -148,7 +148,7 @@ describe('resource threads', () => { }); test('retrieve', async () => { - const responsePromise = openai.beta.threads.retrieve('thread_id'); + const responsePromise = client.beta.threads.retrieve('thread_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -161,12 +161,12 @@ describe('resource threads', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.threads.retrieve('thread_id', { path: '/_stainless_unknown_path' }), + client.beta.threads.retrieve('thread_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('update', async () => { - const responsePromise = openai.beta.threads.update('thread_id', {}); + const responsePromise = client.beta.threads.update('thread_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -177,7 +177,7 @@ describe('resource threads', () => { }); test('del', async () => { - const responsePromise = openai.beta.threads.del('thread_id'); + const responsePromise = client.beta.threads.del('thread_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -189,13 +189,13 @@ describe('resource threads', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.beta.threads.del('thread_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.beta.threads.del('thread_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('createAndRun: only required params', async () => { - const responsePromise = openai.beta.threads.createAndRun({ assistant_id: 'assistant_id' }); + const responsePromise = client.beta.threads.createAndRun({ assistant_id: 'assistant_id' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -206,7 +206,7 @@ describe('resource threads', () => { }); test('createAndRun: required and optional params', async () => { - const response = await openai.beta.threads.createAndRun({ + const response = await client.beta.threads.createAndRun({ assistant_id: 'assistant_id', instructions: 'instructions', max_completion_tokens: 256, diff --git a/tests/api-resources/beta/vector-stores/file-batches.test.ts b/tests/api-resources/beta/vector-stores/file-batches.test.ts index 33bfd2ef7..b714049b4 100644 --- a/tests/api-resources/beta/vector-stores/file-batches.test.ts +++ b/tests/api-resources/beta/vector-stores/file-batches.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource fileBatches', () => { test('create: only required params', async () => { - const responsePromise = openai.beta.vectorStores.fileBatches.create('vs_abc123', { + const responsePromise = client.beta.vectorStores.fileBatches.create('vs_abc123', { file_ids: ['string'], }); const rawResponse = await responsePromise.asResponse(); @@ -23,14 +23,14 @@ describe('resource fileBatches', () => { }); test('create: required and optional params', async () => { - const response = await openai.beta.vectorStores.fileBatches.create('vs_abc123', { + const response = await client.beta.vectorStores.fileBatches.create('vs_abc123', { file_ids: ['string'], chunking_strategy: { type: 'auto' }, }); }); test('retrieve', async () => { - const responsePromise = openai.beta.vectorStores.fileBatches.retrieve('vs_abc123', 'vsfb_abc123'); + const responsePromise = client.beta.vectorStores.fileBatches.retrieve('vs_abc123', 'vsfb_abc123'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -43,14 +43,14 @@ describe('resource fileBatches', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.fileBatches.retrieve('vs_abc123', 'vsfb_abc123', { + client.beta.vectorStores.fileBatches.retrieve('vs_abc123', 'vsfb_abc123', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('cancel', async () => { - const responsePromise = openai.beta.vectorStores.fileBatches.cancel('vector_store_id', 'batch_id'); + const responsePromise = client.beta.vectorStores.fileBatches.cancel('vector_store_id', 'batch_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -63,14 +63,14 @@ describe('resource fileBatches', () => { test('cancel: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.fileBatches.cancel('vector_store_id', 'batch_id', { + client.beta.vectorStores.fileBatches.cancel('vector_store_id', 'batch_id', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('listFiles', async () => { - const responsePromise = openai.beta.vectorStores.fileBatches.listFiles('vector_store_id', 'batch_id'); + const responsePromise = client.beta.vectorStores.fileBatches.listFiles('vector_store_id', 'batch_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -83,7 +83,7 @@ describe('resource fileBatches', () => { test('listFiles: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.fileBatches.listFiles('vector_store_id', 'batch_id', { + client.beta.vectorStores.fileBatches.listFiles('vector_store_id', 'batch_id', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); @@ -92,7 +92,7 @@ describe('resource fileBatches', () => { test('listFiles: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.fileBatches.listFiles( + client.beta.vectorStores.fileBatches.listFiles( 'vector_store_id', 'batch_id', { after: 'after', before: 'before', filter: 'in_progress', limit: 0, order: 'asc' }, diff --git a/tests/api-resources/beta/vector-stores/files.test.ts b/tests/api-resources/beta/vector-stores/files.test.ts index 4b21aed30..7c14d4de3 100644 --- a/tests/api-resources/beta/vector-stores/files.test.ts +++ b/tests/api-resources/beta/vector-stores/files.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource files', () => { test('create: only required params', async () => { - const responsePromise = openai.beta.vectorStores.files.create('vs_abc123', { file_id: 'file_id' }); + const responsePromise = client.beta.vectorStores.files.create('vs_abc123', { file_id: 'file_id' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,14 +21,14 @@ describe('resource files', () => { }); test('create: required and optional params', async () => { - const response = await openai.beta.vectorStores.files.create('vs_abc123', { + const response = await client.beta.vectorStores.files.create('vs_abc123', { file_id: 'file_id', chunking_strategy: { type: 'auto' }, }); }); test('retrieve', async () => { - const responsePromise = openai.beta.vectorStores.files.retrieve('vs_abc123', 'file-abc123'); + const responsePromise = client.beta.vectorStores.files.retrieve('vs_abc123', 'file-abc123'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -41,14 +41,14 @@ describe('resource files', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.files.retrieve('vs_abc123', 'file-abc123', { + client.beta.vectorStores.files.retrieve('vs_abc123', 'file-abc123', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list', async () => { - const responsePromise = openai.beta.vectorStores.files.list('vector_store_id'); + const responsePromise = client.beta.vectorStores.files.list('vector_store_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -61,14 +61,14 @@ describe('resource files', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.files.list('vector_store_id', { path: '/_stainless_unknown_path' }), + client.beta.vectorStores.files.list('vector_store_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.files.list( + client.beta.vectorStores.files.list( 'vector_store_id', { after: 'after', before: 'before', filter: 'in_progress', limit: 0, order: 'asc' }, { path: '/_stainless_unknown_path' }, @@ -77,7 +77,7 @@ describe('resource files', () => { }); test('del', async () => { - const responsePromise = openai.beta.vectorStores.files.del('vector_store_id', 'file_id'); + const responsePromise = client.beta.vectorStores.files.del('vector_store_id', 'file_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -90,7 +90,7 @@ describe('resource files', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.files.del('vector_store_id', 'file_id', { path: '/_stainless_unknown_path' }), + client.beta.vectorStores.files.del('vector_store_id', 'file_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/beta/vector-stores/vector-stores.test.ts b/tests/api-resources/beta/vector-stores/vector-stores.test.ts index 11dcceef8..806098de8 100644 --- a/tests/api-resources/beta/vector-stores/vector-stores.test.ts +++ b/tests/api-resources/beta/vector-stores/vector-stores.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource vectorStores', () => { test('create', async () => { - const responsePromise = openai.beta.vectorStores.create({}); + const responsePromise = client.beta.vectorStores.create({}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,7 +21,7 @@ describe('resource vectorStores', () => { }); test('retrieve', async () => { - const responsePromise = openai.beta.vectorStores.retrieve('vector_store_id'); + const responsePromise = client.beta.vectorStores.retrieve('vector_store_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -34,12 +34,12 @@ describe('resource vectorStores', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.retrieve('vector_store_id', { path: '/_stainless_unknown_path' }), + client.beta.vectorStores.retrieve('vector_store_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('update', async () => { - const responsePromise = openai.beta.vectorStores.update('vector_store_id', {}); + const responsePromise = client.beta.vectorStores.update('vector_store_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -50,7 +50,7 @@ describe('resource vectorStores', () => { }); test('list', async () => { - const responsePromise = openai.beta.vectorStores.list(); + const responsePromise = client.beta.vectorStores.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -62,7 +62,7 @@ describe('resource vectorStores', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.beta.vectorStores.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.beta.vectorStores.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -70,7 +70,7 @@ describe('resource vectorStores', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.list( + client.beta.vectorStores.list( { after: 'after', before: 'before', limit: 0, order: 'asc' }, { path: '/_stainless_unknown_path' }, ), @@ -78,7 +78,7 @@ describe('resource vectorStores', () => { }); test('del', async () => { - const responsePromise = openai.beta.vectorStores.del('vector_store_id'); + const responsePromise = client.beta.vectorStores.del('vector_store_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -91,7 +91,7 @@ describe('resource vectorStores', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.beta.vectorStores.del('vector_store_id', { path: '/_stainless_unknown_path' }), + client.beta.vectorStores.del('vector_store_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/chat/completions.test.ts b/tests/api-resources/chat/completions.test.ts index 66ef2d023..78314074f 100644 --- a/tests/api-resources/chat/completions.test.ts +++ b/tests/api-resources/chat/completions.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource completions', () => { test('create: only required params', async () => { - const responsePromise = openai.chat.completions.create({ + const responsePromise = client.chat.completions.create({ messages: [{ content: 'content', role: 'system' }], model: 'gpt-4-turbo', }); @@ -24,7 +24,7 @@ describe('resource completions', () => { }); test('create: required and optional params', async () => { - const response = await openai.chat.completions.create({ + const response = await client.chat.completions.create({ messages: [{ content: 'content', role: 'system', name: 'name' }], model: 'gpt-4-turbo', frequency_penalty: -2, diff --git a/tests/api-resources/completions.test.ts b/tests/api-resources/completions.test.ts index f78f7a593..82322dc3a 100644 --- a/tests/api-resources/completions.test.ts +++ b/tests/api-resources/completions.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource completions', () => { test('create: only required params', async () => { - const responsePromise = openai.completions.create({ model: 'string', prompt: 'This is a test.' }); + const responsePromise = client.completions.create({ model: 'string', prompt: 'This is a test.' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,7 +21,7 @@ describe('resource completions', () => { }); test('create: required and optional params', async () => { - const response = await openai.completions.create({ + const response = await client.completions.create({ model: 'string', prompt: 'This is a test.', best_of: 0, diff --git a/tests/api-resources/embeddings.test.ts b/tests/api-resources/embeddings.test.ts index d4e1f3240..46dd1b2a3 100644 --- a/tests/api-resources/embeddings.test.ts +++ b/tests/api-resources/embeddings.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource embeddings', () => { test('create: only required params', async () => { - const responsePromise = openai.embeddings.create({ + const responsePromise = client.embeddings.create({ input: 'The quick brown fox jumped over the lazy dog', model: 'text-embedding-3-small', }); @@ -24,7 +24,7 @@ describe('resource embeddings', () => { }); test('create: required and optional params', async () => { - const response = await openai.embeddings.create({ + const response = await client.embeddings.create({ input: 'The quick brown fox jumped over the lazy dog', model: 'text-embedding-3-small', dimensions: 1, diff --git a/tests/api-resources/files.test.ts b/tests/api-resources/files.test.ts index 55eded995..bbaa45a65 100644 --- a/tests/api-resources/files.test.ts +++ b/tests/api-resources/files.test.ts @@ -3,14 +3,14 @@ import OpenAI, { toFile } from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource files', () => { test('create: only required params', async () => { - const responsePromise = openai.files.create({ + const responsePromise = client.files.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), purpose: 'assistants', }); @@ -24,14 +24,14 @@ describe('resource files', () => { }); test('create: required and optional params', async () => { - const response = await openai.files.create({ + const response = await client.files.create({ file: await toFile(Buffer.from('# my file contents'), 'README.md'), purpose: 'assistants', }); }); test('retrieve', async () => { - const responsePromise = openai.files.retrieve('file_id'); + const responsePromise = client.files.retrieve('file_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -43,13 +43,13 @@ describe('resource files', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.files.retrieve('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.files.retrieve('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('list', async () => { - const responsePromise = openai.files.list(); + const responsePromise = client.files.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -61,7 +61,7 @@ describe('resource files', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.files.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.files.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -69,12 +69,12 @@ describe('resource files', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.files.list({ purpose: 'purpose' }, { path: '/_stainless_unknown_path' }), + client.files.list({ purpose: 'purpose' }, { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('del', async () => { - const responsePromise = openai.files.del('file_id'); + const responsePromise = client.files.del('file_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -86,20 +86,20 @@ describe('resource files', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.files.del('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.files.del('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('content: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.files.content('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.files.content('file_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('retrieveContent', async () => { - const responsePromise = openai.files.retrieveContent('file_id'); + const responsePromise = client.files.retrieveContent('file_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -112,7 +112,7 @@ describe('resource files', () => { test('retrieveContent: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.files.retrieveContent('file_id', { path: '/_stainless_unknown_path' }), + client.files.retrieveContent('file_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/fine-tuning/jobs/checkpoints.test.ts b/tests/api-resources/fine-tuning/jobs/checkpoints.test.ts index 3a01448e2..d211a9b10 100644 --- a/tests/api-resources/fine-tuning/jobs/checkpoints.test.ts +++ b/tests/api-resources/fine-tuning/jobs/checkpoints.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource checkpoints', () => { test('list', async () => { - const responsePromise = openai.fineTuning.jobs.checkpoints.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); + const responsePromise = client.fineTuning.jobs.checkpoints.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,7 +23,7 @@ describe('resource checkpoints', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.checkpoints.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { + client.fineTuning.jobs.checkpoints.list('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path', }), ).rejects.toThrow(OpenAI.NotFoundError); @@ -32,7 +32,7 @@ describe('resource checkpoints', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.checkpoints.list( + client.fineTuning.jobs.checkpoints.list( 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', { after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/fine-tuning/jobs/jobs.test.ts b/tests/api-resources/fine-tuning/jobs/jobs.test.ts index c14912c3a..04de7ee21 100644 --- a/tests/api-resources/fine-tuning/jobs/jobs.test.ts +++ b/tests/api-resources/fine-tuning/jobs/jobs.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource jobs', () => { test('create: only required params', async () => { - const responsePromise = openai.fineTuning.jobs.create({ + const responsePromise = client.fineTuning.jobs.create({ model: 'gpt-3.5-turbo', training_file: 'file-abc123', }); @@ -24,7 +24,7 @@ describe('resource jobs', () => { }); test('create: required and optional params', async () => { - const response = await openai.fineTuning.jobs.create({ + const response = await client.fineTuning.jobs.create({ model: 'gpt-3.5-turbo', training_file: 'file-abc123', hyperparameters: { batch_size: 'auto', learning_rate_multiplier: 'auto', n_epochs: 'auto' }, @@ -64,7 +64,7 @@ describe('resource jobs', () => { }); test('retrieve', async () => { - const responsePromise = openai.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); + const responsePromise = client.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -77,12 +77,12 @@ describe('resource jobs', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), + client.fineTuning.jobs.retrieve('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list', async () => { - const responsePromise = openai.fineTuning.jobs.list(); + const responsePromise = client.fineTuning.jobs.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -94,7 +94,7 @@ describe('resource jobs', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.fineTuning.jobs.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.fineTuning.jobs.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); @@ -102,12 +102,12 @@ describe('resource jobs', () => { test('list: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.list({ after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }), + client.fineTuning.jobs.list({ after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('cancel', async () => { - const responsePromise = openai.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); + const responsePromise = client.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -120,12 +120,12 @@ describe('resource jobs', () => { test('cancel: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), + client.fineTuning.jobs.cancel('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('listEvents', async () => { - const responsePromise = openai.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); + const responsePromise = client.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -138,14 +138,14 @@ describe('resource jobs', () => { test('listEvents: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), + client.fineTuning.jobs.listEvents('ft-AF1WoRqd3aJAHsqc9NY7iL8F', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('listEvents: request options and params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.fineTuning.jobs.listEvents( + client.fineTuning.jobs.listEvents( 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', { after: 'after', limit: 0 }, { path: '/_stainless_unknown_path' }, diff --git a/tests/api-resources/images.test.ts b/tests/api-resources/images.test.ts index 33d633a63..43e67b030 100644 --- a/tests/api-resources/images.test.ts +++ b/tests/api-resources/images.test.ts @@ -3,14 +3,14 @@ import OpenAI, { toFile } from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource images', () => { test('createVariation: only required params', async () => { - const responsePromise = openai.images.createVariation({ + const responsePromise = client.images.createVariation({ image: await toFile(Buffer.from('# my file contents'), 'README.md'), }); const rawResponse = await responsePromise.asResponse(); @@ -23,7 +23,7 @@ describe('resource images', () => { }); test('createVariation: required and optional params', async () => { - const response = await openai.images.createVariation({ + const response = await client.images.createVariation({ image: await toFile(Buffer.from('# my file contents'), 'README.md'), model: 'dall-e-2', n: 1, @@ -34,7 +34,7 @@ describe('resource images', () => { }); test('edit: only required params', async () => { - const responsePromise = openai.images.edit({ + const responsePromise = client.images.edit({ image: await toFile(Buffer.from('# my file contents'), 'README.md'), prompt: 'A cute baby sea otter wearing a beret', }); @@ -48,7 +48,7 @@ describe('resource images', () => { }); test('edit: required and optional params', async () => { - const response = await openai.images.edit({ + const response = await client.images.edit({ image: await toFile(Buffer.from('# my file contents'), 'README.md'), prompt: 'A cute baby sea otter wearing a beret', mask: await toFile(Buffer.from('# my file contents'), 'README.md'), @@ -61,7 +61,7 @@ describe('resource images', () => { }); test('generate: only required params', async () => { - const responsePromise = openai.images.generate({ prompt: 'A cute baby sea otter' }); + const responsePromise = client.images.generate({ prompt: 'A cute baby sea otter' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -72,7 +72,7 @@ describe('resource images', () => { }); test('generate: required and optional params', async () => { - const response = await openai.images.generate({ + const response = await client.images.generate({ prompt: 'A cute baby sea otter', model: 'dall-e-3', n: 1, diff --git a/tests/api-resources/models.test.ts b/tests/api-resources/models.test.ts index ca1f98365..eee91d020 100644 --- a/tests/api-resources/models.test.ts +++ b/tests/api-resources/models.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource models', () => { test('retrieve', async () => { - const responsePromise = openai.models.retrieve('gpt-3.5-turbo'); + const responsePromise = client.models.retrieve('gpt-3.5-turbo'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,12 +23,12 @@ describe('resource models', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.models.retrieve('gpt-3.5-turbo', { path: '/_stainless_unknown_path' }), + client.models.retrieve('gpt-3.5-turbo', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('list', async () => { - const responsePromise = openai.models.list(); + const responsePromise = client.models.list(); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -40,13 +40,13 @@ describe('resource models', () => { test('list: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(openai.models.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect(client.models.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( OpenAI.NotFoundError, ); }); test('del', async () => { - const responsePromise = openai.models.del('ft:gpt-3.5-turbo:acemeco:suffix:abc123'); + const responsePromise = client.models.del('ft:gpt-3.5-turbo:acemeco:suffix:abc123'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -59,7 +59,7 @@ describe('resource models', () => { test('del: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.models.del('ft:gpt-3.5-turbo:acemeco:suffix:abc123', { path: '/_stainless_unknown_path' }), + client.models.del('ft:gpt-3.5-turbo:acemeco:suffix:abc123', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); }); diff --git a/tests/api-resources/moderations.test.ts b/tests/api-resources/moderations.test.ts index ef7298fa9..0df1f0371 100644 --- a/tests/api-resources/moderations.test.ts +++ b/tests/api-resources/moderations.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource moderations', () => { test('create: only required params', async () => { - const responsePromise = openai.moderations.create({ input: 'I want to kill them.' }); + const responsePromise = client.moderations.create({ input: 'I want to kill them.' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,7 +21,7 @@ describe('resource moderations', () => { }); test('create: required and optional params', async () => { - const response = await openai.moderations.create({ + const response = await client.moderations.create({ input: 'I want to kill them.', model: 'text-moderation-stable', }); diff --git a/tests/api-resources/uploads/parts.test.ts b/tests/api-resources/uploads/parts.test.ts index 5e69c5861..e584bab8e 100644 --- a/tests/api-resources/uploads/parts.test.ts +++ b/tests/api-resources/uploads/parts.test.ts @@ -3,14 +3,14 @@ import OpenAI, { toFile } from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource parts', () => { test('create: only required params', async () => { - const responsePromise = openai.uploads.parts.create('upload_abc123', { + const responsePromise = client.uploads.parts.create('upload_abc123', { data: await toFile(Buffer.from('# my file contents'), 'README.md'), }); const rawResponse = await responsePromise.asResponse(); @@ -23,7 +23,7 @@ describe('resource parts', () => { }); test('create: required and optional params', async () => { - const response = await openai.uploads.parts.create('upload_abc123', { + const response = await client.uploads.parts.create('upload_abc123', { data: await toFile(Buffer.from('# my file contents'), 'README.md'), }); }); diff --git a/tests/api-resources/uploads/uploads.test.ts b/tests/api-resources/uploads/uploads.test.ts index 08f059d1b..e4e3c6d30 100644 --- a/tests/api-resources/uploads/uploads.test.ts +++ b/tests/api-resources/uploads/uploads.test.ts @@ -3,14 +3,14 @@ import OpenAI from 'openai'; import { Response } from 'node-fetch'; -const openai = new OpenAI({ +const client = new OpenAI({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource uploads', () => { test('create: only required params', async () => { - const responsePromise = openai.uploads.create({ + const responsePromise = client.uploads.create({ bytes: 0, filename: 'filename', mime_type: 'mime_type', @@ -26,7 +26,7 @@ describe('resource uploads', () => { }); test('create: required and optional params', async () => { - const response = await openai.uploads.create({ + const response = await client.uploads.create({ bytes: 0, filename: 'filename', mime_type: 'mime_type', @@ -35,7 +35,7 @@ describe('resource uploads', () => { }); test('cancel', async () => { - const responsePromise = openai.uploads.cancel('upload_abc123'); + const responsePromise = client.uploads.cancel('upload_abc123'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -48,12 +48,12 @@ describe('resource uploads', () => { test('cancel: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - openai.uploads.cancel('upload_abc123', { path: '/_stainless_unknown_path' }), + client.uploads.cancel('upload_abc123', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(OpenAI.NotFoundError); }); test('complete: only required params', async () => { - const responsePromise = openai.uploads.complete('upload_abc123', { + const responsePromise = client.uploads.complete('upload_abc123', { part_ids: ['string', 'string', 'string'], }); const rawResponse = await responsePromise.asResponse(); @@ -66,7 +66,7 @@ describe('resource uploads', () => { }); test('complete: required and optional params', async () => { - const response = await openai.uploads.complete('upload_abc123', { + const response = await client.uploads.complete('upload_abc123', { part_ids: ['string', 'string', 'string'], md5: 'md5', });