Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TypeSpec with latest features including Assistants #6

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# OpenAPI spec for the OpenAI API
# A conversion of the OpenAI OpenAPI to TypeSpec

This repository contains an [OpenAPI](https://www.openapis.org/) specification for the [OpenAI API](https://platform.openai.com/docs/api-reference).
Snapshot: https://raw.githubusercontent.com/openai/openai-openapi/b648b7823135e6fa5148ac9a303c16fdad050da6/openapi.yaml

There are some deltas:

### Changes to API Semantics

- Many things are missing defaults (mostly due to bug where we can't set null defaults)
- Error responses have been added.
- Where known, the `object` property's type is narrowed from string to the constant value it will always be

### Changes to API metadata or OpenAPI format

- Much of the x-oaiMeta entries have not been added.
- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type)
- There is presently no way to set `title`
1 change: 1 addition & 0 deletions assistants/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./operations.tsp";
42 changes: 42 additions & 0 deletions assistants/meta.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import "./models.tsp";

import "@typespec/openapi";

using TypeSpec.OpenAPI;

namespace OpenAI;

// TODO: Fill in example here.
@@extension(OpenAI.ListAssistantsResponse,
"x-oaiMeta",
"""
name: List assistants response object
group: chat
example: *list_assistants_example
"""
);

// TODO: Fill in example here.
@@extension(OpenAI.AssistantObject,
"x-oaiMeta",
"""
name: The assistant object
beta: true
example: *create_assistants_example
"""
);

@@extension(OpenAI.AssistantFileObject,
"x-oaiMeta",
"""
name: The assistant file object
beta: true
example: |
{
"id": "file-abc123",
"object": "assistant.file",
"created_at": 1699055364,
"assistant_id": "asst_abc123"
}
"""
);
231 changes: 231 additions & 0 deletions assistants/models.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import "../common/models.tsp";

using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace OpenAI;

model CreateAssistantRequest {
/**
* ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to
* see all of your available models, or see our [Model overview](/docs/models/overview) for
* descriptions of them.
*/
`model`: string;

/** The name of the assistant. The maximum length is 256 characters. */
@maxLength(256)
name?: string | null;

/** The description of the assistant. The maximum length is 512 characters. */
@maxLength(512)
description?: string | null;

/** The system instructions that the assistant uses. The maximum length is 32768 characters. */
@maxLength(32768)
instructions?: string | null;

/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant.
* Tools can be of types `code_interpreter`, `retrieval`, or `function`.
*/

tools?: CreateAssistantRequestTools = [];

/**
* A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a
* maximum of 20 files attached to the assistant. Files are ordered by their creation date in
* ascending order.
*/
@maxItems(20)
file_ids?: string[] = [];

/**
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
* additional information about the object in a structured format. Keys can be a maximum of 64
* characters long and values can be a maxium of 512 characters long.
*/
@extension("x-oaiTypeLabel", "map")
metadata?: Record<string> | null;
}

model ModifyAssistantRequest {
/**
* ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to
* see all of your available models, or see our [Model overview](/docs/models/overview) for
* descriptions of them.
*/
`model`?: string;

/** The name of the assistant. The maximum length is 256 characters. */
@maxLength(256)
name?: string | null;

/** The description of the assistant. The maximum length is 512 characters. */
@maxLength(512)
description?: string | null;

/** The system instructions that the assistant uses. The maximum length is 32768 characters. */
@maxLength(32768)
instructions?: string | null;

/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant.
* Tools can be of types `code_interpreter`, `retrieval`, or `function`.
*/
tools?: CreateAssistantRequestTools = [];

/**
* A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a
* maximum of 20 files attached to the assistant. Files are ordered by their creation date in
* ascending order.
*/
@maxItems(20)
file_ids?: string[] = [];

/**
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
* additional information about the object in a structured format. Keys can be a maximum of 64
* characters long and values can be a maxium of 512 characters long.
*/
@extension("x-oaiTypeLabel", "map")
metadata?: Record<string> | null;
}

model CreateAssistantFileRequest {
/**
* A [File](/docs/api-reference/files) ID (with `purpose="assistants"`) that the assistant should
* use. Useful for tools like `retrieval` and `code_interpreter` that can access files.
*/
file_id: string;
}

model ListAssistantsResponse {
object: "list";
data: AssistantObject[];
first_id: string;
last_id: string;
has_more: boolean;
}

model DeleteAssistantResponse {
id: string;
deleted: boolean;
object: "assistant.deleted";
}

model ListAssistantFilesResponse {
object: "list";
data: AssistantFileObject[];
first_id: string;
last_id: string;
has_more: boolean;
}

/**
* Deletes the association between the assistant and the file, but does not delete the
* [File](/docs/api-reference/files) object itself.
*/
model DeleteAssistantFileResponse {
id: string;
deleted: boolean;
object: "assistant.file.deleted";
}

@maxItems(128)
model CreateAssistantRequestTools is CreateAssistantRequestTool[];

@oneOf
@extension("x-oaiExpandable", true)
union CreateAssistantRequestTool {
AssistantToolsCode,
AssistantToolsRetrieval,
AssistantToolsFunction
}

model AssistantToolsCode {
/** The type of tool being defined: `code_interpreter` */
type: "code_interpreter";
}

model AssistantToolsRetrieval {
/** The type of tool being defined: `retrieval` */
type: "retrieval";
}

model AssistantToolsFunction {
/** The type of tool being defined: `function` */
type: "function";

function: FunctionObject;
}

/** Represents an `assistant` that can call the model and use tools. */
model AssistantObject {
/** The identifier, which can be referenced in API endpoints. */
id: string;

/** The object type, which is always `assistant`. */
object: "assistant";

/** The Unix timestamp (in seconds) for when the assistant was created. */
@encode("unixTimestamp", int32)
created_at: utcDateTime;

/** The name of the assistant. The maximum length is 256 characters. */
@maxLength(256)
name: string | null;

/** The description of the assistant. The maximum length is 512 characters. */
@maxLength(512)
description: string | null;

/**
* ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to
* see all of your available models, or see our [Model overview](/docs/models/overview) for
* descriptions of them.
*/
`model`: string;

/** The system instructions that the assistant uses. The maximum length is 32768 characters. */
@maxLength(32768)
instructions: string | null;

/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant.
* Tools can be of types `code_interpreter`, `retrieval`, or `function`.
*/
tools: CreateAssistantRequestTools = [];

/**
* A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a
* maximum of 20 files attached to the assistant. Files are ordered by their creation date in
* ascending order.
*/
@maxItems(20)
file_ids: string[] = [];

/**
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
* additional information about the object in a structured format. Keys can be a maximum of 64
* characters long and values can be a maxium of 512 characters long.
*/
@extension("x-oaiTypeLabel", "map")
metadata: Record<string> | null;
}

/** A list of [Files](/docs/api-reference/files) attached to an `assistant`. */
model AssistantFileObject {
/** The identifier, which can be referenced in API endpoints. */
id: string;

/** The object type, which is always `assistant.file`. */
object: "assistant.file";

/** The Unix timestamp (in seconds) for when the assistant file was created. */
@encode("unixTimestamp", int32)
created_at: utcDateTime;

/** The assistant ID that the file is attached to. */
assistant_id: string;
}
Loading