Skip to content

Commit 94435a7

Browse files
committed
refactored static methods to ScorerOps class
1 parent 5e37a2e commit 94435a7

5 files changed

Lines changed: 140 additions & 81 deletions

File tree

src/runloop_api_client/sdk/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
from __future__ import annotations
77

8-
from .sync import DevboxOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps
8+
from .sync import DevboxOps, ScorerOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps
99
from .async_ import (
1010
AsyncDevboxOps,
11+
AsyncScorerOps,
1112
AsyncRunloopSDK,
1213
AsyncSnapshotOps,
1314
AsyncBlueprintOps,
@@ -37,6 +38,8 @@
3738
"AsyncDevboxOps",
3839
"BlueprintOps",
3940
"AsyncBlueprintOps",
41+
"ScorerOps",
42+
"AsyncScorerOps",
4043
"SnapshotOps",
4144
"AsyncSnapshotOps",
4245
"StorageObjectOps",

src/runloop_api_client/sdk/async_.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
LongRequestOptions,
1717
SDKDevboxListParams,
1818
SDKObjectListParams,
19+
SDKScorerListParams,
1920
SDKDevboxCreateParams,
2021
SDKObjectCreateParams,
22+
SDKScorerCreateParams,
2123
SDKBlueprintListParams,
2224
SDKBlueprintCreateParams,
2325
SDKDiskSnapshotListParams,
@@ -27,6 +29,7 @@
2729
from .._client import DEFAULT_MAX_RETRIES, AsyncRunloop
2830
from ._helpers import detect_content_type
2931
from .async_devbox import AsyncDevbox
32+
from .async_scorer import AsyncScorer
3033
from .async_snapshot import AsyncSnapshot
3134
from .async_blueprint import AsyncBlueprint
3235
from .async_storage_object import AsyncStorageObject
@@ -475,6 +478,67 @@ async def upload_from_bytes(
475478
return obj
476479

477480

481+
class AsyncScorerOps:
482+
"""High-level async manager for creating and managing scenario scorers.
483+
484+
Accessed via ``runloop.scorer`` from :class:`AsyncRunloopSDK`, provides
485+
coroutines to create, list, and access scorers.
486+
487+
Example:
488+
>>> runloop = AsyncRunloopSDK()
489+
>>> scorer = await runloop.scorer.create(name="my-scorer", scorer_type="llm_judge")
490+
>>> scorers = await runloop.scorer.list()
491+
"""
492+
493+
def __init__(self, client: AsyncRunloop) -> None:
494+
"""Initialize the manager.
495+
496+
:param client: Generated AsyncRunloop client to wrap
497+
:type client: AsyncRunloop
498+
"""
499+
self._client = client
500+
501+
async def create(
502+
self,
503+
**params: Unpack[SDKScorerCreateParams],
504+
) -> AsyncScorer:
505+
"""Create a new scenario scorer.
506+
507+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
508+
:return: Wrapper bound to the newly created scorer
509+
:rtype: AsyncScorer
510+
"""
511+
response = await self._client.scenarios.scorers.create(
512+
**params,
513+
)
514+
return AsyncScorer(self._client, response.id)
515+
516+
def from_id(self, scorer_id: str) -> AsyncScorer:
517+
"""Return a scorer wrapper for the given ID.
518+
519+
:param scorer_id: Scorer ID to wrap
520+
:type scorer_id: str
521+
:return: Wrapper for the scorer resource
522+
:rtype: AsyncScorer
523+
"""
524+
return AsyncScorer(self._client, scorer_id)
525+
526+
async def list(
527+
self,
528+
**params: Unpack[SDKScorerListParams],
529+
) -> list[AsyncScorer]:
530+
"""List all scenario scorers.
531+
532+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
533+
:return: List of scorer wrappers
534+
:rtype: list[AsyncScorer]
535+
"""
536+
page = await self._client.scenarios.scorers.list(
537+
**params,
538+
)
539+
return [AsyncScorer(self._client, item.id) async for item in page]
540+
541+
478542
class AsyncRunloopSDK:
479543
"""High-level asynchronous entry point for the Runloop SDK.
480544
@@ -488,6 +552,8 @@ class AsyncRunloopSDK:
488552
:vartype devbox: AsyncDevboxOps
489553
:ivar blueprint: High-level async interface for blueprint management
490554
:vartype blueprint: AsyncBlueprintOps
555+
:ivar scorer: High-level async interface for scorer management
556+
:vartype scorer: AsyncScorerOps
491557
:ivar snapshot: High-level async interface for snapshot management
492558
:vartype snapshot: AsyncSnapshotOps
493559
:ivar storage_object: High-level async interface for storage object management
@@ -504,6 +570,7 @@ class AsyncRunloopSDK:
504570
api: AsyncRunloop
505571
devbox: AsyncDevboxOps
506572
blueprint: AsyncBlueprintOps
573+
scorer: AsyncScorerOps
507574
snapshot: AsyncSnapshotOps
508575
storage_object: AsyncStorageObjectOps
509576

@@ -547,6 +614,7 @@ def __init__(
547614

548615
self.devbox = AsyncDevboxOps(self.api)
549616
self.blueprint = AsyncBlueprintOps(self.api)
617+
self.scorer = AsyncScorerOps(self.api)
550618
self.snapshot = AsyncSnapshotOps(self.api)
551619
self.storage_object = AsyncStorageObjectOps(self.api)
552620

src/runloop_api_client/sdk/async_scorer.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from ._types import (
88
BaseRequestOptions,
9-
SDKScorerListParams,
10-
SDKScorerCreateParams,
119
SDKScorerUpdateParams,
1210
SDKScorerValidateParams,
1311
)
@@ -46,44 +44,6 @@ def id(self) -> str:
4644
"""
4745
return self._id
4846

49-
# TODO: replace static method once we have a proper client
50-
@staticmethod
51-
async def create(
52-
client: AsyncRunloop,
53-
**params: Unpack[SDKScorerCreateParams],
54-
) -> "AsyncScorer":
55-
"""Create a new scenario scorer.
56-
57-
:param client: Generated AsyncRunloop client
58-
:type client: AsyncRunloop
59-
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
60-
:return: Wrapper bound to the newly created scorer
61-
:rtype: AsyncScorer
62-
"""
63-
response = await client.scenarios.scorers.create(
64-
**params,
65-
)
66-
return AsyncScorer(client, response.id)
67-
68-
# TODO: replace static method once we have a proper client
69-
@staticmethod
70-
async def list(
71-
client: AsyncRunloop,
72-
**params: Unpack[SDKScorerListParams],
73-
) -> list["AsyncScorer"]:
74-
"""List all scenario scorers.
75-
76-
:param client: Generated AsyncRunloop client
77-
:type client: AsyncRunloop
78-
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
79-
:return: List of scorer wrappers
80-
:rtype: list[AsyncScorer]
81-
"""
82-
page = await client.scenarios.scorers.list(
83-
**params,
84-
)
85-
return [AsyncScorer(client, item.id) async for item in page]
86-
8747
async def get_info(
8848
self,
8949
**options: Unpack[BaseRequestOptions],

src/runloop_api_client/sdk/scorer.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from ._types import (
88
BaseRequestOptions,
9-
SDKScorerListParams,
10-
SDKScorerCreateParams,
119
SDKScorerUpdateParams,
1210
SDKScorerValidateParams,
1311
)
@@ -46,44 +44,6 @@ def id(self) -> str:
4644
"""
4745
return self._id
4846

49-
# TODO: replace static method once we have a proper client
50-
@staticmethod
51-
def create(
52-
client: Runloop,
53-
**params: Unpack[SDKScorerCreateParams],
54-
) -> "Scorer":
55-
"""Create a new scenario scorer.
56-
57-
:param client: Generated Runloop client
58-
:type client: Runloop
59-
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
60-
:return: Wrapper bound to the newly created scorer
61-
:rtype: Scorer
62-
"""
63-
response = client.scenarios.scorers.create(
64-
**params,
65-
)
66-
return Scorer(client, response.id)
67-
68-
# TODO: replace static method once we have a proper client
69-
@staticmethod
70-
def list(
71-
client: Runloop,
72-
**params: Unpack[SDKScorerListParams],
73-
) -> list["Scorer"]:
74-
"""List all scenario scorers.
75-
76-
:param client: Generated Runloop client
77-
:type client: Runloop
78-
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
79-
:return: List of scorer wrappers
80-
:rtype: list[Scorer]
81-
"""
82-
page = client.scenarios.scorers.list(
83-
**params,
84-
)
85-
return [Scorer(client, item.id) for item in page]
86-
8747
def get_info(
8848
self,
8949
**options: Unpack[BaseRequestOptions],

src/runloop_api_client/sdk/sync.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
LongRequestOptions,
1616
SDKDevboxListParams,
1717
SDKObjectListParams,
18+
SDKScorerListParams,
1819
SDKDevboxCreateParams,
1920
SDKObjectCreateParams,
21+
SDKScorerCreateParams,
2022
SDKBlueprintListParams,
2123
SDKBlueprintCreateParams,
2224
SDKDiskSnapshotListParams,
2325
SDKDevboxCreateFromImageParams,
2426
)
2527
from .devbox import Devbox
28+
from .scorer import Scorer
2629
from .._types import Timeout, NotGiven, not_given
2730
from .._client import DEFAULT_MAX_RETRIES, Runloop
2831
from ._helpers import detect_content_type
@@ -470,6 +473,67 @@ def upload_from_bytes(
470473
return obj
471474

472475

476+
class ScorerOps:
477+
"""High-level manager for creating and managing scenario scorers.
478+
479+
Accessed via ``runloop.scorer`` from :class:`RunloopSDK`, provides methods
480+
to create, list, and access scorers.
481+
482+
Example:
483+
>>> runloop = RunloopSDK()
484+
>>> scorer = runloop.scorer.create(name="my-scorer", scorer_type="llm_judge")
485+
>>> scorers = runloop.scorer.list()
486+
"""
487+
488+
def __init__(self, client: Runloop) -> None:
489+
"""Initialize the manager.
490+
491+
:param client: Generated Runloop client to wrap
492+
:type client: Runloop
493+
"""
494+
self._client = client
495+
496+
def create(
497+
self,
498+
**params: Unpack[SDKScorerCreateParams],
499+
) -> Scorer:
500+
"""Create a new scenario scorer.
501+
502+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
503+
:return: Wrapper bound to the newly created scorer
504+
:rtype: Scorer
505+
"""
506+
response = self._client.scenarios.scorers.create(
507+
**params,
508+
)
509+
return Scorer(self._client, response.id)
510+
511+
def from_id(self, scorer_id: str) -> Scorer:
512+
"""Return a scorer wrapper for the given ID.
513+
514+
:param scorer_id: Scorer ID to wrap
515+
:type scorer_id: str
516+
:return: Wrapper for the scorer resource
517+
:rtype: Scorer
518+
"""
519+
return Scorer(self._client, scorer_id)
520+
521+
def list(
522+
self,
523+
**params: Unpack[SDKScorerListParams],
524+
) -> list[Scorer]:
525+
"""List all scenario scorers.
526+
527+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
528+
:return: List of scorer wrappers
529+
:rtype: list[Scorer]
530+
"""
531+
page = self._client.scenarios.scorers.list(
532+
**params,
533+
)
534+
return [Scorer(self._client, item.id) for item in page]
535+
536+
473537
class RunloopSDK:
474538
"""High-level synchronous entry point for the Runloop SDK.
475539
@@ -483,6 +547,8 @@ class RunloopSDK:
483547
:vartype devbox: DevboxOps
484548
:ivar blueprint: High-level interface for blueprint management
485549
:vartype blueprint: BlueprintOps
550+
:ivar scorer: High-level interface for scorer management
551+
:vartype scorer: ScorerOps
486552
:ivar snapshot: High-level interface for snapshot management
487553
:vartype snapshot: SnapshotOps
488554
:ivar storage_object: High-level interface for storage object management
@@ -499,6 +565,7 @@ class RunloopSDK:
499565
api: Runloop
500566
devbox: DevboxOps
501567
blueprint: BlueprintOps
568+
scorer: ScorerOps
502569
snapshot: SnapshotOps
503570
storage_object: StorageObjectOps
504571

@@ -542,6 +609,7 @@ def __init__(
542609

543610
self.devbox = DevboxOps(self.api)
544611
self.blueprint = BlueprintOps(self.api)
612+
self.scorer = ScorerOps(self.api)
545613
self.snapshot = SnapshotOps(self.api)
546614
self.storage_object = StorageObjectOps(self.api)
547615

0 commit comments

Comments
 (0)