FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(api): update API spec from langfuse/langfuse 8242934 (#1790) · codechrl/langfuse-python@87f47ab · GitHub

Commit 87f47ab

Browse files
andauthored
feat(api): update API spec from langfuse/langfuse 8242934 (langfuse#1790)
Co-authored-by: langfuse-bot <langfuse-bot@langfuse.com>
1 parent 370039d commit 87f47ab

19 files changed

Lines changed: 831 additions & 699 deletions

‎langfuse/api/__init__.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@
305305
UpdateScoreConfigRequest,
306306
)
307307
from .scores import (
308+
CreateScoreRequest,
309+
CreateScoreResponse,
310+
CreateScoreSource,
308311
GetScoresResponse,
309312
GetScoresResponseData,
310313
GetScoresResponseDataBoolean,
@@ -411,6 +414,9 @@
411414
"CreateObservationEvent": ".ingestion",
412415
"CreatePromptRequest": ".prompts",
413416
"CreateScoreConfigRequest": ".score_configs",
417+
"CreateScoreRequest": ".scores",
418+
"CreateScoreResponse": ".scores",
419+
"CreateScoreSource": ".scores",
414420
"CreateScoreValue": ".commons",
415421
"CreateSpanBody": ".ingestion",
416422
"CreateSpanEvent": ".ingestion",
@@ -749,6 +755,9 @@ def __dir__():
749755
"CreateObservationEvent",
750756
"CreatePromptRequest",
751757
"CreateScoreConfigRequest",
758+
"CreateScoreRequest",
759+
"CreateScoreResponse",
760+
"CreateScoreSource",
752761
"CreateScoreValue",
753762
"CreateSpanBody",
754763
"CreateSpanEvent",

‎langfuse/api/commons/types/observation_v2.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,23 @@ class ObservationV2(UniversalBaseModel):
5353
typing.Optional[str], FieldMetadata(alias="parentObservationId")
5454
] = pydantic.Field(default=None)
5555
"""
56-
The parent observation ID
56+
The physical parent observation ID, if present.
57+
Observations marked as app roots by the SDK may retain a non-null parent ID.
5758
"""
5859

5960
type: str = pydantic.Field()
6061
"""
6162
The type of the observation (e.g. GENERATION, SPAN, EVENT)
6263
"""
6364

65+
is_root_observation: typing_extensions.Annotated[
66+
typing.Optional[bool], FieldMetadata(alias="isRootObservation")
67+
] = pydantic.Field(default=None)
68+
"""
69+
Whether this observation is a logical root.
70+
This is true for observations without a physical parent and observations marked as app roots by the SDK.
71+
"""
72+
6473
name: typing.Optional[str] = pydantic.Field(default=None)
6574
"""
6675
The name of the observation

‎langfuse/api/legacy/__init__.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
from . import metrics_v1, observations_v1, score_v1
1010
from .metrics_v1 import MetricsResponse
1111
from .observations_v1 import Observations, ObservationsViews
12-
from .score_v1 import CreateScoreRequest, CreateScoreResponse, CreateScoreSource
1312
_dynamic_imports: typing.Dict[str, str] = {
14-
"CreateScoreRequest": ".score_v1",
15-
"CreateScoreResponse": ".score_v1",
16-
"CreateScoreSource": ".score_v1",
1713
"MetricsResponse": ".metrics_v1",
1814
"Observations": ".observations_v1",
1915
"ObservationsViews": ".observations_v1",
@@ -51,13 +47,17 @@ def __dir__():
5147

5248

5349
__all__ = [
54-
"CreateScoreRequest",
55-
"CreateScoreResponse",
56-
"CreateScoreSource",
5750
"MetricsResponse",
5851
"Observations",
5952
"ObservationsViews",
6053
"metrics_v1",
6154
"observations_v1",
6255
"score_v1",
6356
]
57+
58+
# Score-create compatibility aliases (LFE-10397).
59+
from .score_v1 import CreateScoreRequest
60+
from .score_v1 import CreateScoreResponse
61+
from .score_v1 import CreateScoreSource
62+
63+
__all__ = [*__all__, "CreateScoreRequest", "CreateScoreResponse", "CreateScoreSource"]

‎langfuse/api/legacy/score_v1/__init__.py‎

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,9 @@
22

33
# isort: skip_file
44

5-
import typing
6-
from importlib import import_module
7-
8-
if typing.TYPE_CHECKING:
9-
from .types import CreateScoreRequest, CreateScoreResponse, CreateScoreSource
10-
_dynamic_imports: typing.Dict[str, str] = {
11-
"CreateScoreRequest": ".types",
12-
"CreateScoreResponse": ".types",
13-
"CreateScoreSource": ".types",
14-
}
15-
16-
17-
def __getattr__(attr_name: str) -> typing.Any:
18-
module_name = _dynamic_imports.get(attr_name)
19-
if module_name is None:
20-
raise AttributeError(
21-
f"No {attr_name} found in _dynamic_imports for module name -> {__name__}"
22-
)
23-
try:
24-
module = import_module(module_name, __package__)
25-
if module_name == f".{attr_name}":
26-
return module
27-
else:
28-
return getattr(module, attr_name)
29-
except ImportError as e:
30-
raise ImportError(
31-
f"Failed to import {attr_name} from {module_name}: {e}"
32-
) from e
33-
except AttributeError as e:
34-
raise AttributeError(
35-
f"Failed to get {attr_name} from {module_name}: {e}"
36-
) from e
37-
38-
39-
def __dir__():
40-
lazy_attrs = list(_dynamic_imports.keys())
41-
return sorted(lazy_attrs)
42-
5+
# Score-create compatibility aliases (LFE-10397).
6+
from .types import CreateScoreRequest
7+
from .types import CreateScoreResponse
8+
from .types import CreateScoreSource
439

4410
__all__ = ["CreateScoreRequest", "CreateScoreResponse", "CreateScoreSource"]

‎langfuse/api/legacy/score_v1/client.py‎

Lines changed: 16 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
import typing
44

5+
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
56
from ...commons.types.create_score_value import CreateScoreValue
67
from ...commons.types.score_data_type import ScoreDataType
7-
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8+
from ...scores.client import (
9+
AsyncScoresClient as CanonicalAsyncScoresClient,
10+
ScoresClient as CanonicalScoresClient,
11+
OMIT,
12+
)
13+
from ...scores.types.create_score_response import CreateScoreResponse
14+
from ...scores.types.create_score_source import CreateScoreSource
815
from ...core.request_options import RequestOptions
916
from .raw_client import AsyncRawScoreV1Client, RawScoreV1Client
10-
from .types.create_score_response import CreateScoreResponse
11-
from .types.create_score_source import CreateScoreSource
12-
13-
# this is used as the default value for optional parameters
14-
OMIT = typing.cast(typing.Any, ...)
1517

1618

1719
class ScoreV1Client:
@@ -48,70 +50,10 @@ def create(
4850
source: typing.Optional[CreateScoreSource] = OMIT,
4951
request_options: typing.Optional[RequestOptions] = None,
5052
) -> CreateScoreResponse:
51-
"""
52-
Create a score (supports both trace and session scores)
53-
54-
Parameters
55-
----------
56-
name : str
57-
58-
value : CreateScoreValue
59-
The value of the score. Must be passed as string for categorical and text scores, and numeric for boolean and numeric scores. Boolean score values must equal either 1 or 0 (true or false). Text score values must be between 1 and 500 characters.
60-
61-
id : typing.Optional[str]
62-
63-
trace_id : typing.Optional[str]
64-
65-
session_id : typing.Optional[str]
66-
67-
observation_id : typing.Optional[str]
68-
69-
dataset_run_id : typing.Optional[str]
70-
71-
comment : typing.Optional[str]
72-
73-
metadata : typing.Optional[typing.Dict[str, typing.Any]]
74-
75-
environment : typing.Optional[str]
76-
The environment of the score. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
77-
78-
queue_id : typing.Optional[str]
79-
The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
80-
81-
data_type : typing.Optional[ScoreDataType]
82-
The data type of the score. When passing a configId this field is inferred. Otherwise, this field must be passed or will default to numeric.
83-
84-
config_id : typing.Optional[str]
85-
Reference a score config on a score. The unique langfuse identifier of a score config. When passing this field, the dataType and stringValue fields are automatically populated.
86-
87-
source : typing.Optional[CreateScoreSource]
88-
The source of the score. Defaults to API. Set to ANNOTATION to prefill scores (e.g. from an LLM) for a human reviewer to verify in an annotation queue. When source is ANNOTATION, a configId is required unless dataType is CORRECTION. EVAL is reserved for internal evaluator outputs and is not accepted on this endpoint.
89-
90-
request_options : typing.Optional[RequestOptions]
91-
Request-specific configuration.
92-
93-
Returns
94-
-------
95-
CreateScoreResponse
96-
97-
Examples
98-
--------
99-
from langfuse import LangfuseAPI
100-
101-
client = LangfuseAPI(
102-
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
103-
x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
104-
x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
105-
username="YOUR_USERNAME",
106-
password="YOUR_PASSWORD",
107-
base_url="https://yourhost.com/path/to/api",
108-
)
109-
client.legacy.score_v1.create(
110-
name="name",
111-
value=1.1,
112-
)
113-
"""
114-
_response = self._raw_client.create(
53+
"""**Deprecated compatibility alias.** Use ``client.scores.create``."""
54+
return CanonicalScoresClient(
55+
client_wrapper=self._raw_client._client_wrapper
56+
).create(
11557
name=name,
11658
value=value,
11759
id=id,
@@ -128,7 +70,6 @@ def create(
12870
source=source,
12971
request_options=request_options,
13072
)
131-
return _response.data
13273

13374
def delete(
13475
self, score_id: str, *, request_options: typing.Optional[RequestOptions] = None
@@ -202,78 +143,10 @@ async def create(
202143
source: typing.Optional[CreateScoreSource] = OMIT,
203144
request_options: typing.Optional[RequestOptions] = None,
204145
) -> CreateScoreResponse:
205-
"""
206-
Create a score (supports both trace and session scores)
207-
208-
Parameters
209-
----------
210-
name : str
211-
212-
value : CreateScoreValue
213-
The value of the score. Must be passed as string for categorical and text scores, and numeric for boolean and numeric scores. Boolean score values must equal either 1 or 0 (true or false). Text score values must be between 1 and 500 characters.
214-
215-
id : typing.Optional[str]
216-
217-
trace_id : typing.Optional[str]
218-
219-
session_id : typing.Optional[str]
220-
221-
observation_id : typing.Optional[str]
222-
223-
dataset_run_id : typing.Optional[str]
224-
225-
comment : typing.Optional[str]
226-
227-
metadata : typing.Optional[typing.Dict[str, typing.Any]]
228-
229-
environment : typing.Optional[str]
230-
The environment of the score. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
231-
232-
queue_id : typing.Optional[str]
233-
The annotation queue referenced by the score. Indicates if score was initially created while processing annotation queue.
234-
235-
data_type : typing.Optional[ScoreDataType]
236-
The data type of the score. When passing a configId this field is inferred. Otherwise, this field must be passed or will default to numeric.
237-
238-
config_id : typing.Optional[str]
239-
Reference a score config on a score. The unique langfuse identifier of a score config. When passing this field, the dataType and stringValue fields are automatically populated.
240-
241-
source : typing.Optional[CreateScoreSource]
242-
The source of the score. Defaults to API. Set to ANNOTATION to prefill scores (e.g. from an LLM) for a human reviewer to verify in an annotation queue. When source is ANNOTATION, a configId is required unless dataType is CORRECTION. EVAL is reserved for internal evaluator outputs and is not accepted on this endpoint.
243-
244-
request_options : typing.Optional[RequestOptions]
245-
Request-specific configuration.
246-
247-
Returns
248-
-------
249-
CreateScoreResponse
250-
251-
Examples
252-
--------
253-
import asyncio
254-
255-
from langfuse import AsyncLangfuseAPI
256-
257-
client = AsyncLangfuseAPI(
258-
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
259-
x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
260-
x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
261-
username="YOUR_USERNAME",
262-
password="YOUR_PASSWORD",
263-
base_url="https://yourhost.com/path/to/api",
264-
)
265-
266-
267-
async def main() -> None:
268-
await client.legacy.score_v1.create(
269-
name="name",
270-
value=1.1,
271-
)
272-
273-
274-
asyncio.run(main())
275-
"""
276-
_response = await self._raw_client.create(
146+
"""**Deprecated compatibility alias.** Use ``client.scores.create``."""
147+
return await CanonicalAsyncScoresClient(
148+
client_wrapper=self._raw_client._client_wrapper
149+
).create(
277150
name=name,
278151
value=value,
279152
id=id,
@@ -290,7 +163,6 @@ async def main() -> None:
290163
source=source,
291164
request_options=request_options,
292165
)
293-
return _response.data
294166

295167
async def delete(
296168
self, score_id: str, *, request_options: typing.Optional[RequestOptions] = None

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL