Skip to content

Commit

Permalink
feat(api): unify function types (#467)
Browse files Browse the repository at this point in the history
Also fixes an enum `assistant.run.step` -> `thread.run.step`
  • Loading branch information
stainless-bot committed Nov 8, 2023
1 parent 12a0de1 commit d51cd94
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 262 deletions.
7 changes: 7 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Shared

Types:

- <code><a href="./src/resources/shared.ts">FunctionObject</a></code>
- <code><a href="./src/resources/shared.ts">FunctionParameters</a></code>

# Completions

Types:
Expand Down
2 changes: 1 addition & 1 deletion build-deno
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is a build produced from https://github.com/openai/openai-node – please g
Usage:
\`\`\`ts
import OpenAI from "$(echo 'https://deno.land/x/[email protected].1/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)";
import OpenAI from "$(echo 'https://deno.land/x/[email protected].2/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)";
const client = new OpenAI();
\`\`\`
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ export namespace OpenAI {
export import FineTuneListEventsParamsStreaming = API.FineTuneListEventsParamsStreaming;

export import Beta = API.Beta;

export import FunctionObject = API.FunctionObject;
export import FunctionParameters = API.FunctionParameters;
}

export default OpenAI;
109 changes: 4 additions & 105 deletions src/resources/beta/assistants/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import { isRequestOptions } from 'openai/core';
import * as AssistantsAPI from 'openai/resources/beta/assistants/assistants';
import * as Shared from 'openai/resources/shared';
import * as FilesAPI from 'openai/resources/beta/assistants/files';
import { CursorPage, type CursorPageParams } from 'openai/pagination';

Expand Down Expand Up @@ -163,47 +164,13 @@ export namespace Assistant {
}

export interface Function {
/**
* The function definition.
*/
function: Function.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace Function {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export interface AssistantDeleted {
Expand Down Expand Up @@ -282,47 +249,13 @@ export namespace AssistantCreateParams {
}

export interface AssistantToolsFunction {
/**
* The function definition.
*/
function: AssistantToolsFunction.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace AssistantToolsFunction {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export interface AssistantUpdateParams {
Expand Down Expand Up @@ -395,47 +328,13 @@ export namespace AssistantUpdateParams {
}

export interface AssistantToolsFunction {
/**
* The function definition.
*/
function: AssistantToolsFunction.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace AssistantToolsFunction {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export interface AssistantListParams extends CursorPageParams {
Expand Down
77 changes: 5 additions & 72 deletions src/resources/beta/threads/runs/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import { isRequestOptions } from 'openai/core';
import * as RunsAPI from 'openai/resources/beta/threads/runs/runs';
import * as Shared from 'openai/resources/shared';
import * as StepsAPI from 'openai/resources/beta/threads/runs/steps';
import { CursorPage, type CursorPageParams } from 'openai/pagination';

Expand Down Expand Up @@ -221,9 +222,9 @@ export interface Run {
model: string;

/**
* The object type, which is always `assistant.run`.
* The object type, which is always `thread.run`.
*/
object: 'assistant.run';
object: 'thread.run';

/**
* Details on the action required to continue the run. Will be `null` if no action
Expand Down Expand Up @@ -324,47 +325,13 @@ export namespace Run {
}

export interface AssistantToolsFunction {
/**
* The function definition.
*/
function: AssistantToolsFunction.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace AssistantToolsFunction {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export interface RunCreateParams {
Expand Down Expand Up @@ -424,47 +391,13 @@ export namespace RunCreateParams {
}

export interface AssistantToolsFunction {
/**
* The function definition.
*/
function: AssistantToolsFunction.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace AssistantToolsFunction {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export interface RunUpdateParams {
Expand Down
8 changes: 4 additions & 4 deletions src/resources/beta/threads/runs/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ export interface RunStep {
metadata: unknown | null;

/**
* The object type, which is always `assistant.run.step``.
* The object type, which is always `thread.run.step``.
*/
object: 'assistant.run.step';
object: 'thread.run.step';

/**
* The ID of the [run](https://platform.openai.com/docs/api-reference/runs) that
Expand All @@ -280,8 +280,8 @@ export interface RunStep {
run_id: string;

/**
* The status of the run, which can be either `in_progress`, `cancelled`, `failed`,
* `completed`, or `expired`.
* The status of the run step, which can be either `in_progress`, `cancelled`,
* `failed`, `completed`, or `expired`.
*/
status: 'in_progress' | 'cancelled' | 'failed' | 'completed' | 'expired';

Expand Down
37 changes: 2 additions & 35 deletions src/resources/beta/threads/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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 Shared from 'openai/resources/shared';
import * as MessagesAPI from 'openai/resources/beta/threads/messages/messages';
import * as RunsAPI from 'openai/resources/beta/threads/runs/runs';

Expand Down Expand Up @@ -279,47 +280,13 @@ export namespace ThreadCreateAndRunParams {
}

export interface AssistantToolsFunction {
/**
* The function definition.
*/
function: AssistantToolsFunction.Function;
function: Shared.FunctionObject;

/**
* The type of tool being defined: `function`
*/
type: 'function';
}

export namespace AssistantToolsFunction {
/**
* The function definition.
*/
export interface Function {
/**
* A description of what the function does, used by the model to choose when and
* how to call the function.
*/
description: string;

/**
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
* underscores and dashes, with a maximum length of 64.
*/
name: string;

/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for
* examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
* documentation about the format.
*
* To describe a function that accepts no parameters, provide the value
* `{"type": "object", "properties": {}}`.
*/
parameters: Record<string, unknown>;
}
}
}

export namespace Threads {
Expand Down
Loading

0 comments on commit d51cd94

Please sign in to comment.