-
Notifications
You must be signed in to change notification settings - Fork 2
feat(sdk): added scorer classes to sdk #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5e37a2e
94435a7
d2910e7
4194ce1
e8fdc37
c1f617e
74ca76c
c5bc7d3
e3e2c14
e37d9e1
bf11fd2
92b6130
7b68fa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,10 @@ | |
| LongRequestOptions, | ||
| SDKDevboxListParams, | ||
| SDKObjectListParams, | ||
| SDKScorerListParams, | ||
| SDKDevboxCreateParams, | ||
| SDKObjectCreateParams, | ||
| SDKScorerCreateParams, | ||
| SDKBlueprintListParams, | ||
| SDKBlueprintCreateParams, | ||
| SDKDiskSnapshotListParams, | ||
|
|
@@ -27,6 +29,7 @@ | |
| from .._client import DEFAULT_MAX_RETRIES, AsyncRunloop | ||
| from ._helpers import detect_content_type | ||
| from .async_devbox import AsyncDevbox | ||
| from .async_scorer import AsyncScorer | ||
| from .async_snapshot import AsyncSnapshot | ||
| from .async_blueprint import AsyncBlueprint | ||
| from .async_storage_object import AsyncStorageObject | ||
|
|
@@ -475,6 +478,67 @@ async def upload_from_bytes( | |
| return obj | ||
|
|
||
|
|
||
| class AsyncScorerOps: | ||
| """High-level async manager for creating and managing scenario scorers. | ||
|
|
||
| Accessed via ``runloop.scorer`` from :class:`AsyncRunloopSDK`, provides | ||
| coroutines to create, list, and access scorers. | ||
|
|
||
| Example: | ||
| >>> runloop = AsyncRunloopSDK() | ||
| >>> scorer = await runloop.scorer.create(type="my_scorer", bash_script="echo 'score=1.0'") | ||
| >>> scorers = await runloop.scorer.list() | ||
| """ | ||
|
|
||
| def __init__(self, client: AsyncRunloop) -> None: | ||
| """Initialize the manager. | ||
|
|
||
| :param client: Generated AsyncRunloop client to wrap | ||
| :type client: AsyncRunloop | ||
| """ | ||
| self._client = client | ||
|
|
||
| async def create( | ||
| self, | ||
| **params: Unpack[SDKScorerCreateParams], | ||
| ) -> AsyncScorer: | ||
| """Create a new scenario scorer. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters | ||
| :return: Wrapper bound to the newly created scorer | ||
|
||
| :rtype: AsyncScorer | ||
| """ | ||
| response = await self._client.scenarios.scorers.create( | ||
| **params, | ||
| ) | ||
| return AsyncScorer(self._client, response.id) | ||
|
|
||
| def from_id(self, scorer_id: str) -> AsyncScorer: | ||
| """Return a scorer wrapper for the given ID. | ||
|
|
||
| :param scorer_id: Scorer ID to wrap | ||
| :type scorer_id: str | ||
| :return: Wrapper for the scorer resource | ||
| :rtype: AsyncScorer | ||
| """ | ||
| return AsyncScorer(self._client, scorer_id) | ||
|
|
||
| async def list( | ||
| self, | ||
| **params: Unpack[SDKScorerListParams], | ||
| ) -> list[AsyncScorer]: | ||
| """List all scenario scorers. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters | ||
| :return: List of scorer wrappers | ||
| :rtype: list[AsyncScorer] | ||
| """ | ||
| page = await self._client.scenarios.scorers.list( | ||
| **params, | ||
| ) | ||
| return [AsyncScorer(self._client, item.id) async for item in page] | ||
|
|
||
|
|
||
| class AsyncRunloopSDK: | ||
| """High-level asynchronous entry point for the Runloop SDK. | ||
|
|
||
|
|
@@ -488,6 +552,8 @@ class AsyncRunloopSDK: | |
| :vartype devbox: AsyncDevboxOps | ||
| :ivar blueprint: High-level async interface for blueprint management | ||
| :vartype blueprint: AsyncBlueprintOps | ||
| :ivar scorer: High-level async interface for scorer management | ||
| :vartype scorer: AsyncScorerOps | ||
| :ivar snapshot: High-level async interface for snapshot management | ||
| :vartype snapshot: AsyncSnapshotOps | ||
| :ivar storage_object: High-level async interface for storage object management | ||
|
|
@@ -504,6 +570,7 @@ class AsyncRunloopSDK: | |
| api: AsyncRunloop | ||
| devbox: AsyncDevboxOps | ||
| blueprint: AsyncBlueprintOps | ||
| scorer: AsyncScorerOps | ||
| snapshot: AsyncSnapshotOps | ||
| storage_object: AsyncStorageObjectOps | ||
|
|
||
|
|
@@ -547,6 +614,7 @@ def __init__( | |
|
|
||
| self.devbox = AsyncDevboxOps(self.api) | ||
| self.blueprint = AsyncBlueprintOps(self.api) | ||
| self.scorer = AsyncScorerOps(self.api) | ||
| self.snapshot = AsyncSnapshotOps(self.api) | ||
| self.storage_object = AsyncStorageObjectOps(self.api) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Scorer resource class for asynchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ._types import ( | ||
| BaseRequestOptions, | ||
| SDKScorerUpdateParams, | ||
| SDKScorerValidateParams, | ||
| ) | ||
| from .._client import AsyncRunloop | ||
| from ..types.scenarios import ScorerUpdateResponse, ScorerRetrieveResponse, ScorerValidateResponse | ||
|
|
||
|
|
||
| class AsyncScorer: | ||
| """Asynchronous wrapper around a scenario scorer resource.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| client: AsyncRunloop, | ||
| scorer_id: str, | ||
| ) -> None: | ||
| """Initialize the wrapper. | ||
|
||
|
|
||
| :param client: Generated AsyncRunloop client | ||
| :type client: AsyncRunloop | ||
| :param scorer_id: Scorer ID returned by the API | ||
| :type scorer_id: str | ||
| """ | ||
| self._client = client | ||
| self._id = scorer_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<AsyncScorer id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| """Return the scorer ID. | ||
|
|
||
| :return: Unique scorer ID | ||
| :rtype: str | ||
| """ | ||
| return self._id | ||
|
|
||
| async def get_info( | ||
| self, | ||
| **options: Unpack[BaseRequestOptions], | ||
| ) -> ScorerRetrieveResponse: | ||
| """Retrieve the latest scorer details. | ||
|
|
||
| :param options: Optional request configuration | ||
| :return: API response describing the scorer | ||
| :rtype: ScorerRetrieveResponse | ||
| """ | ||
| return await self._client.scenarios.scorers.retrieve( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| async def update( | ||
| self, | ||
| **params: Unpack[SDKScorerUpdateParams], | ||
| ) -> ScorerUpdateResponse: | ||
| """Update the scorer. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters | ||
| :return: API response with updated scorer details | ||
| :rtype: ScorerUpdateResponse | ||
| """ | ||
| return await self._client.scenarios.scorers.update( | ||
| self._id, | ||
| **params, | ||
| ) | ||
|
|
||
| async def validate( | ||
| self, | ||
| **params: Unpack[SDKScorerValidateParams], | ||
| ) -> ScorerValidateResponse: | ||
| """Validate the scorer with a given context. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters | ||
| :return: API response with validation results | ||
| :rtype: ScorerValidateResponse | ||
| """ | ||
| return await self._client.scenarios.scorers.validate( | ||
| self._id, | ||
| **params, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """Scorer resource class for synchronous operations.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing_extensions import Unpack, override | ||
|
|
||
| from ._types import ( | ||
| BaseRequestOptions, | ||
| SDKScorerUpdateParams, | ||
| SDKScorerValidateParams, | ||
| ) | ||
| from .._client import Runloop | ||
| from ..types.scenarios import ScorerUpdateResponse, ScorerRetrieveResponse, ScorerValidateResponse | ||
|
|
||
|
|
||
| class Scorer: | ||
| """Synchronous wrapper around a scenario scorer resource.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| client: Runloop, | ||
| scorer_id: str, | ||
| ) -> None: | ||
| """Initialize the wrapper. | ||
|
|
||
| :param client: Generated Runloop client | ||
| :type client: Runloop | ||
| :param scorer_id: Scorer ID returned by the API | ||
| :type scorer_id: str | ||
| """ | ||
| self._client = client | ||
| self._id = scorer_id | ||
|
|
||
| @override | ||
| def __repr__(self) -> str: | ||
| return f"<Scorer id={self._id!r}>" | ||
|
|
||
| @property | ||
| def id(self) -> str: | ||
| """Return the scorer ID. | ||
|
|
||
| :return: Unique scorer ID | ||
| :rtype: str | ||
| """ | ||
| return self._id | ||
|
|
||
| def get_info( | ||
| self, | ||
| **options: Unpack[BaseRequestOptions], | ||
| ) -> ScorerRetrieveResponse: | ||
| """Retrieve the latest scorer details. | ||
|
|
||
| :param options: Optional request configuration | ||
| :return: API response describing the scorer | ||
| :rtype: ScorerRetrieveResponse | ||
| """ | ||
| return self._client.scenarios.scorers.retrieve( | ||
| self._id, | ||
| **options, | ||
| ) | ||
|
|
||
| def update( | ||
| self, | ||
| **params: Unpack[SDKScorerUpdateParams], | ||
| ) -> ScorerUpdateResponse: | ||
| """Update the scorer. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters | ||
| :return: API response with updated scorer details | ||
| :rtype: ScorerUpdateResponse | ||
| """ | ||
| return self._client.scenarios.scorers.update( | ||
| self._id, | ||
| **params, | ||
| ) | ||
|
|
||
| def validate( | ||
| self, | ||
| **params: Unpack[SDKScorerValidateParams], | ||
| ) -> ScorerValidateResponse: | ||
| """Validate the scorer with a given context. | ||
|
|
||
| :param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters | ||
| :return: API response with validation results | ||
| :rtype: ScorerValidateResponse | ||
| """ | ||
| return self._client.scenarios.scorers.validate( | ||
| self._id, | ||
| **params, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably good to describe as 'benchmark scenario scorers' since 'scenario' isn't particularly obvious outside the benchmark context.