diff --git a/apps/opik-documentation/documentation/rest_api/opik.yaml b/apps/opik-documentation/documentation/rest_api/opik.yaml index 9a0ace8523..131767c870 100644 --- a/apps/opik-documentation/documentation/rest_api/opik.yaml +++ b/apps/opik-documentation/documentation/rest_api/opik.yaml @@ -691,6 +691,31 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorMessage_Public' + /v1/private/experiments/retrieve: + post: + tags: + - Experiments + summary: Get experiment by name + description: Get experiment by name + operationId: getExperimentByName + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Identifier_Public' + responses: + "200": + description: Experiments resource + content: + application/json: + schema: + $ref: '#/components/schemas/Experiment_Public' + "404": + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage_Public' /v1/private/experiments/items/{id}: get: tags: @@ -3351,6 +3376,13 @@ components: type: array items: type: string + Identifier_Public: + required: + - name + type: object + properties: + name: + type: string ExperimentItemStreamRequest: required: - experiment_name diff --git a/sdks/code_generation/fern/openapi/openapi.yaml b/sdks/code_generation/fern/openapi/openapi.yaml index 9a0ace8523..131767c870 100644 --- a/sdks/code_generation/fern/openapi/openapi.yaml +++ b/sdks/code_generation/fern/openapi/openapi.yaml @@ -691,6 +691,31 @@ paths: application/json: schema: $ref: '#/components/schemas/ErrorMessage_Public' + /v1/private/experiments/retrieve: + post: + tags: + - Experiments + summary: Get experiment by name + description: Get experiment by name + operationId: getExperimentByName + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Identifier_Public' + responses: + "200": + description: Experiments resource + content: + application/json: + schema: + $ref: '#/components/schemas/Experiment_Public' + "404": + description: Not found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorMessage_Public' /v1/private/experiments/items/{id}: get: tags: @@ -3351,6 +3376,13 @@ components: type: array items: type: string + Identifier_Public: + required: + - name + type: object + properties: + name: + type: string ExperimentItemStreamRequest: required: - experiment_name diff --git a/sdks/python/src/opik/rest_api/experiments/client.py b/sdks/python/src/opik/rest_api/experiments/client.py index 55d426cd9d..1882598d42 100644 --- a/sdks/python/src/opik/rest_api/experiments/client.py +++ b/sdks/python/src/opik/rest_api/experiments/client.py @@ -427,6 +427,69 @@ def get_experiment_by_id( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def get_experiment_by_name( + self, *, name: str, request_options: typing.Optional[RequestOptions] = None + ) -> ExperimentPublic: + """ + Get experiment by name + + Parameters + ---------- + name : str + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ExperimentPublic + Experiments resource + + Examples + -------- + from Opik import OpikApi + + client = OpikApi() + client.experiments.get_experiment_by_name( + name="name", + ) + """ + _response = self._client_wrapper.httpx_client.request( + "v1/private/experiments/retrieve", + method="POST", + json={ + "name": name, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + ExperimentPublic, + parse_obj_as( + type_=ExperimentPublic, # type: ignore + object_=_response.json(), + ), + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) + _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_experiment_item_by_id( self, id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> ExperimentItemPublic: @@ -1003,6 +1066,77 @@ 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 get_experiment_by_name( + self, *, name: str, request_options: typing.Optional[RequestOptions] = None + ) -> ExperimentPublic: + """ + Get experiment by name + + Parameters + ---------- + name : str + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ExperimentPublic + Experiments resource + + Examples + -------- + import asyncio + + from Opik import AsyncOpikApi + + client = AsyncOpikApi() + + + async def main() -> None: + await client.experiments.get_experiment_by_name( + name="name", + ) + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "v1/private/experiments/retrieve", + method="POST", + json={ + "name": name, + }, + headers={ + "content-type": "application/json", + }, + request_options=request_options, + omit=OMIT, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + ExperimentPublic, + parse_obj_as( + type_=ExperimentPublic, # type: ignore + object_=_response.json(), + ), + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast( + typing.Optional[typing.Any], + parse_obj_as( + type_=typing.Optional[typing.Any], # type: ignore + object_=_response.json(), + ), + ) + ) + _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_experiment_item_by_id( self, id: str, *, request_options: typing.Optional[RequestOptions] = None ) -> ExperimentItemPublic: diff --git a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.d.ts b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.d.ts index b05a7ed70d..c37021a94a 100644 --- a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.d.ts +++ b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.d.ts @@ -111,6 +111,20 @@ export declare class Experiments { * await client.experiments.getExperimentById("id") */ getExperimentById(id: string, requestOptions?: Experiments.RequestOptions): core.APIPromise; + /** + * Get experiment by name + * + * @param {OpikApi.IdentifierPublic} request + * @param {Experiments.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link OpikApi.NotFoundError} + * + * @example + * await client.experiments.getExperimentByName({ + * name: "name" + * }) + */ + getExperimentByName(request: OpikApi.IdentifierPublic, requestOptions?: Experiments.RequestOptions): core.APIPromise; /** * Get experiment item by id * diff --git a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.js b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.js index 9dee6aafe3..30a7631679 100644 --- a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.js +++ b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/Client.js @@ -467,6 +467,71 @@ class Experiments { } }))()); } + /** + * Get experiment by name + * + * @param {OpikApi.IdentifierPublic} request + * @param {Experiments.RequestOptions} requestOptions - Request-specific configuration. + * + * @throws {@link OpikApi.NotFoundError} + * + * @example + * await client.experiments.getExperimentByName({ + * name: "name" + * }) + */ + getExperimentByName(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/experiments/retrieve"), + 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.IdentifierPublic.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: serializers.ExperimentPublic.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }), + headers: _response.headers, + }; + } + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 404: + throw new OpikApi.NotFoundError(_response.error.body); + default: + 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/experiments/retrieve."); + case "unknown": + throw new errors.OpikApiError({ + message: _response.error.errorMessage, + }); + } + }))()); + } /** * Get experiment item by id * diff --git a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.d.ts b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.d.ts new file mode 100644 index 0000000000..d8ea0d0e3e --- /dev/null +++ b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.d.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +/** + * @example + * { + * name: "name" + * } + */ +export interface IdentifierPublic { + name: string; +} diff --git a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.js b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.js new file mode 100644 index 0000000000..33e43da19c --- /dev/null +++ b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/IdentifierPublic.js @@ -0,0 +1,5 @@ +"use strict"; +/** + * This file was auto-generated by Fern from our API Definition. + */ +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/index.d.ts b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/index.d.ts index 74cdea0bf2..438bfea34e 100644 --- a/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/index.d.ts +++ b/sdks/typescript/src/opik/rest_api/api/resources/experiments/client/requests/index.d.ts @@ -4,4 +4,5 @@ export { type ExperimentItemsBatch } from "./ExperimentItemsBatch"; export { type ExperimentItemsDelete } from "./ExperimentItemsDelete"; export { type ExperimentsDelete } from "./ExperimentsDelete"; export { type FindFeedbackScoreNamesRequest } from "./FindFeedbackScoreNamesRequest"; +export { type IdentifierPublic } from "./IdentifierPublic"; export { type ExperimentItemStreamRequest } from "./ExperimentItemStreamRequest"; diff --git a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.d.ts b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.d.ts new file mode 100644 index 0000000000..a3a66ab643 --- /dev/null +++ b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.d.ts @@ -0,0 +1,12 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +import * as serializers from "../../../../index"; +import * as OpikApi from "../../../../../api/index"; +import * as core from "../../../../../core"; +export declare const IdentifierPublic: core.serialization.Schema; +export declare namespace IdentifierPublic { + interface Raw { + name: string; + } +} diff --git a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.js b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.js new file mode 100644 index 0000000000..afa76f290a --- /dev/null +++ b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/IdentifierPublic.js @@ -0,0 +1,33 @@ +"use strict"; +/** + * This file was auto-generated by Fern from our API Definition. + */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.IdentifierPublic = void 0; +const core = __importStar(require("../../../../../core")); +exports.IdentifierPublic = core.serialization.object({ + name: core.serialization.string(), +}); diff --git a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.d.ts b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.d.ts index a2353913f4..43fb512edb 100644 --- a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.d.ts +++ b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.d.ts @@ -2,4 +2,5 @@ export { ExperimentWrite } from "./ExperimentWrite"; export { ExperimentItemsBatch } from "./ExperimentItemsBatch"; export { ExperimentItemsDelete } from "./ExperimentItemsDelete"; export { ExperimentsDelete } from "./ExperimentsDelete"; +export { IdentifierPublic } from "./IdentifierPublic"; export { ExperimentItemStreamRequest } from "./ExperimentItemStreamRequest"; diff --git a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.js b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.js index 3fa84a480c..f84e888516 100644 --- a/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.js +++ b/sdks/typescript/src/opik/rest_api/serialization/resources/experiments/client/requests/index.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ExperimentItemStreamRequest = exports.ExperimentsDelete = exports.ExperimentItemsDelete = exports.ExperimentItemsBatch = exports.ExperimentWrite = void 0; +exports.ExperimentItemStreamRequest = exports.IdentifierPublic = exports.ExperimentsDelete = exports.ExperimentItemsDelete = exports.ExperimentItemsBatch = exports.ExperimentWrite = void 0; var ExperimentWrite_1 = require("./ExperimentWrite"); Object.defineProperty(exports, "ExperimentWrite", { enumerable: true, get: function () { return ExperimentWrite_1.ExperimentWrite; } }); var ExperimentItemsBatch_1 = require("./ExperimentItemsBatch"); @@ -9,5 +9,7 @@ var ExperimentItemsDelete_1 = require("./ExperimentItemsDelete"); Object.defineProperty(exports, "ExperimentItemsDelete", { enumerable: true, get: function () { return ExperimentItemsDelete_1.ExperimentItemsDelete; } }); var ExperimentsDelete_1 = require("./ExperimentsDelete"); Object.defineProperty(exports, "ExperimentsDelete", { enumerable: true, get: function () { return ExperimentsDelete_1.ExperimentsDelete; } }); +var IdentifierPublic_1 = require("./IdentifierPublic"); +Object.defineProperty(exports, "IdentifierPublic", { enumerable: true, get: function () { return IdentifierPublic_1.IdentifierPublic; } }); var ExperimentItemStreamRequest_1 = require("./ExperimentItemStreamRequest"); Object.defineProperty(exports, "ExperimentItemStreamRequest", { enumerable: true, get: function () { return ExperimentItemStreamRequest_1.ExperimentItemStreamRequest; } });