From 8e3a40c2159f731cc88c9dd1cca6a41cbf8a778d Mon Sep 17 00:00:00 2001 From: Ido Berkovich Date: Wed, 4 Dec 2024 16:27:15 +0200 Subject: [PATCH] OPIK-523 add OpenAPI spec and update relevant clients (#810) --- .../documentation/rest_api/opik.yaml | 15 +++ .../code_generation/fern/openapi/openapi.yaml | 15 +++ .../src/opik/rest_api/prompts/client.py | 100 ++++++++++++++++++ .../api/resources/prompts/client/Client.d.ts | 12 +++ .../api/resources/prompts/client/Client.js | 53 ++++++++++ 5 files changed, 195 insertions(+) diff --git a/apps/opik-documentation/documentation/rest_api/opik.yaml b/apps/opik-documentation/documentation/rest_api/opik.yaml index 35f487fdb6..1ab4a505a2 100644 --- a/apps/opik-documentation/documentation/rest_api/opik.yaml +++ b/apps/opik-documentation/documentation/rest_api/opik.yaml @@ -1254,6 +1254,21 @@ paths: responses: "204": description: No content + /v1/private/prompts/delete: + post: + tags: + - Prompts + summary: Delete prompts + description: Delete prompts batch + operationId: deletePromptsBatch + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BatchDelete' + responses: + "204": + description: No Content /v1/private/prompts/versions/{versionId}: get: tags: diff --git a/sdks/code_generation/fern/openapi/openapi.yaml b/sdks/code_generation/fern/openapi/openapi.yaml index 35f487fdb6..1ab4a505a2 100644 --- a/sdks/code_generation/fern/openapi/openapi.yaml +++ b/sdks/code_generation/fern/openapi/openapi.yaml @@ -1254,6 +1254,21 @@ paths: responses: "204": description: No content + /v1/private/prompts/delete: + post: + tags: + - Prompts + summary: Delete prompts + description: Delete prompts batch + operationId: deletePromptsBatch + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/BatchDelete' + responses: + "204": + description: No Content /v1/private/prompts/versions/{versionId}: get: tags: diff --git a/sdks/python/src/opik/rest_api/prompts/client.py b/sdks/python/src/opik/rest_api/prompts/client.py index b6ebe340ac..3cb96d482f 100644 --- a/sdks/python/src/opik/rest_api/prompts/client.py +++ b/sdks/python/src/opik/rest_api/prompts/client.py @@ -462,6 +462,52 @@ def delete_prompt( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def delete_prompts_batch( + self, + *, + ids: typing.Sequence[str], + request_options: typing.Optional[RequestOptions] = None, + ) -> None: + """ + Delete prompts batch + + Parameters + ---------- + ids : typing.Sequence[str] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + None + + Examples + -------- + from Opik import OpikApi + + client = OpikApi() + client.prompts.delete_prompts_batch( + ids=["ids"], + ) + """ + _response = self._client_wrapper.httpx_client.request( + "v1/private/prompts/delete", + method="POST", + json={ + "ids": ids, + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + return + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def get_prompt_version_by_id( self, version_id: str, @@ -1159,6 +1205,60 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def delete_prompts_batch( + self, + *, + ids: typing.Sequence[str], + request_options: typing.Optional[RequestOptions] = None, + ) -> None: + """ + Delete prompts batch + + Parameters + ---------- + ids : typing.Sequence[str] + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + None + + Examples + -------- + import asyncio + + from Opik import AsyncOpikApi + + client = AsyncOpikApi() + + + async def main() -> None: + await client.prompts.delete_prompts_batch( + ids=["ids"], + ) + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "v1/private/prompts/delete", + method="POST", + json={ + "ids": ids, + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + return + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def get_prompt_version_by_id( self, version_id: str, diff --git a/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.d.ts b/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.d.ts index 5d8319b7aa..c703a60d0e 100644 --- a/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.d.ts +++ b/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.d.ts @@ -110,6 +110,18 @@ export declare class Prompts { * await client.prompts.deletePrompt("id") */ deletePrompt(id: string, requestOptions?: Prompts.RequestOptions): core.APIPromise; + /** + * Delete prompts batch + * + * @param {OpikApi.BatchDelete} request + * @param {Prompts.RequestOptions} requestOptions - Request-specific configuration. + * + * @example + * await client.prompts.deletePromptsBatch({ + * ids: ["ids"] + * }) + */ + deletePromptsBatch(request: OpikApi.BatchDelete, requestOptions?: Prompts.RequestOptions): core.APIPromise; /** * Get prompt version by id * diff --git a/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.js b/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.js index b5baef59de..2059676ae2 100644 --- a/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.js +++ b/sdks/typescript/src/opik/rest_api/api/resources/prompts/client/Client.js @@ -443,6 +443,59 @@ class Prompts { } }))()); } + /** + * Delete prompts batch + * + * @param {OpikApi.BatchDelete} request + * @param {Prompts.RequestOptions} requestOptions - Request-specific configuration. + * + * @example + * await client.prompts.deletePromptsBatch({ + * ids: ["ids"] + * }) + */ + deletePromptsBatch(request, requestOptions) { + return core.APIPromise.from((() => __awaiter(this, void 0, void 0, function* () { + var _a; + const _response = yield core.fetcher({ + url: (0, url_join_1.default)((_a = (yield core.Supplier.get(this._options.environment))) !== null && _a !== void 0 ? _a : environments.OpikApiEnvironment.Default, "v1/private/prompts/delete"), + method: "POST", + headers: Object.assign({ "X-Fern-Language": "JavaScript", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version }, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers), + contentType: "application/json", + requestType: "json", + body: serializers.BatchDelete.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), + timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries, + abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal, + }); + if (_response.ok) { + return { + ok: _response.ok, + body: undefined, + headers: _response.headers, + }; + } + if (_response.error.reason === "status-code") { + throw new errors.OpikApiError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + switch (_response.error.reason) { + case "non-json": + throw new errors.OpikApiError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.OpikApiTimeoutError("Timeout exceeded when calling POST /v1/private/prompts/delete."); + case "unknown": + throw new errors.OpikApiError({ + message: _response.error.errorMessage, + }); + } + }))()); + } /** * Get prompt version by id *