Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions langfuse/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,9 @@
CategoricalScoreV3,
CorrectionScoreV3,
CreateScoreBatchError,
CreateScoreBatchRequest,
CreateScoreBatchResponse,
CreateScoreBatchResults,
CreateScoreRequest,
CreateScoreResponse,
CreateScoreSource,
CreateScoresRequest,
CreateScoresResponse,
Expand Down Expand Up @@ -502,12 +500,10 @@
"CreateObservationEvent": ".ingestion",
"CreatePromptRequest": ".prompts",
"CreateScoreBatchError": ".scores",
"CreateScoreBatchRequest": ".scores",
"CreateScoreBatchResponse": ".scores",
"CreateScoreBatchResults": ".scores",
"CreateScoreConfigRequest": ".score_configs",
"CreateScoreRequest": ".scores",
"CreateScoreResponse": ".scores",
"CreateScoreSource": ".scores",
"CreateScoreValue": ".commons",
"CreateScoresRequest": ".scores",
Expand Down Expand Up @@ -916,12 +912,10 @@ def __dir__():
"CreateObservationEvent",
"CreatePromptRequest",
"CreateScoreBatchError",
"CreateScoreBatchRequest",
"CreateScoreBatchResponse",
"CreateScoreBatchResults",
"CreateScoreConfigRequest",
"CreateScoreRequest",
"CreateScoreResponse",
"CreateScoreSource",
"CreateScoreValue",
"CreateScoresRequest",
Expand Down
6 changes: 0 additions & 6 deletions langfuse/api/scores/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
CategoricalScoreV3,
CorrectionScoreV3,
CreateScoreBatchError,
CreateScoreBatchRequest,
CreateScoreBatchResponse,
CreateScoreBatchResults,
CreateScoreRequest,
CreateScoreResponse,
CreateScoreSource,
CreateScoresRequest,
CreateScoresResponse,
Expand Down Expand Up @@ -46,11 +44,9 @@
"CategoricalScoreV3": ".types",
"CorrectionScoreV3": ".types",
"CreateScoreBatchError": ".types",
"CreateScoreBatchRequest": ".types",
"CreateScoreBatchResponse": ".types",
"CreateScoreBatchResults": ".types",
"CreateScoreRequest": ".types",
"CreateScoreResponse": ".types",
"CreateScoreSource": ".types",
"CreateScoresRequest": ".types",
"CreateScoresResponse": ".types",
Expand Down Expand Up @@ -109,11 +105,9 @@ def __dir__():
"CategoricalScoreV3",
"CorrectionScoreV3",
"CreateScoreBatchError",
"CreateScoreBatchRequest",
"CreateScoreBatchResponse",
"CreateScoreBatchResults",
"CreateScoreRequest",
"CreateScoreResponse",
"CreateScoreSource",
"CreateScoresRequest",
"CreateScoresResponse",
Expand Down
32 changes: 22 additions & 10 deletions langfuse/api/scores/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create(
request_options: typing.Optional[RequestOptions] = None,
) -> CreateScoresResponse:
"""
Create scores asynchronously. Single score: 200 with ID. Batch: 202 if accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; batches return 202 or 207.
Create scores asynchronously from a list of scores. Returns 202 if all scores are accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; the endpoint returns 202 or 207.

Parameters
----------
Expand All @@ -63,10 +63,16 @@ def create(
base_url="https://yourhost.com/path/to/api",
)
client.scores.create(
request=CreateScoreRequest(
name="name",
value=1.1,
),
request=[
CreateScoreRequest(
name="name",
value=1.1,
),
CreateScoreRequest(
name="name",
value=1.1,
),
],
)
"""
_response = self._raw_client.create(
Expand Down Expand Up @@ -287,7 +293,7 @@ async def create(
request_options: typing.Optional[RequestOptions] = None,
) -> CreateScoresResponse:
"""
Create scores asynchronously. Single score: 200 with ID. Batch: 202 if accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; batches return 202 or 207.
Create scores asynchronously from a list of scores. Returns 202 if all scores are accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; the endpoint returns 202 or 207.

Parameters
----------
Expand Down Expand Up @@ -319,10 +325,16 @@ async def create(

async def main() -> None:
await client.scores.create(
request=CreateScoreRequest(
name="name",
value=1.1,
),
request=[
CreateScoreRequest(
name="name",
value=1.1,
),
CreateScoreRequest(
name="name",
value=1.1,
),
],
)


Expand Down
4 changes: 2 additions & 2 deletions langfuse/api/scores/raw_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create(
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CreateScoresResponse]:
"""
Create scores asynchronously. Single score: 200 with ID. Batch: 202 if accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; batches return 202 or 207.
Create scores asynchronously from a list of scores. Returns 202 if all scores are accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; the endpoint returns 202 or 207.

Parameters
----------
Expand Down Expand Up @@ -465,7 +465,7 @@ async def create(
request_options: typing.Optional[RequestOptions] = None,
) -> AsyncHttpResponse[CreateScoresResponse]:
"""
Create scores asynchronously. Single score: 200 with ID. Batch: 202 if accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; batches return 202 or 207.
Create scores asynchronously from a list of scores. Returns 202 if all scores are accepted, or 207 with accepted/rejected counts and error messages. Do not automatically retry a 207 batch. The generated reference shows only 200; the endpoint returns 202 or 207.

Parameters
----------
Expand Down
6 changes: 0 additions & 6 deletions langfuse/api/scores/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
from .categorical_score_v3 import CategoricalScoreV3
from .correction_score_v3 import CorrectionScoreV3
from .create_score_batch_error import CreateScoreBatchError
from .create_score_batch_request import CreateScoreBatchRequest
from .create_score_batch_response import CreateScoreBatchResponse
from .create_score_batch_results import CreateScoreBatchResults
from .create_score_request import CreateScoreRequest
from .create_score_response import CreateScoreResponse
from .create_score_source import CreateScoreSource
from .create_scores_request import CreateScoresRequest
from .create_scores_response import CreateScoresResponse
Expand Down Expand Up @@ -48,11 +46,9 @@
"CategoricalScoreV3": ".categorical_score_v3",
"CorrectionScoreV3": ".correction_score_v3",
"CreateScoreBatchError": ".create_score_batch_error",
"CreateScoreBatchRequest": ".create_score_batch_request",
"CreateScoreBatchResponse": ".create_score_batch_response",
"CreateScoreBatchResults": ".create_score_batch_results",
"CreateScoreRequest": ".create_score_request",
"CreateScoreResponse": ".create_score_response",
"CreateScoreSource": ".create_score_source",
"CreateScoresRequest": ".create_scores_request",
"CreateScoresResponse": ".create_scores_response",
Expand Down Expand Up @@ -111,11 +107,9 @@ def __dir__():
"CategoricalScoreV3",
"CorrectionScoreV3",
"CreateScoreBatchError",
"CreateScoreBatchRequest",
"CreateScoreBatchResponse",
"CreateScoreBatchResults",
"CreateScoreRequest",
"CreateScoreResponse",
"CreateScoreSource",
"CreateScoresRequest",
"CreateScoresResponse",
Expand Down
25 changes: 0 additions & 25 deletions langfuse/api/scores/types/create_score_batch_request.py

This file was deleted.

17 changes: 0 additions & 17 deletions langfuse/api/scores/types/create_score_response.py

This file was deleted.

21 changes: 19 additions & 2 deletions langfuse/api/scores/types/create_scores_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@

import typing

from .create_score_batch_request import CreateScoreBatchRequest
from .create_score_request import CreateScoreRequest

CreateScoresRequest = typing.Union[CreateScoreRequest, CreateScoreBatchRequest]
"""
from langfuse.commons import ScoreDataType
from langfuse.scores import CreateScoreRequest

[
CreateScoreRequest(
name="accuracy",
value=0.9,
trace_id="cdef-1234-5678-90ab",
),
CreateScoreRequest(
name="helpfulness",
value=1.0,
data_type=ScoreDataType.BOOLEAN,
trace_id="cdef-1234-5678-90ab",
),
]
"""
CreateScoresRequest = typing.List[CreateScoreRequest]
5 changes: 1 addition & 4 deletions langfuse/api/scores/types/create_scores_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

from .create_score_batch_response import CreateScoreBatchResponse
from .create_score_batch_results import CreateScoreBatchResults
from .create_score_response import CreateScoreResponse

CreateScoresResponse = typing.Union[
CreateScoreBatchResults, CreateScoreResponse, CreateScoreBatchResponse
]
CreateScoresResponse = typing.Union[CreateScoreBatchResults, CreateScoreBatchResponse]
8 changes: 1 addition & 7 deletions tests/unit/test_scores_batch_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
CreateScoreBatchResults,
)
from langfuse.api.scores.types.create_score_request import CreateScoreRequest
from langfuse.api.scores.types.create_score_response import CreateScoreResponse

SINGLE_REQUEST = CreateScoreRequest(name="accuracy", value=0.9, trace_id="trace-1")
BATCH_REQUEST = [
CreateScoreRequest(name="accuracy", value=0.9, trace_id="trace-1"),
CreateScoreRequest(name="tone", value="friendly", trace_id="trace-1"),
]

CASES = [
pytest.param(SINGLE_REQUEST, 200, {"id": "score-1"}, id="single-200"),
pytest.param(BATCH_REQUEST, 202, {"message": "Accepted"}, id="batch-202"),
pytest.param(
BATCH_REQUEST,
Expand All @@ -52,10 +49,7 @@ def handle(request: httpx.Request) -> httpx.Response:


def _assert_parsed(response: Any, status: int, body: dict) -> None:
if status == 200:
assert isinstance(response, CreateScoreResponse)
assert response.id == body["id"]
elif status == 202:
if status == 202:
assert isinstance(response, CreateScoreBatchResponse)
assert response.message == "Accepted"
else:
Expand Down
Loading