From 413df77441c8da1a8971a41d342815a6e9223698 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Thu, 25 Jan 2024 20:15:21 +0100 Subject: [PATCH] feat(api): add text embeddings dimensions param (#650) --- src/resources/chat/completions.ts | 8 ++++++-- src/resources/embeddings.ts | 8 +++++++- tests/api-resources/embeddings.test.ts | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/resources/chat/completions.ts b/src/resources/chat/completions.ts index 6882e5f44..d3fddeacd 100644 --- a/src/resources/chat/completions.ts +++ b/src/resources/chat/completions.ts @@ -660,6 +660,8 @@ export interface ChatCompletionCreateParamsBase { */ model: | (string & {}) + | 'gpt-4-0125-preview' + | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' @@ -754,7 +756,8 @@ export interface ChatCompletionCreateParamsBase { /** * An object specifying the format that the model must output. Compatible with - * `gpt-4-1106-preview` and `gpt-3.5-turbo-1106`. + * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and + * `gpt-3.5-turbo-1106`. * * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the * message the model generates is valid JSON. @@ -874,7 +877,8 @@ export namespace ChatCompletionCreateParams { /** * An object specifying the format that the model must output. Compatible with - * `gpt-4-1106-preview` and `gpt-3.5-turbo-1106`. + * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo) and + * `gpt-3.5-turbo-1106`. * * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the * message the model generates is valid JSON. diff --git a/src/resources/embeddings.ts b/src/resources/embeddings.ts index 318a45275..3f59d2a7c 100644 --- a/src/resources/embeddings.ts +++ b/src/resources/embeddings.ts @@ -96,7 +96,13 @@ export interface EmbeddingCreateParams { * [Model overview](https://platform.openai.com/docs/models/overview) for * descriptions of them. */ - model: (string & {}) | 'text-embedding-ada-002'; + model: (string & {}) | 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large'; + + /** + * The number of dimensions the resulting output embeddings should have. Only + * supported in `text-embedding-3` and later models. + */ + dimensions?: number; /** * The format to return the embeddings in. Can be either `float` or diff --git a/tests/api-resources/embeddings.test.ts b/tests/api-resources/embeddings.test.ts index 24cb19482..bcb5ffbba 100644 --- a/tests/api-resources/embeddings.test.ts +++ b/tests/api-resources/embeddings.test.ts @@ -12,7 +12,7 @@ describe('resource embeddings', () => { test('create: only required params', async () => { const responsePromise = openai.embeddings.create({ input: 'The quick brown fox jumped over the lazy dog', - model: 'text-embedding-ada-002', + model: 'text-embedding-3-small', }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -26,7 +26,8 @@ describe('resource embeddings', () => { test('create: required and optional params', async () => { const response = await openai.embeddings.create({ input: 'The quick brown fox jumped over the lazy dog', - model: 'text-embedding-ada-002', + model: 'text-embedding-3-small', + dimensions: 1, encoding_format: 'float', user: 'user-1234', });