|
27 | 27 |
|
28 | 28 | from typing_extensions import ParamSpec |
29 | 29 |
|
| 30 | +from langfuse.api import UsageDetails |
30 | 31 | from langfuse.client import ( |
31 | 32 | Langfuse, |
32 | 33 | StatefulSpanClient, |
|
71 | 72 | "model": None, |
72 | 73 | "model_parameters": None, |
73 | 74 | "usage": None, |
| 75 | + "usage_details": None, |
| 76 | + "cost_details": None, |
74 | 77 | "prompt": None, |
75 | 78 | "public": None, |
76 | 79 | }, |
@@ -823,6 +826,8 @@ def update_current_observation( |
823 | 826 | model: Optional[str] = None, |
824 | 827 | model_parameters: Optional[Dict[str, MapValue]] = None, |
825 | 828 | usage: Optional[Union[BaseModel, ModelUsage]] = None, |
| 829 | + usage_details: Optional[UsageDetails] = None, |
| 830 | + cost_details: Optional[Dict[str, float]] = None, |
826 | 831 | prompt: Optional[PromptClient] = None, |
827 | 832 | public: Optional[bool] = None, |
828 | 833 | ): |
@@ -857,7 +862,9 @@ def update_current_observation( |
857 | 862 | Generation-specific params: |
858 | 863 | - `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. |
859 | 864 | - `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. |
861 | 868 | - `prompt`(Optional[PromptClient]): The prompt object used for the generation. |
862 | 869 |
|
863 | 870 | Returns: |
@@ -899,6 +906,8 @@ def update_current_observation( |
899 | 906 | "model": model, |
900 | 907 | "model_parameters": model_parameters, |
901 | 908 | "usage": usage, |
| 909 | + "usage_details": usage_details, |
| 910 | + "cost_details": cost_details, |
902 | 911 | "prompt": prompt, |
903 | 912 | "public": public, |
904 | 913 | }.items() |
|
0 commit comments