Skip to content

Commit 04d6576

Browse files
committed
cleanup
1 parent f0a3224 commit 04d6576

3 files changed

Lines changed: 6 additions & 30 deletions

File tree

langfuse/_client/attributes.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from datetime import datetime
1515
from typing import Any, Dict, List, Literal, Optional, Union
1616

17+
from langfuse._client.constants import ObservationTypeGenerationLike
18+
1719
from langfuse._utils.serializer import EventSerializer
1820
from langfuse.model import PromptClient
1921
from langfuse.types import MapValue, SpanLevel
@@ -123,17 +125,7 @@ def create_generation_attributes(
123125
usage_details: Optional[Dict[str, int]] = None,
124126
cost_details: Optional[Dict[str, float]] = None,
125127
prompt: Optional[PromptClient] = None,
126-
observation_type: Optional[
127-
Literal[
128-
"generation",
129-
"agent",
130-
"tool",
131-
"chain",
132-
"retriever",
133-
"evaluator",
134-
"embedding",
135-
]
136-
] = "generation",
128+
observation_type: Optional[ObservationTypeGenerationLike] = "generation",
137129
) -> dict:
138130
attributes = {
139131
LangfuseOtelSpanAttributes.OBSERVATION_TYPE: observation_type,

langfuse/_client/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
LANGFUSE_TRACER_NAME = "langfuse-sdk"
1010

1111

12+
"""Note: this type is used with .__args__ in some cases and therefore must remain flat"""
1213
ObservationTypeGenerationLike: TypeAlias = Literal[
1314
"generation",
1415
"agent",

langfuse/_client/span.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
ObservationTypeLiteral,
4646
ObservationTypeGenerationLike,
4747
ObservationTypeLiteralNoEvent,
48-
get_observation_types_list,
4948
)
5049
from langfuse.logger import langfuse_logger
5150
from langfuse.types import MapValue, ScoreDataType, SpanLevel
@@ -144,15 +143,7 @@ def __init__(
144143

145144
attributes = {}
146145

147-
if as_type in [
148-
"generation",
149-
"agent",
150-
"tool",
151-
"chain",
152-
"retriever",
153-
"evaluator",
154-
"embedding",
155-
]:
146+
if as_type in ObservationTypeGenerationLike.__args__:
156147
attributes = create_generation_attributes(
157148
input=media_processed_input,
158149
output=media_processed_output,
@@ -611,15 +602,7 @@ def update(
611602
self._otel_span.update_name(name)
612603

613604
# Use same logic as __init__ to determine which attributes to create
614-
if self._observation_type in [
615-
"generation",
616-
"agent",
617-
"tool",
618-
"chain",
619-
"retriever",
620-
"evaluator",
621-
"embedding",
622-
]:
605+
if self._observation_type in ObservationTypeGenerationLike.__args__:
623606
attributes = create_generation_attributes(
624607
input=processed_input,
625608
output=processed_output,

0 commit comments

Comments
 (0)