Skip to content

Commit

Permalink
OPIK-582 Get experiment by name endpoint autogenerated code (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisTkachenko authored Dec 16, 2024
1 parent 956003b commit f049b81
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 1 deletion.
32 changes: 32 additions & 0 deletions apps/opik-documentation/documentation/rest_api/opik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3351,6 +3376,13 @@ components:
type: array
items:
type: string
Identifier_Public:
required:
- name
type: object
properties:
name:
type: string
ExperimentItemStreamRequest:
required:
- experiment_name
Expand Down
32 changes: 32 additions & 0 deletions sdks/code_generation/fern/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3351,6 +3376,13 @@ components:
type: array
items:
type: string
Identifier_Public:
required:
- name
type: object
properties:
name:
type: string
ExperimentItemStreamRequest:
required:
- experiment_name
Expand Down
134 changes: 134 additions & 0 deletions sdks/python/src/opik/rest_api/experiments/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ export declare class Experiments {
* await client.experiments.getExperimentById("id")
*/
getExperimentById(id: string, requestOptions?: Experiments.RequestOptions): core.APIPromise<OpikApi.ExperimentPublic>;
/**
* 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<OpikApi.ExperimentPublic>;
/**
* Get experiment item by id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
/**
* @example
* {
* name: "name"
* }
*/
export interface IdentifierPublic {
name: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
/**
* This file was auto-generated by Fern from our API Definition.
*/
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
@@ -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<serializers.IdentifierPublic.Raw, OpikApi.IdentifierPublic>;
export declare namespace IdentifierPublic {
interface Raw {
name: string;
}
}
Loading

0 comments on commit f049b81

Please sign in to comment.