Skip to content

Commit c1f617e

Browse files
committed
update scorer and scorer ops docstrings to be more helpful while not exposing system internals
1 parent e8fdc37 commit c1f617e

4 files changed

Lines changed: 88 additions & 140 deletions

File tree

src/runloop_api_client/sdk/async_.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -479,63 +479,50 @@ async def upload_from_bytes(
479479

480480

481481
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.
482+
"""Create and manage custom scorers (async). Access via ``runloop.scorer``.
486483
487484
Example:
488485
>>> runloop = AsyncRunloopSDK()
489486
>>> scorer = await runloop.scorer.create(type="my_scorer", bash_script="echo 'score=1.0'")
490-
>>> scorers = await runloop.scorer.list()
487+
>>> all_scorers = await runloop.scorer.list()
491488
"""
492489

493490
def __init__(self, client: AsyncRunloop) -> None:
494-
"""Initialize the manager.
491+
"""Initialize AsyncScorerOps.
495492
496-
:param client: Generated AsyncRunloop client to wrap
493+
:param client: AsyncRunloop client instance
497494
:type client: AsyncRunloop
498495
"""
499496
self._client = client
500497

501-
async def create(
502-
self,
503-
**params: Unpack[SDKScorerCreateParams],
504-
) -> AsyncScorer:
505-
"""Create a new scenario scorer.
498+
async def create(self, **params: Unpack[SDKScorerCreateParams]) -> AsyncScorer:
499+
"""Create a new scorer with the given type and bash script.
506500
507501
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
508-
:return: Wrapper bound to the newly created scorer
502+
:return: The newly created scorer
509503
:rtype: AsyncScorer
510504
"""
511-
response = await self._client.scenarios.scorers.create(
512-
**params,
513-
)
505+
response = await self._client.scenarios.scorers.create(**params)
514506
return AsyncScorer(self._client, response.id)
515507

516508
def from_id(self, scorer_id: str) -> AsyncScorer:
517-
"""Return a scorer wrapper for the given ID.
509+
"""Get an AsyncScorer instance for an existing scorer ID.
518510
519-
:param scorer_id: Scorer ID to wrap
511+
:param scorer_id: ID of the scorer
520512
:type scorer_id: str
521-
:return: Wrapper for the scorer resource
513+
:return: AsyncScorer instance for the given ID
522514
:rtype: AsyncScorer
523515
"""
524516
return AsyncScorer(self._client, scorer_id)
525517

526-
async def list(
527-
self,
528-
**params: Unpack[SDKScorerListParams],
529-
) -> list[AsyncScorer]:
530-
"""List all scenario scorers.
518+
async def list(self, **params: Unpack[SDKScorerListParams]) -> list[AsyncScorer]:
519+
"""List all scorers, optionally filtered by parameters.
531520
532521
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
533-
:return: List of scorer wrappers
522+
:return: List of scorers
534523
:rtype: list[AsyncScorer]
535524
"""
536-
page = await self._client.scenarios.scorers.list(
537-
**params,
538-
)
525+
page = await self._client.scenarios.scorers.list(**params)
539526
return [AsyncScorer(self._client, item.id) async for item in page]
540527

541528

src/runloop_api_client/sdk/async_scorer.py

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414

1515

1616
class AsyncScorer:
17-
"""Asynchronous wrapper around a scenario scorer resource."""
17+
"""A custom scorer for evaluating scenario outputs (async).
1818
19-
def __init__(
20-
self,
21-
client: AsyncRunloop,
22-
scorer_id: str,
23-
) -> None:
24-
"""Initialize the wrapper.
19+
Scorers define bash scripts that produce a score (0.0-1.0) for scenario runs.
20+
Obtain instances via ``runloop.scorer.create()`` or ``runloop.scorer.from_id()``.
2521
26-
:param client: Generated AsyncRunloop client
22+
Example:
23+
>>> runloop = AsyncRunloopSDK()
24+
>>> scorer = await runloop.scorer.create(type="my_scorer", bash_script="echo 'score=1.0'")
25+
>>> await scorer.validate(scoring_context={"output": "test"})
26+
"""
27+
28+
def __init__(self, client: AsyncRunloop, scorer_id: str) -> None:
29+
"""Create an AsyncScorer instance.
30+
31+
:param client: AsyncRunloop client instance
2732
:type client: AsyncRunloop
28-
:param scorer_id: Scorer ID returned by the API
33+
:param scorer_id: ID of the scorer
2934
:type scorer_id: str
3035
"""
3136
self._client = client
@@ -37,54 +42,36 @@ def __repr__(self) -> str:
3742

3843
@property
3944
def id(self) -> str:
40-
"""Return the scorer ID.
45+
"""The scorer's unique identifier.
4146
42-
:return: Unique scorer ID
47+
:return: Scorer ID
4348
:rtype: str
4449
"""
4550
return self._id
4651

47-
async def get_info(
48-
self,
49-
**options: Unpack[BaseRequestOptions],
50-
) -> ScorerRetrieveResponse:
51-
"""Retrieve the latest scorer details.
52+
async def get_info(self, **options: Unpack[BaseRequestOptions]) -> ScorerRetrieveResponse:
53+
"""Fetch current scorer details from the API.
5254
53-
:param options: Optional request configuration
54-
:return: API response describing the scorer
55+
:param options: See :typeddict:`~runloop_api_client.sdk._types.BaseRequestOptions` for available options
56+
:return: Current scorer details
5557
:rtype: ScorerRetrieveResponse
5658
"""
57-
return await self._client.scenarios.scorers.retrieve(
58-
self._id,
59-
**options,
60-
)
59+
return await self._client.scenarios.scorers.retrieve(self._id, **options)
6160

62-
async def update(
63-
self,
64-
**params: Unpack[SDKScorerUpdateParams],
65-
) -> ScorerUpdateResponse:
66-
"""Update the scorer.
61+
async def update(self, **params: Unpack[SDKScorerUpdateParams]) -> ScorerUpdateResponse:
62+
"""Update the scorer's type or bash script.
6763
6864
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters
69-
:return: API response with updated scorer details
65+
:return: Updated scorer details
7066
:rtype: ScorerUpdateResponse
7167
"""
72-
return await self._client.scenarios.scorers.update(
73-
self._id,
74-
**params,
75-
)
68+
return await self._client.scenarios.scorers.update(self._id, **params)
7669

77-
async def validate(
78-
self,
79-
**params: Unpack[SDKScorerValidateParams],
80-
) -> ScorerValidateResponse:
81-
"""Validate the scorer with a given context.
70+
async def validate(self, **params: Unpack[SDKScorerValidateParams]) -> ScorerValidateResponse:
71+
"""Run the scorer against the provided context and return the result.
8272
8373
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters
84-
:return: API response with validation results
74+
:return: Validation result with score
8575
:rtype: ScorerValidateResponse
8676
"""
87-
return await self._client.scenarios.scorers.validate(
88-
self._id,
89-
**params,
90-
)
77+
return await self._client.scenarios.scorers.validate(self._id, **params)

src/runloop_api_client/sdk/scorer.py

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414

1515

1616
class Scorer:
17-
"""Synchronous wrapper around a scenario scorer resource."""
17+
"""A custom scorer for evaluating scenario outputs.
1818
19-
def __init__(
20-
self,
21-
client: Runloop,
22-
scorer_id: str,
23-
) -> None:
24-
"""Initialize the wrapper.
19+
Scorers define bash scripts that produce a score (0.0-1.0) for scenario runs.
20+
Obtain instances via ``runloop.scorer.create()`` or ``runloop.scorer.from_id()``.
2521
26-
:param client: Generated Runloop client
22+
Example:
23+
>>> runloop = RunloopSDK()
24+
>>> scorer = runloop.scorer.create(type="my_scorer", bash_script="echo 'score=1.0'")
25+
>>> scorer.validate(scoring_context={"output": "test"})
26+
"""
27+
28+
def __init__(self, client: Runloop, scorer_id: str) -> None:
29+
"""Create a Scorer instance.
30+
31+
:param client: Runloop client instance
2732
:type client: Runloop
28-
:param scorer_id: Scorer ID returned by the API
33+
:param scorer_id: ID of the scorer
2934
:type scorer_id: str
3035
"""
3136
self._client = client
@@ -37,54 +42,36 @@ def __repr__(self) -> str:
3742

3843
@property
3944
def id(self) -> str:
40-
"""Return the scorer ID.
45+
"""The scorer's unique identifier.
4146
42-
:return: Unique scorer ID
47+
:return: Scorer ID
4348
:rtype: str
4449
"""
4550
return self._id
4651

47-
def get_info(
48-
self,
49-
**options: Unpack[BaseRequestOptions],
50-
) -> ScorerRetrieveResponse:
51-
"""Retrieve the latest scorer details.
52+
def get_info(self, **options: Unpack[BaseRequestOptions]) -> ScorerRetrieveResponse:
53+
"""Fetch current scorer details from the API.
5254
53-
:param options: Optional request configuration
54-
:return: API response describing the scorer
55+
:param options: See :typeddict:`~runloop_api_client.sdk._types.BaseRequestOptions` for available options
56+
:return: Current scorer details
5557
:rtype: ScorerRetrieveResponse
5658
"""
57-
return self._client.scenarios.scorers.retrieve(
58-
self._id,
59-
**options,
60-
)
59+
return self._client.scenarios.scorers.retrieve(self._id, **options)
6160

62-
def update(
63-
self,
64-
**params: Unpack[SDKScorerUpdateParams],
65-
) -> ScorerUpdateResponse:
66-
"""Update the scorer.
61+
def update(self, **params: Unpack[SDKScorerUpdateParams]) -> ScorerUpdateResponse:
62+
"""Update the scorer's type or bash script.
6763
6864
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerUpdateParams` for available parameters
69-
:return: API response with updated scorer details
65+
:return: Updated scorer details
7066
:rtype: ScorerUpdateResponse
7167
"""
72-
return self._client.scenarios.scorers.update(
73-
self._id,
74-
**params,
75-
)
68+
return self._client.scenarios.scorers.update(self._id, **params)
7669

77-
def validate(
78-
self,
79-
**params: Unpack[SDKScorerValidateParams],
80-
) -> ScorerValidateResponse:
81-
"""Validate the scorer with a given context.
70+
def validate(self, **params: Unpack[SDKScorerValidateParams]) -> ScorerValidateResponse:
71+
"""Run the scorer against the provided context and return the result.
8272
8373
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerValidateParams` for available parameters
84-
:return: API response with validation results
74+
:return: Validation result with score
8575
:rtype: ScorerValidateResponse
8676
"""
87-
return self._client.scenarios.scorers.validate(
88-
self._id,
89-
**params,
90-
)
77+
return self._client.scenarios.scorers.validate(self._id, **params)

src/runloop_api_client/sdk/sync.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -474,63 +474,50 @@ def upload_from_bytes(
474474

475475

476476
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.
477+
"""Create and manage custom scorers. Access via ``runloop.scorer``.
481478
482479
Example:
483480
>>> runloop = RunloopSDK()
484481
>>> scorer = runloop.scorer.create(type="my_scorer", bash_script="echo 'score=1.0'")
485-
>>> scorers = runloop.scorer.list()
482+
>>> all_scorers = runloop.scorer.list()
486483
"""
487484

488485
def __init__(self, client: Runloop) -> None:
489-
"""Initialize the manager.
486+
"""Initialize ScorerOps.
490487
491-
:param client: Generated Runloop client to wrap
488+
:param client: Runloop client instance
492489
:type client: Runloop
493490
"""
494491
self._client = client
495492

496-
def create(
497-
self,
498-
**params: Unpack[SDKScorerCreateParams],
499-
) -> Scorer:
500-
"""Create a new scenario scorer.
493+
def create(self, **params: Unpack[SDKScorerCreateParams]) -> Scorer:
494+
"""Create a new scorer with the given type and bash script.
501495
502496
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerCreateParams` for available parameters
503-
:return: Wrapper bound to the newly created scorer
497+
:return: The newly created scorer
504498
:rtype: Scorer
505499
"""
506-
response = self._client.scenarios.scorers.create(
507-
**params,
508-
)
500+
response = self._client.scenarios.scorers.create(**params)
509501
return Scorer(self._client, response.id)
510502

511503
def from_id(self, scorer_id: str) -> Scorer:
512-
"""Return a scorer wrapper for the given ID.
504+
"""Get a Scorer instance for an existing scorer ID.
513505
514-
:param scorer_id: Scorer ID to wrap
506+
:param scorer_id: ID of the scorer
515507
:type scorer_id: str
516-
:return: Wrapper for the scorer resource
508+
:return: Scorer instance for the given ID
517509
:rtype: Scorer
518510
"""
519511
return Scorer(self._client, scorer_id)
520512

521-
def list(
522-
self,
523-
**params: Unpack[SDKScorerListParams],
524-
) -> list[Scorer]:
525-
"""List all scenario scorers.
513+
def list(self, **params: Unpack[SDKScorerListParams]) -> list[Scorer]:
514+
"""List all scorers, optionally filtered by parameters.
526515
527516
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKScorerListParams` for available parameters
528-
:return: List of scorer wrappers
517+
:return: List of scorers
529518
:rtype: list[Scorer]
530519
"""
531-
page = self._client.scenarios.scorers.list(
532-
**params,
533-
)
520+
page = self._client.scenarios.scorers.list(**params)
534521
return [Scorer(self._client, item.id) for item in page]
535522

536523

0 commit comments

Comments
 (0)