Skip to content

Commit

Permalink
fix(api): accidentally required params, add new models & other fixes (#…
Browse files Browse the repository at this point in the history
…463)

- Mark chat completion image url as required
- Add system_fingerprint to chat completions
  • Loading branch information
stainless-bot committed Nov 8, 2023
1 parent 19402c3 commit 1cb403e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/resources/beta/threads/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import { isRequestOptions } from 'openai/core';
import * as ThreadsAPI from 'openai/resources/beta/threads/threads';
import * as MessagesAPI from 'openai/resources/beta/threads/messages/messages';
import * as RunsAPI from 'openai/resources/beta/threads/runs/runs';
Expand All @@ -13,7 +14,15 @@ export class Threads extends APIResource {
/**
* Create a thread.
*/
create(body: ThreadCreateParams, options?: Core.RequestOptions): Core.APIPromise<Thread> {
create(body?: ThreadCreateParams, options?: Core.RequestOptions): Core.APIPromise<Thread>;
create(options?: Core.RequestOptions): Core.APIPromise<Thread>;
create(
body: ThreadCreateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<Thread> {
if (isRequestOptions(body)) {
return this.create({}, body);
}
return this.post('/threads', {
body,
...options,
Expand Down
18 changes: 14 additions & 4 deletions src/resources/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ export interface ChatCompletionChunk {
* The object type, which is always `chat.completion.chunk`.
*/
object: 'chat.completion.chunk';

/**
* This fingerprint represents the backend configuration that the model runs with.
*
* Can be used in conjunction with the `seed` request parameter to understand when
* backend changes have been made that might impact determinism.
*/
system_fingerprint?: string;
}

export namespace ChatCompletionChunk {
Expand Down Expand Up @@ -296,14 +304,14 @@ export interface ChatCompletionContentPartImage {
export namespace ChatCompletionContentPartImage {
export interface ImageURL {
/**
* Specifies the detail level of the image.
* Either a URL of the image or the base64 encoded image data.
*/
detail?: 'auto' | 'low' | 'high';
url: string;

/**
* Either a URL of the image or the base64 encoded image data.
* Specifies the detail level of the image.
*/
url?: string;
detail?: 'auto' | 'low' | 'high';
}
}

Expand Down Expand Up @@ -579,6 +587,8 @@ export interface ChatCompletionCreateParamsBase {
*/
model:
| (string & {})
| 'gpt-4-1106-preview'
| 'gpt-4-vision-preview'
| 'gpt-4'
| 'gpt-4-0314'
| 'gpt-4-0613'
Expand Down
26 changes: 25 additions & 1 deletion tests/api-resources/beta/threads/threads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const openai = new OpenAI({

describe('resource threads', () => {
test('create', async () => {
const responsePromise = openai.beta.threads.create({});
const responsePromise = openai.beta.threads.create();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -20,6 +20,30 @@ describe('resource threads', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

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(
OpenAI.NotFoundError,
);
});

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(
{
messages: [
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
{ role: 'user', content: 'x', file_ids: ['string'], metadata: {} },
],
metadata: {},
},
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(OpenAI.NotFoundError);
});

test('retrieve', async () => {
const responsePromise = openai.beta.threads.retrieve('string');
const rawResponse = await responsePromise.asResponse();
Expand Down

0 comments on commit 1cb403e

Please sign in to comment.