Skip to content

Commit 20e86f9

Browse files
committed
add decorator support
1 parent 652fd2e commit 20e86f9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

langfuse/decorators/langfuse_decorator.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from typing_extensions import ParamSpec
2929

30+
from langfuse.api import UsageDetails
3031
from langfuse.client import (
3132
Langfuse,
3233
StatefulSpanClient,
@@ -71,6 +72,8 @@
7172
"model": None,
7273
"model_parameters": None,
7374
"usage": None,
75+
"usage_details": None,
76+
"cost_details": None,
7477
"prompt": None,
7578
"public": None,
7679
},
@@ -823,6 +826,8 @@ def update_current_observation(
823826
model: Optional[str] = None,
824827
model_parameters: Optional[Dict[str, MapValue]] = None,
825828
usage: Optional[Union[BaseModel, ModelUsage]] = None,
829+
usage_details: Optional[UsageDetails] = None,
830+
cost_details: Optional[Dict[str, float]] = None,
826831
prompt: Optional[PromptClient] = None,
827832
public: Optional[bool] = None,
828833
):
@@ -857,7 +862,9 @@ def update_current_observation(
857862
Generation-specific params:
858863
- `completion_start_time` (Optional[datetime]): The time at which the completion started (streaming). Set it to get latency analytics broken down into time until completion started and completion duration.
859864
- `model_parameters` (Optional[Dict[str, MapValue]]): The parameters of the model used for the generation; can be any key-value pairs.
860-
- `usage` (Optional[Union[BaseModel, ModelUsage]]): The usage object supports the OpenAi structure with {promptTokens, completionTokens, totalTokens} and a more generic version {input, output, total, unit, inputCost, outputCost, totalCost} where unit can be of value "TOKENS", "CHARACTERS", "MILLISECONDS", "SECONDS", or "IMAGES". Refer to the docs on how to automatically infer token usage and costs in Langfuse.
865+
- `usage` (Optional[Union[BaseModel, ModelUsage]]): (Deprecated. Use `usage_details` and `cost_details` instead.) The usage object supports the OpenAi structure with {promptTokens, completionTokens, totalTokens} and a more generic version {input, output, total, unit, inputCost, outputCost, totalCost} where unit can be of value "TOKENS", "CHARACTERS", "MILLISECONDS", "SECONDS", or "IMAGES". Refer to the docs on how to automatically infer token usage and costs in Langfuse.
866+
- `usage_details` (Optional[Dict[str, int]]): The usage details of the observation. Reflects the number of units consumed per usage type. All keys must sum up to the total key value. The total key holds the total number of units consumed.
867+
- `cost_details` (Optional[Dict[str, float]]): The cost details of the observation. Reflects the USD cost of the observation per cost type. All keys must sum up to the total key value. The total key holds the total cost of the observation.
861868
- `prompt`(Optional[PromptClient]): The prompt object used for the generation.
862869
863870
Returns:
@@ -899,6 +906,8 @@ def update_current_observation(
899906
"model": model,
900907
"model_parameters": model_parameters,
901908
"usage": usage,
909+
"usage_details": usage_details,
910+
"cost_details": cost_details,
902911
"prompt": prompt,
903912
"public": public,
904913
}.items()

langfuse/types/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, Dict, List, Literal, Optional, Protocol, TypedDict, Union
55

66
from pydantic import BaseModel
7-
from langfuse.api import MediaContentType
7+
from langfuse.api import MediaContentType, UsageDetails
88
from langfuse.model import MapValue, ModelUsage, PromptClient
99

1010
SpanLevel = Literal["DEBUG", "DEFAULT", "WARNING", "ERROR"]
@@ -34,6 +34,8 @@ class ObservationParams(TraceMetadata, TypedDict):
3434
model: Optional[str]
3535
model_parameters: Optional[Dict[str, MapValue]]
3636
usage: Optional[Union[BaseModel, ModelUsage]]
37+
usage_details: Optional[UsageDetails]
38+
cost_details: Optional[Dict[str, float]]
3739
prompt: Optional[PromptClient]
3840

3941

0 commit comments

Comments
 (0)