Skip to content

Commit 9a68a2f

Browse files
committed
added scorer class (kept create and list as static methods for now since we don't know how we're creating scorers yet)
1 parent bf8bf33 commit 9a68a2f

File tree

4 files changed

+281
-0
lines changed

4 files changed

+281
-0
lines changed

src/runloop_api_client/sdk/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
AsyncStorageObjectOps,
1515
)
1616
from .devbox import Devbox
17+
from .scorer import Scorer
1718
from .snapshot import Snapshot
1819
from .blueprint import Blueprint
1920
from .execution import Execution
2021
from .async_devbox import AsyncDevbox
22+
from .async_scorer import AsyncScorer
2123
from .async_snapshot import AsyncSnapshot
2224
from .storage_object import StorageObject
2325
from .async_blueprint import AsyncBlueprint
@@ -48,6 +50,8 @@
4850
"AsyncExecutionResult",
4951
"Blueprint",
5052
"AsyncBlueprint",
53+
"Scorer",
54+
"AsyncScorer",
5155
"Snapshot",
5256
"AsyncSnapshot",
5357
"StorageObject",

src/runloop_api_client/sdk/_types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .._types import Body, Query, Headers, Timeout, NotGiven
55
from ..lib.polling import PollingConfig
66
from ..types.devboxes import DiskSnapshotListParams, DiskSnapshotUpdateParams
7+
from ..types.scenarios import ScorerListParams, ScorerCreateParams, ScorerUpdateParams, ScorerValidateParams
78
from ..types.devbox_list_params import DevboxListParams
89
from ..types.object_list_params import ObjectListParams
910
from ..types.devbox_create_params import DevboxCreateParams, DevboxBaseCreateParams
@@ -140,3 +141,19 @@ class SDKObjectCreateParams(ObjectCreateParams, LongRequestOptions):
140141

141142
class SDKObjectDownloadParams(ObjectDownloadParams, BaseRequestOptions):
142143
pass
144+
145+
146+
class SDKScorerCreateParams(ScorerCreateParams, LongRequestOptions):
147+
pass
148+
149+
150+
class SDKScorerListParams(ScorerListParams, BaseRequestOptions):
151+
pass
152+
153+
154+
class SDKScorerUpdateParams(ScorerUpdateParams, LongRequestOptions):
155+
pass
156+
157+
158+
class SDKScorerValidateParams(ScorerValidateParams, LongRequestOptions):
159+
pass
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""Scorer resource class for asynchronous operations."""
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Unpack, override
6+
7+
from ._types import (
8+
BaseRequestOptions,
9+
SDKScorerListParams,
10+
SDKScorerCreateParams,
11+
SDKScorerUpdateParams,
12+
SDKScorerValidateParams,
13+
)
14+
from .._client import AsyncRunloop
15+
from ..types.scenarios import ScorerUpdateResponse, ScorerRetrieveResponse, ScorerValidateResponse
16+
17+
18+
class AsyncScorer:
19+
"""Asynchronous wrapper around a scenario scorer resource."""
20+
21+
def __init__(
22+
self,
23+
client: AsyncRunloop,
24+
scorer_id: str,
25+
) -> None:
26+
"""Initialize the wrapper.
27+
28+
:param client: Generated AsyncRunloop client
29+
:type client: AsyncRunloop
30+
:param scorer_id: Scorer ID returned by the API
31+
:type scorer_id: str
32+
"""
33+
self._client = client
34+
self._id = scorer_id
35+
36+
@override
37+
def __repr__(self) -> str:
38+
return f"<AsyncScorer id={self._id!r}>"
39+
40+
@property
41+
def id(self) -> str:
42+
"""Return the scorer ID.
43+
44+
:return: Unique scorer ID
45+
:rtype: str
46+
"""
47+
return self._id
48+
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+
87+
async def get_info(
88+
self,
89+
**options: Unpack[BaseRequestOptions],
90+
) -> ScorerRetrieveResponse:
91+
"""Retrieve the latest scorer details.
92+
93+
:param options: Optional request configuration
94+
:return: API response describing the scorer
95+
:rtype: ScorerRetrieveResponse
96+
"""
97+
return await self._client.scenarios.scorers.retrieve(
98+
self._id,
99+
**options,
100+
)
101+
102+
async def update(
103+
self,
104+
**params: Unpack[SDKScorerUpdateParams],
105+
) -> ScorerUpdateResponse:
106+
"""Update the scorer.
107+
108+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters
109+
:return: API response with updated scorer details
110+
:rtype: ScorerUpdateResponse
111+
"""
112+
return await self._client.scenarios.scorers.update(
113+
self._id,
114+
**params,
115+
)
116+
117+
async def validate(
118+
self,
119+
**params: Unpack[SDKScorerValidateParams],
120+
) -> ScorerValidateResponse:
121+
"""Validate the scorer with a given context.
122+
123+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters
124+
:return: API response with validation results
125+
:rtype: ScorerValidateResponse
126+
"""
127+
return await self._client.scenarios.scorers.validate(
128+
self._id,
129+
**params,
130+
)
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""Scorer resource class for synchronous operations."""
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Unpack, override
6+
7+
from ._types import (
8+
BaseRequestOptions,
9+
SDKScorerListParams,
10+
SDKScorerCreateParams,
11+
SDKScorerUpdateParams,
12+
SDKScorerValidateParams,
13+
)
14+
from .._client import Runloop
15+
from ..types.scenarios import ScorerUpdateResponse, ScorerRetrieveResponse, ScorerValidateResponse
16+
17+
18+
class Scorer:
19+
"""Synchronous wrapper around a scenario scorer resource."""
20+
21+
def __init__(
22+
self,
23+
client: Runloop,
24+
scorer_id: str,
25+
) -> None:
26+
"""Initialize the wrapper.
27+
28+
:param client: Generated Runloop client
29+
:type client: Runloop
30+
:param scorer_id: Scorer ID returned by the API
31+
:type scorer_id: str
32+
"""
33+
self._client = client
34+
self._id = scorer_id
35+
36+
@override
37+
def __repr__(self) -> str:
38+
return f"<Scorer id={self._id!r}>"
39+
40+
@property
41+
def id(self) -> str:
42+
"""Return the scorer ID.
43+
44+
:return: Unique scorer ID
45+
:rtype: str
46+
"""
47+
return self._id
48+
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+
87+
def get_info(
88+
self,
89+
**options: Unpack[BaseRequestOptions],
90+
) -> ScorerRetrieveResponse:
91+
"""Retrieve the latest scorer details.
92+
93+
:param options: Optional request configuration
94+
:return: API response describing the scorer
95+
:rtype: ScorerRetrieveResponse
96+
"""
97+
return self._client.scenarios.scorers.retrieve(
98+
self._id,
99+
**options,
100+
)
101+
102+
def update(
103+
self,
104+
**params: Unpack[SDKScorerUpdateParams],
105+
) -> ScorerUpdateResponse:
106+
"""Update the scorer.
107+
108+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters
109+
:return: API response with updated scorer details
110+
:rtype: ScorerUpdateResponse
111+
"""
112+
return self._client.scenarios.scorers.update(
113+
self._id,
114+
**params,
115+
)
116+
117+
def validate(
118+
self,
119+
**params: Unpack[SDKScorerValidateParams],
120+
) -> ScorerValidateResponse:
121+
"""Validate the scorer with a given context.
122+
123+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters
124+
:return: API response with validation results
125+
:rtype: ScorerValidateResponse
126+
"""
127+
return self._client.scenarios.scorers.validate(
128+
self._id,
129+
**params,
130+
)

0 commit comments

Comments
 (0)