From 0dea4829ea79a3ffe1115af588c7d17ce61357f0 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Wed, 22 Feb 2023 17:33:45 +0000 Subject: [PATCH] ci: regenerated with OpenAPI Doc 1.1.0, Speakeay CLI 1.4.7 --- README.md | 103 ++ RELEASES.md | 7 + USAGE.md | 20 + files.gen | 70 + gen.yaml | 6 +- package-lock.json | 376 +++++ package.json | 24 + src/index.ts | 1 + src/internal/utils/contenttype.ts | 29 + src/internal/utils/headers.ts | 110 ++ src/internal/utils/index.ts | 8 + src/internal/utils/pathparams.ts | 70 + src/internal/utils/queryparams.ts | 98 ++ src/internal/utils/requestbody.ts | 302 +++++ src/internal/utils/retries.ts | 168 +++ src/internal/utils/security.ts | 220 +++ src/internal/utils/utils.ts | 254 ++++ src/sdk/index.ts | 1 + src/sdk/models/operations/cancelfinetune.ts | 23 + src/sdk/models/operations/createanswer.ts | 19 + .../models/operations/createclassification.ts | 19 + src/sdk/models/operations/createcompletion.ts | 19 + src/sdk/models/operations/createedit.ts | 19 + src/sdk/models/operations/createembedding.ts | 19 + src/sdk/models/operations/createfile.ts | 19 + src/sdk/models/operations/createfinetune.ts | 19 + src/sdk/models/operations/createimage.ts | 19 + src/sdk/models/operations/createimageedit.ts | 19 + .../models/operations/createimagevariation.ts | 19 + src/sdk/models/operations/createmoderation.ts | 19 + src/sdk/models/operations/createsearch.ts | 27 + src/sdk/models/operations/deletefile.ts | 24 + src/sdk/models/operations/deletemodel.ts | 24 + src/sdk/models/operations/downloadfile.ts | 23 + src/sdk/models/operations/index.ts | 25 + src/sdk/models/operations/listengines.ts | 14 + src/sdk/models/operations/listfiles.ts | 14 + .../models/operations/listfinetuneevents.ts | 32 + src/sdk/models/operations/listfinetunes.ts | 14 + src/sdk/models/operations/listmodels.ts | 14 + src/sdk/models/operations/retrieveengine.ts | 23 + src/sdk/models/operations/retrievefile.ts | 23 + src/sdk/models/operations/retrievefinetune.ts | 23 + src/sdk/models/operations/retrievemodel.ts | 23 + src/sdk/models/shared/createanswerrequest.ts | 58 + src/sdk/models/shared/createanswerresponse.ts | 30 + .../shared/createclassificationrequest.ts | 46 + .../shared/createclassificationresponse.ts | 33 + .../models/shared/createcompletionrequest.ts | 52 + .../models/shared/createcompletionresponse.ts | 61 + src/sdk/models/shared/createeditrequest.ts | 22 + src/sdk/models/shared/createeditresponse.ts | 55 + .../models/shared/createembeddingrequest.ts | 13 + .../models/shared/createembeddingresponse.ts | 35 + src/sdk/models/shared/createfilerequest.ts | 18 + .../models/shared/createfinetunerequest.ts | 40 + .../models/shared/createimageeditrequest.ts | 41 + src/sdk/models/shared/createimagerequest.ts | 28 + .../shared/createimagevariationrequest.ts | 27 + .../models/shared/createmoderationrequest.ts | 10 + .../models/shared/createmoderationresponse.ts | 70 + src/sdk/models/shared/createsearchrequest.ts | 22 + src/sdk/models/shared/createsearchresponse.ts | 24 + src/sdk/models/shared/deletefileresponse.ts | 13 + src/sdk/models/shared/deletemodelresponse.ts | 13 + src/sdk/models/shared/index.ts | 26 + src/sdk/models/shared/listenginesresponse.ts | 10 + src/sdk/models/shared/listfilesresponse.ts | 10 + .../shared/listfinetuneeventsresponse.ts | 10 + .../models/shared/listfinetunesresponse.ts | 10 + src/sdk/models/shared/listmodelsresponse.ts | 10 + src/sdk/openai.ts | 1206 +++++++++++++++++ src/sdk/sdk.ts | 43 + tsconfig.json | 32 + 74 files changed, 4469 insertions(+), 1 deletion(-) create mode 100755 README.md create mode 100644 RELEASES.md create mode 100755 USAGE.md create mode 100755 files.gen create mode 100755 package-lock.json create mode 100755 package.json create mode 100755 src/index.ts create mode 100755 src/internal/utils/contenttype.ts create mode 100755 src/internal/utils/headers.ts create mode 100755 src/internal/utils/index.ts create mode 100755 src/internal/utils/pathparams.ts create mode 100755 src/internal/utils/queryparams.ts create mode 100755 src/internal/utils/requestbody.ts create mode 100755 src/internal/utils/retries.ts create mode 100755 src/internal/utils/security.ts create mode 100755 src/internal/utils/utils.ts create mode 100755 src/sdk/index.ts create mode 100755 src/sdk/models/operations/cancelfinetune.ts create mode 100755 src/sdk/models/operations/createanswer.ts create mode 100755 src/sdk/models/operations/createclassification.ts create mode 100755 src/sdk/models/operations/createcompletion.ts create mode 100755 src/sdk/models/operations/createedit.ts create mode 100755 src/sdk/models/operations/createembedding.ts create mode 100755 src/sdk/models/operations/createfile.ts create mode 100755 src/sdk/models/operations/createfinetune.ts create mode 100755 src/sdk/models/operations/createimage.ts create mode 100755 src/sdk/models/operations/createimageedit.ts create mode 100755 src/sdk/models/operations/createimagevariation.ts create mode 100755 src/sdk/models/operations/createmoderation.ts create mode 100755 src/sdk/models/operations/createsearch.ts create mode 100755 src/sdk/models/operations/deletefile.ts create mode 100755 src/sdk/models/operations/deletemodel.ts create mode 100755 src/sdk/models/operations/downloadfile.ts create mode 100755 src/sdk/models/operations/index.ts create mode 100755 src/sdk/models/operations/listengines.ts create mode 100755 src/sdk/models/operations/listfiles.ts create mode 100755 src/sdk/models/operations/listfinetuneevents.ts create mode 100755 src/sdk/models/operations/listfinetunes.ts create mode 100755 src/sdk/models/operations/listmodels.ts create mode 100755 src/sdk/models/operations/retrieveengine.ts create mode 100755 src/sdk/models/operations/retrievefile.ts create mode 100755 src/sdk/models/operations/retrievefinetune.ts create mode 100755 src/sdk/models/operations/retrievemodel.ts create mode 100755 src/sdk/models/shared/createanswerrequest.ts create mode 100755 src/sdk/models/shared/createanswerresponse.ts create mode 100755 src/sdk/models/shared/createclassificationrequest.ts create mode 100755 src/sdk/models/shared/createclassificationresponse.ts create mode 100755 src/sdk/models/shared/createcompletionrequest.ts create mode 100755 src/sdk/models/shared/createcompletionresponse.ts create mode 100755 src/sdk/models/shared/createeditrequest.ts create mode 100755 src/sdk/models/shared/createeditresponse.ts create mode 100755 src/sdk/models/shared/createembeddingrequest.ts create mode 100755 src/sdk/models/shared/createembeddingresponse.ts create mode 100755 src/sdk/models/shared/createfilerequest.ts create mode 100755 src/sdk/models/shared/createfinetunerequest.ts create mode 100755 src/sdk/models/shared/createimageeditrequest.ts create mode 100755 src/sdk/models/shared/createimagerequest.ts create mode 100755 src/sdk/models/shared/createimagevariationrequest.ts create mode 100755 src/sdk/models/shared/createmoderationrequest.ts create mode 100755 src/sdk/models/shared/createmoderationresponse.ts create mode 100755 src/sdk/models/shared/createsearchrequest.ts create mode 100755 src/sdk/models/shared/createsearchresponse.ts create mode 100755 src/sdk/models/shared/deletefileresponse.ts create mode 100755 src/sdk/models/shared/deletemodelresponse.ts create mode 100755 src/sdk/models/shared/index.ts create mode 100755 src/sdk/models/shared/listenginesresponse.ts create mode 100755 src/sdk/models/shared/listfilesresponse.ts create mode 100755 src/sdk/models/shared/listfinetuneeventsresponse.ts create mode 100755 src/sdk/models/shared/listfinetunesresponse.ts create mode 100755 src/sdk/models/shared/listmodelsresponse.ts create mode 100755 src/sdk/openai.ts create mode 100755 src/sdk/sdk.ts create mode 100755 tsconfig.json diff --git a/README.md b/README.md new file mode 100755 index 0000000..2dc1f88 --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +# @openai/sdk + + +## SDK Installation + +### NPM + +```bash +npm add @openai/sdk +``` + +### Yarn + +```bash +yarn add @openai/sdk +``` + + +## SDK Example Usage + +```typescript +import { Openai, withSecurity} from "@openai/sdk"; +import { CancelFineTuneRequest, CancelFineTuneResponse } from "@openai/sdk/src/sdk/models/operations"; +import { AxiosError } from "axios"; + + +const sdk = new Openai(); + +const req: CancelFineTuneRequest = { + pathParams: { + fineTuneId: "unde", + }, +}; + +sdk.openAI.cancelFineTune(req).then((res: CancelFineTuneResponse | AxiosError) => { + // handle response +}); +``` + + + +## SDK Available Operations + + +### openAI + +* `cancelFineTune` - Immediately cancel a fine-tune job. + +* `createAnswer` - Answers the specified question using the provided documents and examples. + +The endpoint first [searches](/docs/api-reference/searches) over provided documents or files to find relevant context. The relevant context is combined with the provided examples and question to create the prompt for [completion](/docs/api-reference/completions). + +* `createClassification` - Classifies the specified `query` using provided examples. + +The endpoint first [searches](/docs/api-reference/searches) over the labeled examples +to select the ones most relevant for the particular query. Then, the relevant examples +are combined with the query to construct a prompt to produce the final label via the +[completions](/docs/api-reference/completions) endpoint. + +Labeled examples can be provided via an uploaded `file`, or explicitly listed in the +request using the `examples` parameter for quick tests and small scale use cases. + +* `createCompletion` - Creates a completion for the provided prompt and parameters +* `createEdit` - Creates a new edit for the provided input, instruction, and parameters +* `createEmbedding` - Creates an embedding vector representing the input text. +* `createFile` - Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. + +* `createFineTune` - Creates a job that fine-tunes a specified model from a given dataset. + +Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. + +[Learn more about Fine-tuning](/docs/guides/fine-tuning) + +* `createImage` - Creates an image given a prompt. +* `createImageEdit` - Creates an edited or extended image given an original image and a prompt. +* `createImageVariation` - Creates a variation of a given image. +* `createModeration` - Classifies if text violates OpenAI's Content Policy +* `createSearch` - The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. + +To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time. When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents. These documents will be returned along with their search scores. + +The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query. + +* `deleteFile` - Delete a file. +* `deleteModel` - Delete a fine-tuned model. You must have the Owner role in your organization. +* `downloadFile` - Returns the contents of the specified file +* `listEngines` - Lists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability. +* `listFiles` - Returns a list of files that belong to the user's organization. +* `listFineTuneEvents` - Get fine-grained status updates for a fine-tune job. + +* `listFineTunes` - List your organization's fine-tuning jobs + +* `listModels` - Lists the currently available models, and provides basic information about each one such as the owner and availability. +* `retrieveEngine` - Retrieves a model instance, providing basic information about it such as the owner and availability. +* `retrieveFile` - Returns information about a specific file. +* `retrieveFineTune` - Gets info about the fine-tune job. + +[Learn more about Fine-tuning](/docs/guides/fine-tuning) + +* `retrieveModel` - Retrieves a model instance, providing basic information about the model such as the owner and permissioning. + + +### SDK Generated by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks) diff --git a/RELEASES.md b/RELEASES.md new file mode 100644 index 0000000..eae99b6 --- /dev/null +++ b/RELEASES.md @@ -0,0 +1,7 @@ + + +## Version 1.2.0 +### Changes +Based on: +- OpenAPI Doc 1.1.0 https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml +- Speakeasy CLI 1.4.7 https://github.com/speakeasy-api/speakeasy \ No newline at end of file diff --git a/USAGE.md b/USAGE.md new file mode 100755 index 0000000..9e0ff5b --- /dev/null +++ b/USAGE.md @@ -0,0 +1,20 @@ + +```typescript +import { Openai, withSecurity} from "@openai/sdk"; +import { CancelFineTuneRequest, CancelFineTuneResponse } from "@openai/sdk/src/sdk/models/operations"; +import { AxiosError } from "axios"; + + +const sdk = new Openai(); + +const req: CancelFineTuneRequest = { + pathParams: { + fineTuneId: "unde", + }, +}; + +sdk.openAI.cancelFineTune(req).then((res: CancelFineTuneResponse | AxiosError) => { + // handle response +}); +``` + \ No newline at end of file diff --git a/files.gen b/files.gen new file mode 100755 index 0000000..eb0b0f4 --- /dev/null +++ b/files.gen @@ -0,0 +1,70 @@ +src/sdk/openai.ts +src/sdk/sdk.ts +package-lock.json +package.json +src/index.ts +src/internal/utils/contenttype.ts +src/internal/utils/headers.ts +src/internal/utils/index.ts +src/internal/utils/pathparams.ts +src/internal/utils/queryparams.ts +src/internal/utils/requestbody.ts +src/internal/utils/retries.ts +src/internal/utils/security.ts +src/internal/utils/utils.ts +src/sdk/index.ts +tsconfig.json +src/sdk/models/operations/cancelfinetune.ts +src/sdk/models/operations/createanswer.ts +src/sdk/models/operations/createclassification.ts +src/sdk/models/operations/createcompletion.ts +src/sdk/models/operations/createedit.ts +src/sdk/models/operations/createembedding.ts +src/sdk/models/operations/createfile.ts +src/sdk/models/operations/createfinetune.ts +src/sdk/models/operations/createimage.ts +src/sdk/models/operations/createimageedit.ts +src/sdk/models/operations/createimagevariation.ts +src/sdk/models/operations/createmoderation.ts +src/sdk/models/operations/createsearch.ts +src/sdk/models/operations/deletefile.ts +src/sdk/models/operations/deletemodel.ts +src/sdk/models/operations/downloadfile.ts +src/sdk/models/operations/listengines.ts +src/sdk/models/operations/listfiles.ts +src/sdk/models/operations/listfinetuneevents.ts +src/sdk/models/operations/listfinetunes.ts +src/sdk/models/operations/listmodels.ts +src/sdk/models/operations/retrieveengine.ts +src/sdk/models/operations/retrievefile.ts +src/sdk/models/operations/retrievefinetune.ts +src/sdk/models/operations/retrievemodel.ts +src/sdk/models/operations/index.ts +src/sdk/models/shared/createanswerresponse.ts +src/sdk/models/shared/createanswerrequest.ts +src/sdk/models/shared/createclassificationresponse.ts +src/sdk/models/shared/createclassificationrequest.ts +src/sdk/models/shared/createcompletionresponse.ts +src/sdk/models/shared/createcompletionrequest.ts +src/sdk/models/shared/createeditresponse.ts +src/sdk/models/shared/createeditrequest.ts +src/sdk/models/shared/createembeddingresponse.ts +src/sdk/models/shared/createembeddingrequest.ts +src/sdk/models/shared/createfilerequest.ts +src/sdk/models/shared/createfinetunerequest.ts +src/sdk/models/shared/createimagerequest.ts +src/sdk/models/shared/createimageeditrequest.ts +src/sdk/models/shared/createimagevariationrequest.ts +src/sdk/models/shared/createmoderationresponse.ts +src/sdk/models/shared/createmoderationrequest.ts +src/sdk/models/shared/createsearchresponse.ts +src/sdk/models/shared/createsearchrequest.ts +src/sdk/models/shared/deletefileresponse.ts +src/sdk/models/shared/deletemodelresponse.ts +src/sdk/models/shared/listenginesresponse.ts +src/sdk/models/shared/listfilesresponse.ts +src/sdk/models/shared/listfinetuneeventsresponse.ts +src/sdk/models/shared/listfinetunesresponse.ts +src/sdk/models/shared/listmodelsresponse.ts +src/sdk/models/shared/index.ts +USAGE.md \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index 0b25a34..a1e546c 100644 --- a/gen.yaml +++ b/gen.yaml @@ -1,5 +1,9 @@ +management: + openapi-checksum: 070eea1a67c4e5af9e7dbad61d95fd37 + openapi-version: 1.1.0 + speakeasy-version: 1.4.7 typescript: - version: 1.1.0 + version: 1.2.0 packagename: '@openai/sdk' author: openai sdkclassname: openai diff --git a/package-lock.json b/package-lock.json new file mode 100755 index 0000000..8264a40 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,376 @@ +{ + "name": "@openai/sdk", + "version": "1.2.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@openai/sdk", + "version": "1.2.0", + "dependencies": { + "axios": "^1.1.3", + "form-data": "^4.0.0", + "qs": "^6.11.0", + "reflect-metadata": "^0.1.13" + }, + "devDependencies": { + "@types/node": "^18.11.5", + "@types/qs": "^6.9.7", + "typescript": "^4.8.4" + } + }, + "node_modules/@types/node": { + "version": "18.11.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", + "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==", + "dev": true + }, + "node_modules/@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz", + "integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/get-intrinsic": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz", + "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==", + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/typescript": { + "version": "4.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@types/node": { + "version": "18.11.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", + "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==", + "dev": true + }, + "@types/qs": { + "version": "6.9.7", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", + "integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==", + "dev": true + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "axios": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz", + "integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "get-intrinsic": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz", + "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==" + }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "requires": { + "side-channel": "^1.0.4" + } + }, + "reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, + "typescript": { + "version": "4.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100755 index 0000000..77d2a92 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "@openai/sdk", + "version": "1.2.0", + "author": "openai", + "scripts": { + "prepare": "tsc --build" + }, + "dependencies": { + "axios": "^1.1.3", + "form-data": "^4.0.0", + "qs": "^6.11.0", + "reflect-metadata": "^0.1.13" + }, + "devDependencies": { + "@types/node": "^18.11.5", + "@types/qs": "^6.9.7", + "typescript": "^4.8.4" + }, + "main": "dist/index.js", + "files": [ + "dist", + "README.md" + ] +} diff --git a/src/index.ts b/src/index.ts new file mode 100755 index 0000000..d28eeda --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export * from "./sdk"; diff --git a/src/internal/utils/contenttype.ts b/src/internal/utils/contenttype.ts new file mode 100755 index 0000000..50c1d0a --- /dev/null +++ b/src/internal/utils/contenttype.ts @@ -0,0 +1,29 @@ +export function matchContentType( + contentType: string, + pattern: string +): boolean { + let res = false; + contentType + .split(";") + .map((ctPart: string) => { + return ctPart.trim(); + }) + .forEach((ctPart: string) => { + if (ctPart === pattern || pattern === "*" || pattern === "*/*") { + res = true; + return; + } + if (ctPart === pattern) { + res = true; + return; + } + const parts: string[] = ctPart.split("/"); + if (parts.length === 2) { + if (`${parts[0]}/*` === pattern || `*/${parts[1]}` === pattern) { + res = true; + return; + } + } + }); + return res; +} diff --git a/src/internal/utils/headers.ts b/src/internal/utils/headers.ts new file mode 100755 index 0000000..6dab0c9 --- /dev/null +++ b/src/internal/utils/headers.ts @@ -0,0 +1,110 @@ +import { AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios"; +import { + isBooleanRecord, + isEmpty, + isNumberRecord, + isStringRecord, + parseParamDecorator, +} from "./utils"; + +import { ParamDecorator } from "./pathparams"; + +export const headerMetadataKey = "header"; + +export function getHeadersFromRequest(headerParams: any): any { + if (headerParams == null) return; + let headers: any = {}; + const fieldNames: string[] = Object.getOwnPropertyNames(headerParams); + fieldNames.forEach((fname) => { + const headerAnn: string = Reflect.getMetadata( + headerMetadataKey, + headerParams, + fname + ); + if (headerAnn == null) return; + const headerDecorator: ParamDecorator = parseParamDecorator( + headerAnn, + fname, + "simple", + false + ); + if (headerDecorator == null) return; + const value: string = serializeHeader( + headerParams[fname], + headerDecorator.Explode + ); + if (value != "") headers[headerDecorator.ParamName] = value; + }); + return headers; +} + +export function getHeadersFromResponse( + headers: RawAxiosResponseHeaders | AxiosResponseHeaders +): Record { + const reponseHeaders: Record = {}; + + Object.keys(headers).forEach((key) => { + const value = headers[key]; + + if (!value) return; + + if (Array.isArray(value)) { + const h: string[] = []; + + value.forEach((val: any) => { + if (val) { + h.push(String(val)); + } + }); + + reponseHeaders[key] = h; + } else { + reponseHeaders[key] = [value]; + } + }); + + return reponseHeaders; +} + +function serializeHeader(header: any, explode: boolean): string { + const headerVals: string[] = []; + if (Array.isArray(header)) { + header.forEach((val: any) => { + headerVals.push(String(val)); + }); + } else if ( + isStringRecord(header) || + isNumberRecord(header) || + isBooleanRecord(header) + ) { + Object.getOwnPropertyNames(header).forEach((headerKey: string) => { + if (explode) headerVals.push(`${headerKey}=${header[headerKey]}`); + else headerVals.push(`${headerKey},${header[headerKey]}`); + }); + } else if (header instanceof Object) { + Object.getOwnPropertyNames(header).forEach((headerKey: string) => { + const headerAnn: string = Reflect.getMetadata( + headerMetadataKey, + header, + headerKey + ); + if (headerAnn == null) return; + const headerDecorator: ParamDecorator = parseParamDecorator( + headerAnn, + headerKey, + "simple", + explode + ); + if (headerDecorator == null) return; + + const headerFieldValue = header[headerKey]; + if (isEmpty(headerFieldValue)) return; + else if (explode) + headerVals.push(`${headerDecorator.ParamName}=${headerFieldValue}`); + else headerVals.push(`${headerDecorator.ParamName},${headerFieldValue}`); + }); + } else { + return String(header); + } + return headerVals.join(","); +} diff --git a/src/internal/utils/index.ts b/src/internal/utils/index.ts new file mode 100755 index 0000000..d885793 --- /dev/null +++ b/src/internal/utils/index.ts @@ -0,0 +1,8 @@ +export * from "./contenttype"; +export * from "./headers"; +export * from "./pathparams"; +export * from "./queryparams"; +export * from "./requestbody"; +export * from "./retries"; +export * from "./security"; +export * from "./utils"; diff --git a/src/internal/utils/pathparams.ts b/src/internal/utils/pathparams.ts new file mode 100755 index 0000000..787cedc --- /dev/null +++ b/src/internal/utils/pathparams.ts @@ -0,0 +1,70 @@ +import { parseParamDecorator } from "./utils"; +import { isStringRecord, isNumberRecord, isBooleanRecord, isEmpty } from "./utils"; + +export const ppMetadataKey = "pathParam"; + +export function getSimplePathParams( + paramName: string, + paramValue: any, + explode: boolean +): Map { + const pathParams: Map = new Map(); + const ppVals: string[] = []; + if (Array.isArray(paramValue)) { + paramValue.forEach((param) => { + ppVals.push(String(param)); + }); + pathParams.set(paramName, ppVals.join(",")); + } else if (isStringRecord(paramValue) || isNumberRecord(paramValue) || isBooleanRecord(paramValue)) { + Object.getOwnPropertyNames(paramValue).forEach((paramKey: string) => { + if (explode) ppVals.push(`${paramKey}=${paramValue[paramKey]}`); + else ppVals.push(`${paramKey},${paramValue[paramKey]}`); + }); + pathParams.set(paramName, ppVals.join(",")); + } else if (paramValue instanceof Object) { + Object.getOwnPropertyNames(paramValue).forEach((paramKey: string) => { + const ppAnn: string = Reflect.getMetadata( + ppMetadataKey, + paramValue, + paramKey + ); + if (ppAnn == null) return; + const ppDecorator: ParamDecorator = parseParamDecorator( + ppAnn, + paramKey, + "simple", + explode + ); + if (ppDecorator == null) return; + + const paramFieldValue = paramValue[paramKey]; + + if (isEmpty(paramFieldValue)) return; + else if (explode) + ppVals.push(`${ppDecorator.ParamName}=${paramFieldValue}`); + else ppVals.push(`${ppDecorator.ParamName},${paramFieldValue}`); + }); + pathParams.set(paramName, ppVals.join(",")); + } else { + pathParams.set(paramName, String(paramValue)); + } + return pathParams; +} + +export class ParamDecorator { + Style: string; + Explode: boolean; + ParamName: string; + Serialization?: string; + constructor( + Style: string, + Explode: boolean, + ParamName: string, + Serialization?: string + ) { + this.Style = Style; + this.Explode = Explode; + this.ParamName = ParamName; + this.Serialization = Serialization; + } +} diff --git a/src/internal/utils/queryparams.ts b/src/internal/utils/queryparams.ts new file mode 100755 index 0000000..34e34c4 --- /dev/null +++ b/src/internal/utils/queryparams.ts @@ -0,0 +1,98 @@ +import {ParamDecorator} from "./pathparams"; +import {ParamsSerializerOptions} from "axios"; +import {parseParamDecorator} from "./utils"; +import qs from "qs"; + +export const qpMetadataKey = "queryParam"; + +export function getQueryParamSerializer( + queryParams: any +): ParamsSerializerOptions { + let paramsSerializer: ParamsSerializerOptions = { + serialize: formSerializerExplode, + }; + if (!queryParams) return paramsSerializer; + const fieldNames: string[] = Object.getOwnPropertyNames(queryParams); + fieldNames.forEach((fname) => { + const qpAnn: string = Reflect.getMetadata( + qpMetadataKey, + queryParams, + fname + ); + if (!qpAnn) return {serialize: (params: any) => ""}; + const qpDecorator: ParamDecorator = parseParamDecorator( + qpAnn, + fname, + "form", + true + ); + if (!qpDecorator) return; + if (qpDecorator.Serialization === "json") + paramsSerializer = { + serialize: (params: any) => Object.keys(params).map(key => + `${key}=${JSON.stringify(params[key])}` + ).join("&"), + }; + else { + switch (qpDecorator.Style) { + case "deepObject": + paramsSerializer = { + serialize: (params: any) => { + return qs.stringify(params); + }, + }; + break; + case "form": + if (qpDecorator.Explode) { + paramsSerializer = { + serialize: formSerializerExplode, + }; + } else { + paramsSerializer = { + serialize: formSerializer, + }; + } + break; + default: + // go to next query parameter field, assume first implemented serializer will serialize all query parameters for this request + return; + } + } + }); + return paramsSerializer; +} + +function formSerializer(params: any): string { + const query: string[] = []; + Object.entries(Object.assign({}, params)).forEach(([key, value]) => { + if (!value) return; + if (value !== Object(value)) query.push(`${key}=${value}`); + else if (Array.isArray(value)) { + const values: string = value.join(","); + query.push(`${key}=${values}`); + } else { + const values: string = Object.entries(Object.assign({}, value)) + .map(([objKey, objValue]) => `${objKey},${objValue}`) + .join(","); + query.push(`${key}=${values}`); + } + }); + return query.join("&"); +} + +function formSerializerExplode(params: any): string { + const query: string[] = []; + Object.entries(Object.assign({}, params)).forEach(([key, value]) => { + if (!value) return; + if (value !== Object(value)) query.push(`${key}=${value}`); + else if (Array.isArray(value)) { + query.push(value.map((aValue) => `${key}=${aValue}`).join("&")); + } else + query.push( + Object.entries(Object.assign({}, value)) + .map(([objKey, objValue]) => `${objKey}=${objValue}`) + .join("&") + ); + }); + return query.join("&"); +} diff --git a/src/internal/utils/requestbody.ts b/src/internal/utils/requestbody.ts new file mode 100755 index 0000000..fa6e8bf --- /dev/null +++ b/src/internal/utils/requestbody.ts @@ -0,0 +1,302 @@ +import FormData from "form-data"; + +const requestMetadataKey = "request"; +const mpFormMetadataKey = "multipart_form"; + +export function serializeRequestBody(request: any): [object, any] { + if (!request.hasOwnProperty(requestMetadataKey)) { + throw new Error("request body not found"); + } + let requestBodyObj = request; + const firstLevelRequestAnn: string = Reflect.getMetadata( + requestMetadataKey, + request, + requestMetadataKey + ); + if (firstLevelRequestAnn == null) + requestBodyObj = request[requestMetadataKey]; + const fieldNames: string[] = Object.getOwnPropertyNames(requestBodyObj); + let [requestHeaders, requestBody]: [object, any] = [{}, {}]; + fieldNames.forEach((fname) => { + const requestAnn: string = Reflect.getMetadata( + requestMetadataKey, + requestBodyObj, + fname + ); + if (requestAnn == null) return; + const requestDecorator: RequestDecorator = + parseRequestDecorator(requestAnn); + switch (requestDecorator.MediaType) { + case "multipart/form-data": + case "multipart/mixed": + requestBody = encodeMultipartFormData(requestBodyObj[fname]); + requestHeaders = (requestBody as FormData).getHeaders(); + break; + case "application/x-www-form-urlencoded": + [requestHeaders, requestBody] = [ + {"Content-Type": `${requestDecorator.MediaType}`}, + encodeFormUrlEncodeData(requestBodyObj[fname]) + ]; + break; + case "application/json": + case "text/json": + [requestHeaders, requestBody] = [ + {"Content-Type": `${requestDecorator.MediaType}`}, + {...requestBodyObj[fname]}, + ]; + break; + default: + requestBody = requestBodyObj[fname]; + const requestBodyType: string = typeof requestBody; + if ( + requestBodyType === "string" || + requestBody instanceof String || + requestBody instanceof Uint8Array + ) + requestHeaders = {"Content-Type": `${requestDecorator.MediaType}`}; + else + throw new Error( + `invalid request body type ${requestBodyType} for mediaType ${requestDecorator.MediaType}` + ); + } + }); + return [requestHeaders, requestBody]; +} + +type FormAnnotation = { + name?: string; + style?: string; + explode?: boolean; + json?: boolean; +}; + +const encodeFormUrlEncodeData = (data: any): FormData => { + const formData: FormData = new FormData(); + const fieldNames: string[] = Object.getOwnPropertyNames(data); + fieldNames.forEach((fname) => { + const formAnn: string = Reflect.getMetadata( + "form", + data, + fname + ); + if (formAnn === null) { + return; + } + const annotation = parseFormMetadata(formAnn); + + if (annotation.json) { + formData.append(annotation.name ?? fname, JSON.stringify(data[fname])); + return; + } + + if (annotation.style === "form") { + let parsed: Record; + if (annotation.explode === true) { + parsed = formExplode(fname, data[fname]); + } else { + parsed = formNotExplode(fname, data[fname]) + } + + Object.keys(parsed).forEach(key => { + parsed[key].forEach(v => + formData.append(key, v)); + }); + return; + } + }); + return formData; +} + +const formExplode = (fname: string, data: any): Record => { + const exploded: Record = {}; + if (Array.isArray(data)) { + data.forEach(value => { + if (!exploded[fname]) { + exploded[fname] = []; + } + exploded[fname].push(value); + }); + } else { + if (typeof data === "object") { + Object.keys(data).forEach(key => { + if (!exploded[key]) { + exploded[key] = []; + } + exploded[key].push(data[key]); + }); + } else { + if (!exploded[fname]) { + exploded[fname] = []; + } + exploded[fname].push(data.toString()); + } + } + return exploded; +} + +const formNotExplode = (fname: string, data: any): Record => { + const notExploded: Record = {}; + if (Array.isArray(data)) { + if (!notExploded[fname]) { + notExploded[fname] = []; + } + notExploded[fname].push(data + .map(item => item.toString()) + .join(",")); + } else { + if (typeof data === "object") { + Object.keys(data).forEach(key => { + if (!notExploded[key]) { + notExploded[key] = []; + } + notExploded[fname].push(`${key}=${data[key]}`); + }); + } else { + if (!notExploded[fname]) { + notExploded[fname] = []; + } + notExploded[fname].push(data.toString()); + } + } + return notExploded; +} + +const parseFormMetadata = (formAnn: string): FormAnnotation => + formAnn.split(";").map((keyValue) => { + const split = keyValue.split("="); + if (split.length !== 2) { + throw new Error(`Unable to parse form metadata "${keyValue}"`); + } + const obj: Record = {}; + obj[split[0]] = split[0] === "explode" || split[0] === "json" ? split[1] === "true" : split[1]; + + return obj; + }).reduce((accum, cur) => ({...accum, ...cur})); + +function encodeMultipartFormData(form: any): FormData { + const formData: FormData = new FormData(); + const fieldNames: string[] = Object.getOwnPropertyNames(form); + fieldNames.forEach((fname) => { + const mpFormAnn: string = Reflect.getMetadata( + mpFormMetadataKey, + form, + fname + ); + if (mpFormAnn == null) return; + const mpFormDecorator: MultipartFormDecorator = + parseMultipartFormDecorator(mpFormAnn); + if (mpFormDecorator.File) + return encodeMultipartFormDataFile(formData, form[fname]); + else if (mpFormDecorator.JSON) { + formData.append(mpFormDecorator.Name, JSON.stringify(form[fname])); + } else { + if (Array.isArray(form[fname])) { + form[fname].forEach((val: any) => { + formData.append(mpFormDecorator.Name + "[]", String(val)); + }); + } else { + formData.append(mpFormDecorator.Name, String(form[fname])); + } + } + }); + return formData; +} + +function encodeMultipartFormDataFile(formData: FormData, file: any): FormData { + if (typeof file !== "object" || Array.isArray(file) || file == null) { + throw new Error("invalid type for multipart/form-data file"); + } + const fieldNames: string[] = Object.getOwnPropertyNames(file); + let content: any = null; + let fileName = ""; + let mpFormDecoratorName = ""; + + fieldNames.forEach((fname) => { + const mpFormAnn: string = Reflect.getMetadata( + mpFormMetadataKey, + file, + fname + ); + if (mpFormAnn == null) return; + const mpFormDecorator: MultipartFormDecorator = + parseMultipartFormDecorator(mpFormAnn); + if (!mpFormDecorator.Content && mpFormDecorator.Name == "") return; + if (mpFormDecorator.Content) content = file[fname]; + else { + mpFormDecoratorName = mpFormDecorator.Name; + fileName = file[fname]; + } + }); + + if (mpFormDecoratorName === "" || fileName === "" || content == null) { + throw new Error("invalid multipart/form-data file"); + } + formData.append( + "file", + Buffer.from(content), + fileName + ); + return formData; +} + +function parseMultipartFormDecorator( + mpFormAnn: string +): MultipartFormDecorator { + // example "name=file" + const mpFormDecorator: MultipartFormDecorator = new MultipartFormDecorator( + false, + false, + false, + "" + ); + mpFormAnn.split(";").forEach((mpFormAnnPart) => { + const [mpFormKey, mpFormVal]: string[] = mpFormAnnPart.split("="); + switch (mpFormKey) { + case "file": + mpFormDecorator.File = mpFormVal == "true"; + break; + case "content": + mpFormDecorator.Content = mpFormVal == "true"; + break; + case "name": + mpFormDecorator.Name = mpFormVal; + break; + case "json": + mpFormDecorator.JSON = mpFormVal == "true"; + } + }); + + return mpFormDecorator; +} + +class MultipartFormDecorator { + File: boolean; + Content: boolean; + JSON: boolean; + Name: string; + + constructor(File: boolean, Content: boolean, JSON: boolean, Name: string) { + this.File = File; + this.Content = Content; + this.JSON = JSON; + this.Name = Name; + } +} + +function parseRequestDecorator(requestAnn: string): RequestDecorator { + // example "media_type=multipart/form-data" + const requestDecorator: RequestDecorator = new RequestDecorator( + "application/octet-stream" + ); + const [mediaTypeKey, mediaTypeVal]: string[] = requestAnn.split("="); + if (mediaTypeKey === "media_type") requestDecorator.MediaType = mediaTypeVal; + return requestDecorator; +} + +class RequestDecorator { + MediaType: string; + + constructor(MediaType: string) { + this.MediaType = MediaType; + } +} diff --git a/src/internal/utils/retries.ts b/src/internal/utils/retries.ts new file mode 100755 index 0000000..db616a6 --- /dev/null +++ b/src/internal/utils/retries.ts @@ -0,0 +1,168 @@ +import { AxiosError, AxiosResponse } from "axios"; + +export class BackoffStrategy { + initialInterval: number; + maxInterval: number; + exponent: number; + maxElapsedTime: number; + + constructor( + initialInterval: number, + maxInterval: number, + exponent: number, + maxElapsedTime: number + ) { + this.initialInterval = initialInterval; + this.maxInterval = maxInterval; + this.exponent = exponent; + this.maxElapsedTime = maxElapsedTime; + } +} + +export class RetryConfig { + strategy: string; + backoff?: BackoffStrategy; + retryConnectionErrors: boolean; + + constructor(strategy: string, retryConnectionErrors: boolean = true) { + this.strategy = strategy; + this.retryConnectionErrors = retryConnectionErrors; + } +} + +export class Retries { + config: RetryConfig; + statusCodes: string[]; + + constructor(config: RetryConfig, statusCodes: string[]) { + this.config = config; + this.statusCodes = statusCodes; + } +} + +class PermanentError extends Error { + inner: unknown; + + constructor(inner: unknown) { + super("Permanent error"); + this.inner = inner; + } +} + +class TemporaryError extends Error { + res: AxiosResponse; + + constructor(res: AxiosResponse) { + super("Temporary error"); + this.res = res; + } +} + +export async function Retry( + fn: () => Promise>, + retries: Retries +): Promise> { + switch (retries.config.strategy) { + case "backoff": + return retryBackoff( + async () => { + try { + const res = await fn(); + if (isRetryableResponse(res, retries.statusCodes)) { + throw new TemporaryError(res); + } + + return res; + } catch (err) { + if (err instanceof AxiosError) { + if (err.response) { + if (isRetryableResponse(err.response, retries.statusCodes)) { + throw err; + } + throw new PermanentError(err); + } else if (err.request) { + throw err; + } else { + throw new PermanentError(err); + } + } else if (err instanceof TemporaryError) { + throw err; + } + throw new PermanentError(err); + } + }, + retries.config.backoff?.initialInterval ?? 500, + retries.config.backoff?.maxInterval ?? 60000, + retries.config.backoff?.exponent ?? 1.5, + retries.config.backoff?.maxElapsedTime ?? 3600000 + ); + default: + return await fn(); + } +} + +function isRetryableResponse( + res: AxiosResponse, + statusCodes: string[] +): boolean { + for (const code of statusCodes) { + if (code.toUpperCase().includes("X")) { + const codeRange = parseInt(code[0]); + if (isNaN(codeRange)) { + throw new Error("Invalid status code range"); + } + + const s = res.status / 100; + + if (s >= codeRange && s < codeRange + 1) { + return true; + } + } else if (res.status == parseInt(code)) { + return true; + } + } + + return false; +} + +async function retryBackoff( + fn: () => Promise>, + initialInterval: number, + maxInterval: number, + exponent: number, + maxElapsedTime: number +): Promise> { + const start = Date.now(); + let x = 0; + + while (true) { + try { + return await fn(); + } catch (err) { + if (err instanceof PermanentError) { + throw err.inner; + } + + const now = Date.now(); + if (now - start > maxElapsedTime) { + if (err instanceof TemporaryError) { + return err.res; + } + + throw err; + } + + const d = Math.min( + initialInterval * Math.pow(x, exponent) + Math.random() * 1000, + maxInterval + ); + + await delay(d); + x++; + } + } +} + +async function delay(delay: number): Promise { + return new Promise((resolve) => setTimeout(resolve, delay)); +} diff --git a/src/internal/utils/security.ts b/src/internal/utils/security.ts new file mode 100755 index 0000000..28193b2 --- /dev/null +++ b/src/internal/utils/security.ts @@ -0,0 +1,220 @@ +import { AxiosInstance } from "axios"; + +const securityMetadataKey = "security"; + +export function createSecurityClient( + client: AxiosInstance, + security: any +): AxiosInstance { + return parseSecurityClass(client, security); +} + +function parseSecurityDecorator(securityAnn: string): SecurityDecorator { + // scheme=true;type=apiKey;subtype=header" + let option = false; + let scheme = false; + let name = ""; + let securityType = ""; + let securitySubType = ""; + + securityAnn.split(";").forEach((securityAnnPart) => { + const [sKey, sVal]: string[] = securityAnnPart.split("="); + switch (sKey) { + case "name": + name = sVal; + break; + case "type": + securityType = sVal; + break; + case "subtype": + securitySubType = sVal; + break; + case "option": + option = sVal == "true"; + break; + case "scheme": + scheme = sVal == "true"; + } + }); + + return new SecurityDecorator( + name, + securityType, + option, + scheme, + securitySubType + ); +} + +function parseSecurityClass( + client: AxiosInstance, + security: any +): AxiosInstance { + const fieldNames: string[] = Object.getOwnPropertyNames(security); + fieldNames.forEach((fname) => { + const securityAnn: string = Reflect.getMetadata( + securityMetadataKey, + security, + fname + ); + if (securityAnn == null) return; + const securityDecorator: SecurityDecorator = + parseSecurityDecorator(securityAnn); + if (securityDecorator == null) return; + if (securityDecorator.Option) { + return parseSecurityOption(client, security[fname]); + } else if (securityDecorator.Scheme) { + return parseSecurityScheme(client, securityDecorator, security[fname]); + } + }); + + return client; +} + +function parseSecurityOption( + client: AxiosInstance, + optionType: any +): AxiosInstance { + const fieldNames: string[] = Object.getOwnPropertyNames(optionType); + fieldNames.forEach((fname) => { + const securityAnn: string = Reflect.getMetadata( + securityMetadataKey, + optionType, + fname + ); + if (securityAnn == null) return; + const securityDecorator: SecurityDecorator = + parseSecurityDecorator(securityAnn); + if (securityDecorator != null && securityDecorator.Scheme) return; + if (securityDecorator.Scheme) { + return parseSecurityScheme(client, securityDecorator, optionType[fname]); + } + }); + + return client; +} + +function parseSecurityScheme( + client: AxiosInstance, + schemeDecorator: SecurityDecorator, + scheme: any +): AxiosInstance { + if (schemeDecorator.Type === "http" && schemeDecorator.SubType === "basic") { + return parseBasicAuthScheme(client, scheme); + } + + const fieldNames: string[] = Object.getOwnPropertyNames(scheme); + fieldNames.forEach((fname) => { + const securityAnn: string = Reflect.getMetadata( + securityMetadataKey, + scheme, + fname + ); + if (securityAnn == null) return; + const securityDecorator: SecurityDecorator = + parseSecurityDecorator(securityAnn); + if (securityDecorator == null || securityDecorator.Name === "") return; + + switch (schemeDecorator.Type) { + case "apiKey": + switch (schemeDecorator.SubType) { + case "header": + client.defaults.headers.common[securityDecorator.Name] = + scheme[fname]; + break; + case "query": + client.defaults.params[securityDecorator.Name] = scheme[fname]; + break; + case "cookie": + const securityDecoratorName: string = securityDecorator.Name; + const val: string = scheme[fname]; + client.defaults.headers.common[ + "Cookie" + ] = `${securityDecoratorName}=${val}`; + break; + default: + throw new Error("not supported"); + } + break; + case "openIdConnect": + client.defaults.headers.common[securityDecorator.Name] = scheme[fname]; + break; + case "oauth2": + client.defaults.headers.common[securityDecorator.Name] = scheme[fname]; + break; + case "http": + switch (schemeDecorator.SubType) { + case "basic": + break; + case "bearer": + client.defaults.headers.common[securityDecorator.Name] = + scheme[fname]; + break; + default: + throw new Error("not supported"); + } + break; + default: + throw new Error("not supported"); + } + }); + + return client; +} + +function parseBasicAuthScheme( + client: AxiosInstance, + scheme: any +): AxiosInstance { + let username, + password = ""; + + const fieldNames: string[] = Object.getOwnPropertyNames(scheme); + fieldNames.forEach((fname) => { + const securityAnn: string = Reflect.getMetadata( + securityMetadataKey, + scheme, + fname + ); + if (securityAnn == null) return; + const securityDecorator: SecurityDecorator = + parseSecurityDecorator(securityAnn); + if (securityDecorator == null || securityDecorator.Name === "") return; + + switch (securityDecorator.Name) { + case "username": + username = scheme[fname]; + break; + case "password": + password = scheme[fname]; + break; + } + }); + + client.defaults.headers.common["Authorization"] = `Basic ${Buffer.from( + `${username}:${password}` + ).toString("base64")}`; + + return client; +} + +class SecurityDecorator { + Name: string; + Type: string; + Option: boolean; + Scheme: boolean; + SubType: string; + constructor( + Name: string, + Type: string, + Option: boolean, + Scheme: boolean, + SubType: string + ) { + this.Name = Name; + this.Type = Type; + this.Option = Option; + this.Scheme = Scheme; + this.SubType = SubType; + } +} diff --git a/src/internal/utils/utils.ts b/src/internal/utils/utils.ts new file mode 100755 index 0000000..bba636f --- /dev/null +++ b/src/internal/utils/utils.ts @@ -0,0 +1,254 @@ +import "reflect-metadata"; + +import { + ParamDecorator, + getSimplePathParams, + ppMetadataKey, +} from "./pathparams"; + +interface propInfo { + key: string | symbol; + type: any; + elemType: any; + elemDepth: number; +} + +function isSpeakeasyBase(type: any): boolean { + return type && Object.getPrototypeOf(type)?.name == "SpeakeasyBase"; +} + +function handleArray(value: any, elemType: any, elemDepth: number): any { + if (!Array.isArray(value)) { + return value; + } + + if (elemDepth == 1) { + return value.map((v: any) => new elemType(v)); + } else { + return value.map((v: any) => { + if (Array.isArray(v)) { + return handleArray(v, elemType, elemDepth - 1); + } else if (typeof v == "object") { + return handleObject(v, elemType, elemDepth - 1); + } else { + return v; + } + }); + } +} + +function handleObject(value: any, elemType: any, elemDepth: number): any { + if (typeof value != "object") { + return value; + } + + if (elemDepth == 1) { + return Object.keys(value).reduce((acc: any, key: string) => { + acc[key] = new elemType(value[key]); + return acc; + }, {}); + } else { + return Object.keys(value).reduce((acc: any, key: string) => { + const v = value[key]; + if (Array.isArray(v)) { + acc[key] = handleArray(v, elemType, elemDepth - 1); + } else if (typeof v == "object") { + acc[key] = handleObject(v, elemType, elemDepth - 1); + } else { + acc[key] = v; + } + return acc; + }, {}); + } +} + +export class SpeakeasyBase { + constructor(payload?: Record) { + const props: propInfo[] = (this as any)["__props__"]; + if (props) { + for (const prop of props) { + if (payload && payload.hasOwnProperty(prop.key)) { + const value = payload[prop.key]; + if (isSpeakeasyBase(prop.type)) { + (this as any)[prop.key] = new prop.type(value); + } else if ( + prop.type.name == "Array" && + isSpeakeasyBase(prop.elemType) + ) { + (this as any)[prop.key] = handleArray( + value, + prop.elemType, + prop.elemDepth + ); + } else if ( + prop.type.name == "Object" && + isSpeakeasyBase(prop.elemType) + ) { + (this as any)[prop.key] = handleObject( + value, + prop.elemType, + prop.elemDepth + ); + } else { + (this as any)[prop.key] = value; + } + } + } + } + } +} + +export function SpeakeasyMetadata< + T extends SpeakeasyBase = Record +>(params?: { + data?: string; + elemType?: { new (): T }; + elemDepth?: number; +}): PropertyDecorator { + return (target, propertyKey) => { + if (params?.data) { + const annsArr = params.data.split(", "); + + for (let i = 0; i < annsArr.length; i += 2) { + Reflect.defineMetadata(annsArr[i], annsArr[i + 1], target, propertyKey); + } + } + + let props: propInfo[]; + if (target.hasOwnProperty("__props__")) { + props = (target as any)["__props__"]; + } else { + props = (target as any)["__props__"] = []; + } + + const prop = { + key: propertyKey, + type: Reflect.getMetadata("design:type", target, propertyKey), + } as propInfo; + + if (params?.elemType) { + prop.elemType = params.elemType; + prop.elemDepth = params.elemDepth || 1; + } + + props.push(prop); + }; +} + +export function replaceParameters( + stringWithParams: string, + params: Map +): string { + let res: string = stringWithParams; + params.forEach((value, key) => { + const match: string = "{" + key + "}"; + res = res.replaceAll(match, value); + }); + return res; +} + +export function generateURL( + serverURL: string, + path: string, + pathParams: any +): string { + const url: string = serverURL.replace(/\/$/, "") + path; + const parsedParameters: Map = new Map(); + const fieldNames: string[] = Object.getOwnPropertyNames(pathParams); + fieldNames.forEach((fname) => { + const ppAnn: string = Reflect.getMetadata(ppMetadataKey, pathParams, fname); + if (ppAnn == null) return; + const ppDecorator: ParamDecorator = parseParamDecorator( + ppAnn, + fname, + "simple", + false + ); + if (ppDecorator == null) return; + switch (ppDecorator.Style) { + case "simple": + const simpleParams: Map = getSimplePathParams( + ppDecorator.ParamName, + pathParams[fname], + ppDecorator.Explode + ); + simpleParams.forEach((value, key) => { + parsedParameters.set(key, value); + }); + } + }); + return replaceParameters(url, parsedParameters); +} + +export function parseParamDecorator( + ann: string, + fName: string, + defaultStyle: string, + defaultExplode: boolean +): ParamDecorator { + // style=simple;explode=false;name=apiID + const decorator: ParamDecorator = new ParamDecorator( + defaultStyle, + defaultExplode, + fName.toLowerCase() + ); + + ann.split(";").forEach((annPart) => { + const [paramKey, paramVal]: string[] = annPart.split("="); + switch (paramKey) { + case "style": + decorator.Style = paramVal; + break; + case "explode": + decorator.Explode = paramVal == "true"; + break; + case "name": + decorator.ParamName = paramVal; + break; + case "serialization": + decorator.Serialization = paramVal; + } + }); + return decorator; +} + +export function isStringRecord(obj: any): obj is Record { + if (typeof obj !== "object") + return false + + if (Object.getOwnPropertySymbols(obj).length > 0) + return false + + return Object.getOwnPropertyNames(obj) + .every(prop => typeof obj[prop] === "string") +} + +export function isNumberRecord(obj: any): obj is Record { + if (typeof obj !== "object") + return false + + if (Object.getOwnPropertySymbols(obj).length > 0) + return false + + return Object.getOwnPropertyNames(obj) + .every(prop => typeof obj[prop] === "number") +} + +export function isBooleanRecord(obj: any): obj is Record { + if (typeof obj !== "object") + return false + + if (Object.getOwnPropertySymbols(obj).length > 0) + return false + + return Object.getOwnPropertyNames(obj) + .every(prop => typeof obj[prop] === "boolean") +} + +export function isEmpty(value: any): boolean { + // check for undefined, null, and NaN + let res: boolean = false; + if (typeof value === "number") res = Number.isNaN(value); + else if (typeof value === "string") res = value === ""; + return res || value == null; +} diff --git a/src/sdk/index.ts b/src/sdk/index.ts new file mode 100755 index 0000000..d28eeda --- /dev/null +++ b/src/sdk/index.ts @@ -0,0 +1 @@ +export * from "./sdk"; diff --git a/src/sdk/models/operations/cancelfinetune.ts b/src/sdk/models/operations/cancelfinetune.ts new file mode 100755 index 0000000..e78d06b --- /dev/null +++ b/src/sdk/models/operations/cancelfinetune.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CancelFineTunePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=fine_tune_id" }) + fineTuneId: string; +} + +export class CancelFineTuneRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: CancelFineTunePathParams; +} + +export class CancelFineTuneResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + fineTune?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createanswer.ts b/src/sdk/models/operations/createanswer.ts new file mode 100755 index 0000000..57f20df --- /dev/null +++ b/src/sdk/models/operations/createanswer.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateAnswerRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateAnswerRequest; +} + +export class CreateAnswerResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createAnswerResponse?: shared.CreateAnswerResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createclassification.ts b/src/sdk/models/operations/createclassification.ts new file mode 100755 index 0000000..bf3a458 --- /dev/null +++ b/src/sdk/models/operations/createclassification.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateClassificationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateClassificationRequest; +} + +export class CreateClassificationResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createClassificationResponse?: shared.CreateClassificationResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createcompletion.ts b/src/sdk/models/operations/createcompletion.ts new file mode 100755 index 0000000..8fdc6fb --- /dev/null +++ b/src/sdk/models/operations/createcompletion.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateCompletionRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateCompletionRequest; +} + +export class CreateCompletionResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createCompletionResponse?: shared.CreateCompletionResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createedit.ts b/src/sdk/models/operations/createedit.ts new file mode 100755 index 0000000..8fd2a97 --- /dev/null +++ b/src/sdk/models/operations/createedit.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateEditRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateEditRequest; +} + +export class CreateEditResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createEditResponse?: shared.CreateEditResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createembedding.ts b/src/sdk/models/operations/createembedding.ts new file mode 100755 index 0000000..458c336 --- /dev/null +++ b/src/sdk/models/operations/createembedding.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateEmbeddingRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateEmbeddingRequest; +} + +export class CreateEmbeddingResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createEmbeddingResponse?: shared.CreateEmbeddingResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createfile.ts b/src/sdk/models/operations/createfile.ts new file mode 100755 index 0000000..c86bc48 --- /dev/null +++ b/src/sdk/models/operations/createfile.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateFileRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=multipart/form-data" }) + request: shared.CreateFileRequest; +} + +export class CreateFileResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + openAIFile?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createfinetune.ts b/src/sdk/models/operations/createfinetune.ts new file mode 100755 index 0000000..c74b94d --- /dev/null +++ b/src/sdk/models/operations/createfinetune.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateFineTuneRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateFineTuneRequest; +} + +export class CreateFineTuneResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + fineTune?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createimage.ts b/src/sdk/models/operations/createimage.ts new file mode 100755 index 0000000..77e110a --- /dev/null +++ b/src/sdk/models/operations/createimage.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateImageRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateImageRequest; +} + +export class CreateImageResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + imagesResponse?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createimageedit.ts b/src/sdk/models/operations/createimageedit.ts new file mode 100755 index 0000000..918f3e1 --- /dev/null +++ b/src/sdk/models/operations/createimageedit.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateImageEditRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=multipart/form-data" }) + request: shared.CreateImageEditRequest; +} + +export class CreateImageEditResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + imagesResponse?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createimagevariation.ts b/src/sdk/models/operations/createimagevariation.ts new file mode 100755 index 0000000..277b862 --- /dev/null +++ b/src/sdk/models/operations/createimagevariation.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateImageVariationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=multipart/form-data" }) + request: shared.CreateImageVariationRequest; +} + +export class CreateImageVariationResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + imagesResponse?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createmoderation.ts b/src/sdk/models/operations/createmoderation.ts new file mode 100755 index 0000000..204f532 --- /dev/null +++ b/src/sdk/models/operations/createmoderation.ts @@ -0,0 +1,19 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateModerationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateModerationRequest; +} + +export class CreateModerationResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createModerationResponse?: shared.CreateModerationResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/createsearch.ts b/src/sdk/models/operations/createsearch.ts new file mode 100755 index 0000000..8ef5c73 --- /dev/null +++ b/src/sdk/models/operations/createsearch.ts @@ -0,0 +1,27 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class CreateSearchPathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=engine_id" }) + engineId: string; +} + +export class CreateSearchRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: CreateSearchPathParams; + + @SpeakeasyMetadata({ data: "request, media_type=application/json" }) + request: shared.CreateSearchRequest; +} + +export class CreateSearchResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + createSearchResponse?: shared.CreateSearchResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/deletefile.ts b/src/sdk/models/operations/deletefile.ts new file mode 100755 index 0000000..318415c --- /dev/null +++ b/src/sdk/models/operations/deletefile.ts @@ -0,0 +1,24 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class DeleteFilePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=file_id" }) + fileId: string; +} + +export class DeleteFileRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: DeleteFilePathParams; +} + +export class DeleteFileResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + deleteFileResponse?: shared.DeleteFileResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/deletemodel.ts b/src/sdk/models/operations/deletemodel.ts new file mode 100755 index 0000000..86b78e1 --- /dev/null +++ b/src/sdk/models/operations/deletemodel.ts @@ -0,0 +1,24 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class DeleteModelPathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=model" }) + model: string; +} + +export class DeleteModelRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: DeleteModelPathParams; +} + +export class DeleteModelResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + deleteModelResponse?: shared.DeleteModelResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/downloadfile.ts b/src/sdk/models/operations/downloadfile.ts new file mode 100755 index 0000000..3e96dee --- /dev/null +++ b/src/sdk/models/operations/downloadfile.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class DownloadFilePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=file_id" }) + fileId: string; +} + +export class DownloadFileRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: DownloadFilePathParams; +} + +export class DownloadFileResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + statusCode: number; + + @SpeakeasyMetadata() + downloadFile200ApplicationJSONString?: string; +} \ No newline at end of file diff --git a/src/sdk/models/operations/index.ts b/src/sdk/models/operations/index.ts new file mode 100755 index 0000000..c77f06d --- /dev/null +++ b/src/sdk/models/operations/index.ts @@ -0,0 +1,25 @@ +export * from "./cancelfinetune"; +export * from "./createanswer"; +export * from "./createclassification"; +export * from "./createcompletion"; +export * from "./createedit"; +export * from "./createembedding"; +export * from "./createfile"; +export * from "./createfinetune"; +export * from "./createimage"; +export * from "./createimageedit"; +export * from "./createimagevariation"; +export * from "./createmoderation"; +export * from "./createsearch"; +export * from "./deletefile"; +export * from "./deletemodel"; +export * from "./downloadfile"; +export * from "./listengines"; +export * from "./listfiles"; +export * from "./listfinetuneevents"; +export * from "./listfinetunes"; +export * from "./listmodels"; +export * from "./retrieveengine"; +export * from "./retrievefile"; +export * from "./retrievefinetune"; +export * from "./retrievemodel"; diff --git a/src/sdk/models/operations/listengines.ts b/src/sdk/models/operations/listengines.ts new file mode 100755 index 0000000..31a3c36 --- /dev/null +++ b/src/sdk/models/operations/listengines.ts @@ -0,0 +1,14 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class ListEnginesResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + listEnginesResponse?: shared.ListEnginesResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/listfiles.ts b/src/sdk/models/operations/listfiles.ts new file mode 100755 index 0000000..5a75055 --- /dev/null +++ b/src/sdk/models/operations/listfiles.ts @@ -0,0 +1,14 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class ListFilesResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + listFilesResponse?: shared.ListFilesResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/listfinetuneevents.ts b/src/sdk/models/operations/listfinetuneevents.ts new file mode 100755 index 0000000..a29d2fd --- /dev/null +++ b/src/sdk/models/operations/listfinetuneevents.ts @@ -0,0 +1,32 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class ListFineTuneEventsPathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=fine_tune_id" }) + fineTuneId: string; +} + +export class ListFineTuneEventsQueryParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "queryParam, style=form;explode=true;name=stream" }) + stream?: boolean; +} + +export class ListFineTuneEventsRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: ListFineTuneEventsPathParams; + + @SpeakeasyMetadata() + queryParams: ListFineTuneEventsQueryParams; +} + +export class ListFineTuneEventsResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + listFineTuneEventsResponse?: shared.ListFineTuneEventsResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/listfinetunes.ts b/src/sdk/models/operations/listfinetunes.ts new file mode 100755 index 0000000..142c311 --- /dev/null +++ b/src/sdk/models/operations/listfinetunes.ts @@ -0,0 +1,14 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class ListFineTunesResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + listFineTunesResponse?: shared.ListFineTunesResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/listmodels.ts b/src/sdk/models/operations/listmodels.ts new file mode 100755 index 0000000..b9afec9 --- /dev/null +++ b/src/sdk/models/operations/listmodels.ts @@ -0,0 +1,14 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; +import * as shared from "../shared"; + + +export class ListModelsResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + listModelsResponse?: shared.ListModelsResponse; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/retrieveengine.ts b/src/sdk/models/operations/retrieveengine.ts new file mode 100755 index 0000000..3ae1a46 --- /dev/null +++ b/src/sdk/models/operations/retrieveengine.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class RetrieveEnginePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=engine_id" }) + engineId: string; +} + +export class RetrieveEngineRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: RetrieveEnginePathParams; +} + +export class RetrieveEngineResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + engine?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/retrievefile.ts b/src/sdk/models/operations/retrievefile.ts new file mode 100755 index 0000000..4772771 --- /dev/null +++ b/src/sdk/models/operations/retrievefile.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class RetrieveFilePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=file_id" }) + fileId: string; +} + +export class RetrieveFileRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: RetrieveFilePathParams; +} + +export class RetrieveFileResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + openAIFile?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/retrievefinetune.ts b/src/sdk/models/operations/retrievefinetune.ts new file mode 100755 index 0000000..bd01cd1 --- /dev/null +++ b/src/sdk/models/operations/retrievefinetune.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class RetrieveFineTunePathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=fine_tune_id" }) + fineTuneId: string; +} + +export class RetrieveFineTuneRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: RetrieveFineTunePathParams; +} + +export class RetrieveFineTuneResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + fineTune?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/operations/retrievemodel.ts b/src/sdk/models/operations/retrievemodel.ts new file mode 100755 index 0000000..7a4bc6b --- /dev/null +++ b/src/sdk/models/operations/retrievemodel.ts @@ -0,0 +1,23 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class RetrieveModelPathParams extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "pathParam, style=simple;explode=false;name=model" }) + model: string; +} + +export class RetrieveModelRequest extends SpeakeasyBase { + @SpeakeasyMetadata() + pathParams: RetrieveModelPathParams; +} + +export class RetrieveModelResponse extends SpeakeasyBase { + @SpeakeasyMetadata() + contentType: string; + + @SpeakeasyMetadata() + model?: any; + + @SpeakeasyMetadata() + statusCode: number; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createanswerrequest.ts b/src/sdk/models/shared/createanswerrequest.ts new file mode 100755 index 0000000..810a84a --- /dev/null +++ b/src/sdk/models/shared/createanswerrequest.ts @@ -0,0 +1,58 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateAnswerRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=documents" }) + documents?: string[]; + + @SpeakeasyMetadata({ data: "json, name=examples" }) + examples: string[][]; + + @SpeakeasyMetadata({ data: "json, name=examples_context" }) + examplesContext: string; + + @SpeakeasyMetadata({ data: "json, name=expand" }) + expand?: any[]; + + @SpeakeasyMetadata({ data: "json, name=file" }) + file?: string; + + @SpeakeasyMetadata({ data: "json, name=logit_bias" }) + logitBias?: any; + + @SpeakeasyMetadata({ data: "json, name=logprobs" }) + logprobs?: number; + + @SpeakeasyMetadata({ data: "json, name=max_rerank" }) + maxRerank?: number; + + @SpeakeasyMetadata({ data: "json, name=max_tokens" }) + maxTokens?: number; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: string; + + @SpeakeasyMetadata({ data: "json, name=n" }) + n?: number; + + @SpeakeasyMetadata({ data: "json, name=question" }) + question: string; + + @SpeakeasyMetadata({ data: "json, name=return_metadata" }) + returnMetadata?: any; + + @SpeakeasyMetadata({ data: "json, name=return_prompt" }) + returnPrompt?: boolean; + + @SpeakeasyMetadata({ data: "json, name=search_model" }) + searchModel?: string; + + @SpeakeasyMetadata({ data: "json, name=stop" }) + stop?: any; + + @SpeakeasyMetadata({ data: "json, name=temperature" }) + temperature?: number; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createanswerresponse.ts b/src/sdk/models/shared/createanswerresponse.ts new file mode 100755 index 0000000..bca28ce --- /dev/null +++ b/src/sdk/models/shared/createanswerresponse.ts @@ -0,0 +1,30 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateAnswerResponseSelectedDocuments extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=document" }) + document?: number; + + @SpeakeasyMetadata({ data: "json, name=text" }) + text?: string; +} + +export class CreateAnswerResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=answers" }) + answers?: string[]; + + @SpeakeasyMetadata({ data: "json, name=completion" }) + completion?: string; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model?: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object?: string; + + @SpeakeasyMetadata({ data: "json, name=search_model" }) + searchModel?: string; + + @SpeakeasyMetadata({ data: "json, name=selected_documents", elemType: CreateAnswerResponseSelectedDocuments }) + selectedDocuments?: CreateAnswerResponseSelectedDocuments[]; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createclassificationrequest.ts b/src/sdk/models/shared/createclassificationrequest.ts new file mode 100755 index 0000000..df52d0f --- /dev/null +++ b/src/sdk/models/shared/createclassificationrequest.ts @@ -0,0 +1,46 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateClassificationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=examples" }) + examples?: string[][]; + + @SpeakeasyMetadata({ data: "json, name=expand" }) + expand?: any; + + @SpeakeasyMetadata({ data: "json, name=file" }) + file?: string; + + @SpeakeasyMetadata({ data: "json, name=labels" }) + labels?: string[]; + + @SpeakeasyMetadata({ data: "json, name=logit_bias" }) + logitBias?: any; + + @SpeakeasyMetadata({ data: "json, name=logprobs" }) + logprobs?: any; + + @SpeakeasyMetadata({ data: "json, name=max_examples" }) + maxExamples?: number; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: any; + + @SpeakeasyMetadata({ data: "json, name=query" }) + query: string; + + @SpeakeasyMetadata({ data: "json, name=return_metadata" }) + returnMetadata?: any; + + @SpeakeasyMetadata({ data: "json, name=return_prompt" }) + returnPrompt?: any; + + @SpeakeasyMetadata({ data: "json, name=search_model" }) + searchModel?: any; + + @SpeakeasyMetadata({ data: "json, name=temperature" }) + temperature?: number; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createclassificationresponse.ts b/src/sdk/models/shared/createclassificationresponse.ts new file mode 100755 index 0000000..907f6a8 --- /dev/null +++ b/src/sdk/models/shared/createclassificationresponse.ts @@ -0,0 +1,33 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateClassificationResponseSelectedExamples extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=document" }) + document?: number; + + @SpeakeasyMetadata({ data: "json, name=label" }) + label?: string; + + @SpeakeasyMetadata({ data: "json, name=text" }) + text?: string; +} + +export class CreateClassificationResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=completion" }) + completion?: string; + + @SpeakeasyMetadata({ data: "json, name=label" }) + label?: string; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model?: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object?: string; + + @SpeakeasyMetadata({ data: "json, name=search_model" }) + searchModel?: string; + + @SpeakeasyMetadata({ data: "json, name=selected_examples", elemType: CreateClassificationResponseSelectedExamples }) + selectedExamples?: CreateClassificationResponseSelectedExamples[]; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createcompletionrequest.ts b/src/sdk/models/shared/createcompletionrequest.ts new file mode 100755 index 0000000..69dd524 --- /dev/null +++ b/src/sdk/models/shared/createcompletionrequest.ts @@ -0,0 +1,52 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateCompletionRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=best_of" }) + bestOf?: number; + + @SpeakeasyMetadata({ data: "json, name=echo" }) + echo?: boolean; + + @SpeakeasyMetadata({ data: "json, name=frequency_penalty" }) + frequencyPenalty?: number; + + @SpeakeasyMetadata({ data: "json, name=logit_bias" }) + logitBias?: Record; + + @SpeakeasyMetadata({ data: "json, name=logprobs" }) + logprobs?: number; + + @SpeakeasyMetadata({ data: "json, name=max_tokens" }) + maxTokens?: number; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: string; + + @SpeakeasyMetadata({ data: "json, name=n" }) + n?: number; + + @SpeakeasyMetadata({ data: "json, name=presence_penalty" }) + presencePenalty?: number; + + @SpeakeasyMetadata({ data: "json, name=prompt" }) + prompt?: any; + + @SpeakeasyMetadata({ data: "json, name=stop" }) + stop?: any; + + @SpeakeasyMetadata({ data: "json, name=stream" }) + stream?: boolean; + + @SpeakeasyMetadata({ data: "json, name=suffix" }) + suffix?: string; + + @SpeakeasyMetadata({ data: "json, name=temperature" }) + temperature?: number; + + @SpeakeasyMetadata({ data: "json, name=top_p" }) + topP?: number; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createcompletionresponse.ts b/src/sdk/models/shared/createcompletionresponse.ts new file mode 100755 index 0000000..e936309 --- /dev/null +++ b/src/sdk/models/shared/createcompletionresponse.ts @@ -0,0 +1,61 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateCompletionResponseChoicesLogprobs extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=text_offset" }) + textOffset?: number[]; + + @SpeakeasyMetadata({ data: "json, name=token_logprobs" }) + tokenLogprobs?: number[]; + + @SpeakeasyMetadata({ data: "json, name=tokens" }) + tokens?: string[]; + + @SpeakeasyMetadata({ data: "json, name=top_logprobs" }) + topLogprobs?: Record[]; +} + +export class CreateCompletionResponseChoices extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=finish_reason" }) + finishReason?: string; + + @SpeakeasyMetadata({ data: "json, name=index" }) + index?: number; + + @SpeakeasyMetadata({ data: "json, name=logprobs" }) + logprobs?: CreateCompletionResponseChoicesLogprobs; + + @SpeakeasyMetadata({ data: "json, name=text" }) + text?: string; +} + +export class CreateCompletionResponseUsage extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=completion_tokens" }) + completionTokens: number; + + @SpeakeasyMetadata({ data: "json, name=prompt_tokens" }) + promptTokens: number; + + @SpeakeasyMetadata({ data: "json, name=total_tokens" }) + totalTokens: number; +} + +export class CreateCompletionResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=choices", elemType: CreateCompletionResponseChoices }) + choices: CreateCompletionResponseChoices[]; + + @SpeakeasyMetadata({ data: "json, name=created" }) + created: number; + + @SpeakeasyMetadata({ data: "json, name=id" }) + id: string; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; + + @SpeakeasyMetadata({ data: "json, name=usage" }) + usage?: CreateCompletionResponseUsage; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createeditrequest.ts b/src/sdk/models/shared/createeditrequest.ts new file mode 100755 index 0000000..f83d5ce --- /dev/null +++ b/src/sdk/models/shared/createeditrequest.ts @@ -0,0 +1,22 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateEditRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=input" }) + input?: string; + + @SpeakeasyMetadata({ data: "json, name=instruction" }) + instruction: string; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: any; + + @SpeakeasyMetadata({ data: "json, name=n" }) + n?: number; + + @SpeakeasyMetadata({ data: "json, name=temperature" }) + temperature?: number; + + @SpeakeasyMetadata({ data: "json, name=top_p" }) + topP?: number; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createeditresponse.ts b/src/sdk/models/shared/createeditresponse.ts new file mode 100755 index 0000000..254bcab --- /dev/null +++ b/src/sdk/models/shared/createeditresponse.ts @@ -0,0 +1,55 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateEditResponseChoicesLogprobs extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=text_offset" }) + textOffset?: number[]; + + @SpeakeasyMetadata({ data: "json, name=token_logprobs" }) + tokenLogprobs?: number[]; + + @SpeakeasyMetadata({ data: "json, name=tokens" }) + tokens?: string[]; + + @SpeakeasyMetadata({ data: "json, name=top_logprobs" }) + topLogprobs?: Record[]; +} + +export class CreateEditResponseChoices extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=finish_reason" }) + finishReason?: string; + + @SpeakeasyMetadata({ data: "json, name=index" }) + index?: number; + + @SpeakeasyMetadata({ data: "json, name=logprobs" }) + logprobs?: CreateEditResponseChoicesLogprobs; + + @SpeakeasyMetadata({ data: "json, name=text" }) + text?: string; +} + +export class CreateEditResponseUsage extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=completion_tokens" }) + completionTokens: number; + + @SpeakeasyMetadata({ data: "json, name=prompt_tokens" }) + promptTokens: number; + + @SpeakeasyMetadata({ data: "json, name=total_tokens" }) + totalTokens: number; +} + +export class CreateEditResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=choices", elemType: CreateEditResponseChoices }) + choices: CreateEditResponseChoices[]; + + @SpeakeasyMetadata({ data: "json, name=created" }) + created: number; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; + + @SpeakeasyMetadata({ data: "json, name=usage" }) + usage: CreateEditResponseUsage; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createembeddingrequest.ts b/src/sdk/models/shared/createembeddingrequest.ts new file mode 100755 index 0000000..55664bd --- /dev/null +++ b/src/sdk/models/shared/createembeddingrequest.ts @@ -0,0 +1,13 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateEmbeddingRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=input" }) + input: any; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: any; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createembeddingresponse.ts b/src/sdk/models/shared/createembeddingresponse.ts new file mode 100755 index 0000000..3b948c4 --- /dev/null +++ b/src/sdk/models/shared/createembeddingresponse.ts @@ -0,0 +1,35 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateEmbeddingResponseData extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=embedding" }) + embedding: number[]; + + @SpeakeasyMetadata({ data: "json, name=index" }) + index: number; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} + +export class CreateEmbeddingResponseUsage extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=prompt_tokens" }) + promptTokens: number; + + @SpeakeasyMetadata({ data: "json, name=total_tokens" }) + totalTokens: number; +} + +export class CreateEmbeddingResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data", elemType: CreateEmbeddingResponseData }) + data: CreateEmbeddingResponseData[]; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; + + @SpeakeasyMetadata({ data: "json, name=usage" }) + usage: CreateEmbeddingResponseUsage; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createfilerequest.ts b/src/sdk/models/shared/createfilerequest.ts new file mode 100755 index 0000000..b45f1f0 --- /dev/null +++ b/src/sdk/models/shared/createfilerequest.ts @@ -0,0 +1,18 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateFileRequestFile extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, content=true" }) + content: Uint8Array; + + @SpeakeasyMetadata({ data: "multipart_form, name=file" }) + file: string; +} + +export class CreateFileRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, file=true" }) + file: CreateFileRequestFile; + + @SpeakeasyMetadata({ data: "multipart_form, name=purpose" }) + purpose: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createfinetunerequest.ts b/src/sdk/models/shared/createfinetunerequest.ts new file mode 100755 index 0000000..608433d --- /dev/null +++ b/src/sdk/models/shared/createfinetunerequest.ts @@ -0,0 +1,40 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateFineTuneRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=batch_size" }) + batchSize?: number; + + @SpeakeasyMetadata({ data: "json, name=classification_betas" }) + classificationBetas?: number[]; + + @SpeakeasyMetadata({ data: "json, name=classification_n_classes" }) + classificationNClasses?: number; + + @SpeakeasyMetadata({ data: "json, name=classification_positive_class" }) + classificationPositiveClass?: string; + + @SpeakeasyMetadata({ data: "json, name=compute_classification_metrics" }) + computeClassificationMetrics?: boolean; + + @SpeakeasyMetadata({ data: "json, name=learning_rate_multiplier" }) + learningRateMultiplier?: number; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model?: string; + + @SpeakeasyMetadata({ data: "json, name=n_epochs" }) + nEpochs?: number; + + @SpeakeasyMetadata({ data: "json, name=prompt_loss_weight" }) + promptLossWeight?: number; + + @SpeakeasyMetadata({ data: "json, name=suffix" }) + suffix?: string; + + @SpeakeasyMetadata({ data: "json, name=training_file" }) + trainingFile: string; + + @SpeakeasyMetadata({ data: "json, name=validation_file" }) + validationFile?: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createimageeditrequest.ts b/src/sdk/models/shared/createimageeditrequest.ts new file mode 100755 index 0000000..d16d3fc --- /dev/null +++ b/src/sdk/models/shared/createimageeditrequest.ts @@ -0,0 +1,41 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateImageEditRequestImage extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, content=true" }) + content: Uint8Array; + + @SpeakeasyMetadata({ data: "multipart_form, name=image" }) + image: string; +} + +export class CreateImageEditRequestMask extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, content=true" }) + content: Uint8Array; + + @SpeakeasyMetadata({ data: "multipart_form, name=mask" }) + mask: string; +} + +export class CreateImageEditRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, file=true" }) + image: CreateImageEditRequestImage; + + @SpeakeasyMetadata({ data: "multipart_form, file=true" }) + mask?: CreateImageEditRequestMask; + + @SpeakeasyMetadata({ data: "multipart_form, name=n" }) + n?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=prompt" }) + prompt: string; + + @SpeakeasyMetadata({ data: "multipart_form, name=response_format" }) + responseFormat?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=size" }) + size?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createimagerequest.ts b/src/sdk/models/shared/createimagerequest.ts new file mode 100755 index 0000000..f9f93c5 --- /dev/null +++ b/src/sdk/models/shared/createimagerequest.ts @@ -0,0 +1,28 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + +export enum CreateImageRequestResponseFormatEnum { + Url = "url", + B64Json = "b64_json" +} +export enum CreateImageRequestSizeEnum { + TwoHundredAndFiftySixx256 = "256x256", + FiveHundredAndTwelvex512 = "512x512", + OneThousandAndTwentyFourx1024 = "1024x1024" +} + +export class CreateImageRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=n" }) + n?: number; + + @SpeakeasyMetadata({ data: "json, name=prompt" }) + prompt: string; + + @SpeakeasyMetadata({ data: "json, name=response_format" }) + responseFormat?: CreateImageRequestResponseFormatEnum; + + @SpeakeasyMetadata({ data: "json, name=size" }) + size?: CreateImageRequestSizeEnum; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createimagevariationrequest.ts b/src/sdk/models/shared/createimagevariationrequest.ts new file mode 100755 index 0000000..e93bc99 --- /dev/null +++ b/src/sdk/models/shared/createimagevariationrequest.ts @@ -0,0 +1,27 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateImageVariationRequestImage extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, content=true" }) + content: Uint8Array; + + @SpeakeasyMetadata({ data: "multipart_form, name=image" }) + image: string; +} + +export class CreateImageVariationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "multipart_form, file=true" }) + image: CreateImageVariationRequestImage; + + @SpeakeasyMetadata({ data: "multipart_form, name=n" }) + n?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=response_format" }) + responseFormat?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=size" }) + size?: any; + + @SpeakeasyMetadata({ data: "multipart_form, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createmoderationrequest.ts b/src/sdk/models/shared/createmoderationrequest.ts new file mode 100755 index 0000000..150ccdc --- /dev/null +++ b/src/sdk/models/shared/createmoderationrequest.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateModerationRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=input" }) + input: any; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model?: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createmoderationresponse.ts b/src/sdk/models/shared/createmoderationresponse.ts new file mode 100755 index 0000000..5fd8174 --- /dev/null +++ b/src/sdk/models/shared/createmoderationresponse.ts @@ -0,0 +1,70 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateModerationResponseResultsCategories extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=hate" }) + hate: boolean; + + @SpeakeasyMetadata({ data: "json, name=hate/threatening" }) + hateThreatening: boolean; + + @SpeakeasyMetadata({ data: "json, name=self-harm" }) + selfHarm: boolean; + + @SpeakeasyMetadata({ data: "json, name=sexual" }) + sexual: boolean; + + @SpeakeasyMetadata({ data: "json, name=sexual/minors" }) + sexualMinors: boolean; + + @SpeakeasyMetadata({ data: "json, name=violence" }) + violence: boolean; + + @SpeakeasyMetadata({ data: "json, name=violence/graphic" }) + violenceGraphic: boolean; +} + +export class CreateModerationResponseResultsCategoryScores extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=hate" }) + hate: number; + + @SpeakeasyMetadata({ data: "json, name=hate/threatening" }) + hateThreatening: number; + + @SpeakeasyMetadata({ data: "json, name=self-harm" }) + selfHarm: number; + + @SpeakeasyMetadata({ data: "json, name=sexual" }) + sexual: number; + + @SpeakeasyMetadata({ data: "json, name=sexual/minors" }) + sexualMinors: number; + + @SpeakeasyMetadata({ data: "json, name=violence" }) + violence: number; + + @SpeakeasyMetadata({ data: "json, name=violence/graphic" }) + violenceGraphic: number; +} + +export class CreateModerationResponseResults extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=categories" }) + categories: CreateModerationResponseResultsCategories; + + @SpeakeasyMetadata({ data: "json, name=category_scores" }) + categoryScores: CreateModerationResponseResultsCategoryScores; + + @SpeakeasyMetadata({ data: "json, name=flagged" }) + flagged: boolean; +} + +export class CreateModerationResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=id" }) + id: string; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model: string; + + @SpeakeasyMetadata({ data: "json, name=results", elemType: CreateModerationResponseResults }) + results: CreateModerationResponseResults[]; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createsearchrequest.ts b/src/sdk/models/shared/createsearchrequest.ts new file mode 100755 index 0000000..3b79f1c --- /dev/null +++ b/src/sdk/models/shared/createsearchrequest.ts @@ -0,0 +1,22 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateSearchRequest extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=documents" }) + documents?: string[]; + + @SpeakeasyMetadata({ data: "json, name=file" }) + file?: string; + + @SpeakeasyMetadata({ data: "json, name=max_rerank" }) + maxRerank?: number; + + @SpeakeasyMetadata({ data: "json, name=query" }) + query: string; + + @SpeakeasyMetadata({ data: "json, name=return_metadata" }) + returnMetadata?: boolean; + + @SpeakeasyMetadata({ data: "json, name=user" }) + user?: any; +} \ No newline at end of file diff --git a/src/sdk/models/shared/createsearchresponse.ts b/src/sdk/models/shared/createsearchresponse.ts new file mode 100755 index 0000000..44327cd --- /dev/null +++ b/src/sdk/models/shared/createsearchresponse.ts @@ -0,0 +1,24 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class CreateSearchResponseData extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=document" }) + document?: number; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object?: string; + + @SpeakeasyMetadata({ data: "json, name=score" }) + score?: number; +} + +export class CreateSearchResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data", elemType: CreateSearchResponseData }) + data?: CreateSearchResponseData[]; + + @SpeakeasyMetadata({ data: "json, name=model" }) + model?: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object?: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/deletefileresponse.ts b/src/sdk/models/shared/deletefileresponse.ts new file mode 100755 index 0000000..022fc08 --- /dev/null +++ b/src/sdk/models/shared/deletefileresponse.ts @@ -0,0 +1,13 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class DeleteFileResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=deleted" }) + deleted: boolean; + + @SpeakeasyMetadata({ data: "json, name=id" }) + id: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/deletemodelresponse.ts b/src/sdk/models/shared/deletemodelresponse.ts new file mode 100755 index 0000000..8209c86 --- /dev/null +++ b/src/sdk/models/shared/deletemodelresponse.ts @@ -0,0 +1,13 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class DeleteModelResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=deleted" }) + deleted: boolean; + + @SpeakeasyMetadata({ data: "json, name=id" }) + id: string; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/index.ts b/src/sdk/models/shared/index.ts new file mode 100755 index 0000000..728b5e5 --- /dev/null +++ b/src/sdk/models/shared/index.ts @@ -0,0 +1,26 @@ +export * from "./createanswerrequest"; +export * from "./createanswerresponse"; +export * from "./createclassificationrequest"; +export * from "./createclassificationresponse"; +export * from "./createcompletionrequest"; +export * from "./createcompletionresponse"; +export * from "./createeditrequest"; +export * from "./createeditresponse"; +export * from "./createembeddingrequest"; +export * from "./createembeddingresponse"; +export * from "./createfilerequest"; +export * from "./createfinetunerequest"; +export * from "./createimageeditrequest"; +export * from "./createimagerequest"; +export * from "./createimagevariationrequest"; +export * from "./createmoderationrequest"; +export * from "./createmoderationresponse"; +export * from "./createsearchrequest"; +export * from "./createsearchresponse"; +export * from "./deletefileresponse"; +export * from "./deletemodelresponse"; +export * from "./listenginesresponse"; +export * from "./listfilesresponse"; +export * from "./listfinetuneeventsresponse"; +export * from "./listfinetunesresponse"; +export * from "./listmodelsresponse"; diff --git a/src/sdk/models/shared/listenginesresponse.ts b/src/sdk/models/shared/listenginesresponse.ts new file mode 100755 index 0000000..34354a3 --- /dev/null +++ b/src/sdk/models/shared/listenginesresponse.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class ListEnginesResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data" }) + data: any[]; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/listfilesresponse.ts b/src/sdk/models/shared/listfilesresponse.ts new file mode 100755 index 0000000..2eee6a6 --- /dev/null +++ b/src/sdk/models/shared/listfilesresponse.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class ListFilesResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data" }) + data: any[]; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/listfinetuneeventsresponse.ts b/src/sdk/models/shared/listfinetuneeventsresponse.ts new file mode 100755 index 0000000..9c57390 --- /dev/null +++ b/src/sdk/models/shared/listfinetuneeventsresponse.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class ListFineTuneEventsResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data" }) + data: any[]; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/listfinetunesresponse.ts b/src/sdk/models/shared/listfinetunesresponse.ts new file mode 100755 index 0000000..1fa4687 --- /dev/null +++ b/src/sdk/models/shared/listfinetunesresponse.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class ListFineTunesResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data" }) + data: any[]; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/models/shared/listmodelsresponse.ts b/src/sdk/models/shared/listmodelsresponse.ts new file mode 100755 index 0000000..94575c8 --- /dev/null +++ b/src/sdk/models/shared/listmodelsresponse.ts @@ -0,0 +1,10 @@ +import { SpeakeasyBase, SpeakeasyMetadata } from "../../../internal/utils"; + + +export class ListModelsResponse extends SpeakeasyBase { + @SpeakeasyMetadata({ data: "json, name=data" }) + data: any[]; + + @SpeakeasyMetadata({ data: "json, name=object" }) + object: string; +} \ No newline at end of file diff --git a/src/sdk/openai.ts b/src/sdk/openai.ts new file mode 100755 index 0000000..e6c7584 --- /dev/null +++ b/src/sdk/openai.ts @@ -0,0 +1,1206 @@ +import * as utils from "../internal/utils"; +import * as operations from "./models/operations"; +import { AxiosInstance, AxiosRequestConfig, AxiosResponse, ParamsSerializerOptions } from "axios"; + +export class OpenAI { + _defaultClient: AxiosInstance; + _securityClient: AxiosInstance; + _serverURL: string; + _language: string; + _sdkVersion: string; + _genVersion: string; + + constructor(defaultClient: AxiosInstance, securityClient: AxiosInstance, serverURL: string, language: string, sdkVersion: string, genVersion: string) { + this._defaultClient = defaultClient; + this._securityClient = securityClient; + this._serverURL = serverURL; + this._language = language; + this._sdkVersion = sdkVersion; + this._genVersion = genVersion; + } + + /** + * cancelFineTune - Immediately cancel a fine-tune job. + * + **/ + cancelFineTune( + req: operations.CancelFineTuneRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CancelFineTuneRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/fine-tunes/{fine_tune_id}/cancel", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "post", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CancelFineTuneResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.fineTune = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createAnswer - Answers the specified question using the provided documents and examples. + * + * The endpoint first [searches](/docs/api-reference/searches) over provided documents or files to find relevant context. The relevant context is combined with the provided examples and question to create the prompt for [completion](/docs/api-reference/completions). + * + **/ + createAnswer( + req: operations.CreateAnswerRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateAnswerRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/answers"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateAnswerResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createAnswerResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createClassification - Classifies the specified `query` using provided examples. + * + * The endpoint first [searches](/docs/api-reference/searches) over the labeled examples + * to select the ones most relevant for the particular query. Then, the relevant examples + * are combined with the query to construct a prompt to produce the final label via the + * [completions](/docs/api-reference/completions) endpoint. + * + * Labeled examples can be provided via an uploaded `file`, or explicitly listed in the + * request using the `examples` parameter for quick tests and small scale use cases. + * + **/ + createClassification( + req: operations.CreateClassificationRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateClassificationRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/classifications"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateClassificationResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createClassificationResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createCompletion - Creates a completion for the provided prompt and parameters + **/ + createCompletion( + req: operations.CreateCompletionRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateCompletionRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/completions"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateCompletionResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createCompletionResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createEdit - Creates a new edit for the provided input, instruction, and parameters + **/ + createEdit( + req: operations.CreateEditRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateEditRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/edits"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateEditResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createEditResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createEmbedding - Creates an embedding vector representing the input text. + **/ + createEmbedding( + req: operations.CreateEmbeddingRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateEmbeddingRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/embeddings"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateEmbeddingResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createEmbeddingResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createFile - Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. + * + **/ + createFile( + req: operations.CreateFileRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateFileRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/files"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateFileResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.openAIFile = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createFineTune - Creates a job that fine-tunes a specified model from a given dataset. + * + * Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. + * + * [Learn more about Fine-tuning](/docs/guides/fine-tuning) + * + **/ + createFineTune( + req: operations.CreateFineTuneRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateFineTuneRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/fine-tunes"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateFineTuneResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.fineTune = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createImage - Creates an image given a prompt. + **/ + createImage( + req: operations.CreateImageRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateImageRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/images/generations"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateImageResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.imagesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createImageEdit - Creates an edited or extended image given an original image and a prompt. + **/ + createImageEdit( + req: operations.CreateImageEditRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateImageEditRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/images/edits"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateImageEditResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.imagesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createImageVariation - Creates a variation of a given image. + **/ + createImageVariation( + req: operations.CreateImageVariationRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateImageVariationRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/images/variations"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateImageVariationResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.imagesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createModeration - Classifies if text violates OpenAI's Content Policy + **/ + createModeration( + req: operations.CreateModerationRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateModerationRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/moderations"; + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateModerationResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createModerationResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * createSearch - The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. + * + * To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time. When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents. These documents will be returned along with their search scores. + * + * The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query. + * + **/ + createSearch( + req: operations.CreateSearchRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.CreateSearchRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/engines/{engine_id}/search", req.pathParams); + + let [reqBodyHeaders, reqBody]: [object, any] = [{}, {}]; + + try { + [reqBodyHeaders, reqBody] = utils.serializeRequestBody(req); + } catch (e: unknown) { + if (e instanceof Error) { + throw new Error(`Error serializing request body, cause: ${e.message}`); + } + } + + const client: AxiosInstance = this._defaultClient!; + const headers = {...reqBodyHeaders, ...config?.headers}; + if (reqBody == null || Object.keys(reqBody).length === 0) throw new Error("request body is required"); + + const r = client.request({ + url: url, + method: "post", + headers: headers, + data: reqBody, + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.CreateSearchResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.createSearchResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * deleteFile - Delete a file. + **/ + deleteFile( + req: operations.DeleteFileRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.DeleteFileRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/files/{file_id}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "delete", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.DeleteFileResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.deleteFileResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * deleteModel - Delete a fine-tuned model. You must have the Owner role in your organization. + **/ + deleteModel( + req: operations.DeleteModelRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.DeleteModelRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/models/{model}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "delete", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.DeleteModelResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.deleteModelResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * downloadFile - Returns the contents of the specified file + **/ + downloadFile( + req: operations.DownloadFileRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.DownloadFileRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/files/{file_id}/content", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.DownloadFileResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.downloadFile200ApplicationJSONString = JSON.stringify(httpRes?.data); + } + break; + } + + return res; + }) + } + + + /** + * listEngines - Lists the currently available (non-finetuned) models, and provides basic information about each one such as the owner and availability. + **/ + listEngines( + config?: AxiosRequestConfig + ): Promise { + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/engines"; + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.ListEnginesResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.listEnginesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * listFiles - Returns a list of files that belong to the user's organization. + **/ + listFiles( + config?: AxiosRequestConfig + ): Promise { + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/files"; + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.ListFilesResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.listFilesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * listFineTuneEvents - Get fine-grained status updates for a fine-tune job. + * + **/ + listFineTuneEvents( + req: operations.ListFineTuneEventsRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.ListFineTuneEventsRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/fine-tunes/{fine_tune_id}/events", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + const qpSerializer: ParamsSerializerOptions = utils.getQueryParamSerializer(req.queryParams); + + const requestConfig: AxiosRequestConfig = { + ...config, + params: req.queryParams, + paramsSerializer: qpSerializer, + }; + + + const r = client.request({ + url: url, + method: "get", + ...requestConfig, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.ListFineTuneEventsResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.listFineTuneEventsResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * listFineTunes - List your organization's fine-tuning jobs + * + **/ + listFineTunes( + config?: AxiosRequestConfig + ): Promise { + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/fine-tunes"; + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.ListFineTunesResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.listFineTunesResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * listModels - Lists the currently available models, and provides basic information about each one such as the owner and availability. + **/ + listModels( + config?: AxiosRequestConfig + ): Promise { + const baseURL: string = this._serverURL; + const url: string = baseURL.replace(/\/$/, "") + "/models"; + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.ListModelsResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.listModelsResponse = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * retrieveEngine - Retrieves a model instance, providing basic information about it such as the owner and availability. + **/ + retrieveEngine( + req: operations.RetrieveEngineRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.RetrieveEngineRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/engines/{engine_id}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.RetrieveEngineResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.engine = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * retrieveFile - Returns information about a specific file. + **/ + retrieveFile( + req: operations.RetrieveFileRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.RetrieveFileRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/files/{file_id}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.RetrieveFileResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.openAIFile = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * retrieveFineTune - Gets info about the fine-tune job. + * + * [Learn more about Fine-tuning](/docs/guides/fine-tuning) + * + **/ + retrieveFineTune( + req: operations.RetrieveFineTuneRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.RetrieveFineTuneRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/fine-tunes/{fine_tune_id}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.RetrieveFineTuneResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.fineTune = httpRes?.data; + } + break; + } + + return res; + }) + } + + + /** + * retrieveModel - Retrieves a model instance, providing basic information about the model such as the owner and permissioning. + **/ + retrieveModel( + req: operations.RetrieveModelRequest, + config?: AxiosRequestConfig + ): Promise { + if (!(req instanceof utils.SpeakeasyBase)) { + req = new operations.RetrieveModelRequest(req); + } + + const baseURL: string = this._serverURL; + const url: string = utils.generateURL(baseURL, "/models/{model}", req.pathParams); + + const client: AxiosInstance = this._defaultClient!; + + const r = client.request({ + url: url, + method: "get", + ...config, + }); + + return r.then((httpRes: AxiosResponse) => { + const contentType: string = httpRes?.headers?.["content-type"] ?? ""; + + if (httpRes?.status == null) throw new Error(`status code not found in response: ${httpRes}`); + const res: operations.RetrieveModelResponse = {statusCode: httpRes.status, contentType: contentType}; + switch (true) { + case httpRes?.status == 200: + if (utils.matchContentType(contentType, `application/json`)) { + res.model = httpRes?.data; + } + break; + } + + return res; + }) + } + +} diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts new file mode 100755 index 0000000..fc2c5ad --- /dev/null +++ b/src/sdk/sdk.ts @@ -0,0 +1,43 @@ +import { OpenAI } from "./openai"; +import axios, { AxiosInstance } from "axios"; + +export const ServerList = [ + "https://api.openai.com/v1", +] as const; + + + +export type SDKProps = { + defaultClient?: AxiosInstance; + + serverUrl?: string; +} + + +export class Openai { + public openAI: OpenAI; + + public _defaultClient: AxiosInstance; + public _securityClient: AxiosInstance; + public _serverURL: string; + private _language = "typescript"; + private _sdkVersion = "1.2.0"; + private _genVersion = "1.4.7"; + + constructor(props: SDKProps) { + this._serverURL = props.serverUrl ?? ServerList[0]; + + this._defaultClient = props.defaultClient ?? axios.create({ baseURL: this._serverURL }); + this._securityClient = this._defaultClient; + + this.openAI = new OpenAI( + this._defaultClient, + this._securityClient, + this._serverURL, + this._language, + this._sdkVersion, + this._genVersion + ); + } + +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100755 index 0000000..df095a3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "es2021", + ], + "baseUrl": "src", + "rootDir": "src", + "outDir": "dist", + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "strictPropertyInitialization": false, + "declaration": true, + "types": [ + "reflect-metadata" + ] + }, + "include": [ + "src" + ] +}