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
2 changes: 2 additions & 0 deletions langfuse/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ServiceUnavailableError,
Session,
SessionWithTraces,
Sort,
Trace,
TraceBody,
TraceEvent,
Expand Down Expand Up @@ -149,6 +150,7 @@
"ServiceUnavailableError",
"Session",
"SessionWithTraces",
"Sort",
"Trace",
"TraceBody",
"TraceEvent",
Expand Down
3 changes: 2 additions & 1 deletion langfuse/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
from .projects import Project, Projects
from .prompts import CreatePromptRequest, Prompt
from .score import CreateScoreRequest, Scores
from .trace import Traces
from .trace import Sort, Traces

__all__ = [
"AccessDeniedError",
Expand Down Expand Up @@ -149,6 +149,7 @@
"ServiceUnavailableError",
"Session",
"SessionWithTraces",
"Sort",
"Trace",
"TraceBody",
"TraceEvent",
Expand Down
6 changes: 6 additions & 0 deletions langfuse/api/resources/commons/types/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Usage(pydantic.BaseModel):
output: typing.Optional[int] = None
total: typing.Optional[int] = None
unit: typing.Optional[ModelUsageUnit] = None
input_cost: typing.Optional[float] = pydantic.Field(alias="inputCost", default=None)
output_cost: typing.Optional[float] = pydantic.Field(
alias="outputCost", default=None
)
total_cost: typing.Optional[float] = pydantic.Field(alias="totalCost", default=None)

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
Expand All @@ -37,4 +42,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
class Config:
frozen = True
smart_union = True
allow_population_by_field_name = True
json_encoders = {dt.datetime: serialize_datetime}
4 changes: 2 additions & 2 deletions langfuse/api/resources/trace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was auto-generated by Fern from our API Definition.

from .types import Traces
from .types import Sort, Traces

__all__ = ["Traces"]
__all__ = ["Sort", "Traces"]
8 changes: 8 additions & 0 deletions langfuse/api/resources/trace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def list(
limit: typing.Optional[int] = None,
user_id: typing.Optional[str] = None,
name: typing.Optional[str] = None,
order_by: str,
tags: typing.Optional[typing.Union[str, typing.List[str]]] = None,
) -> Traces:
"""
Expand All @@ -82,6 +83,8 @@ def list(

- name: typing.Optional[str].

- order_by: str. Format of the string sort_by=timestamp.asc (id, timestamp, name, userId, release, version, public, bookmarked, sessionId)

- tags: typing.Optional[typing.Union[str, typing.List[str]]]. Only traces that include all of these tags will be returned.
"""
_response = self._client_wrapper.httpx_client.request(
Expand All @@ -95,6 +98,7 @@ def list(
"limit": limit,
"userId": user_id,
"name": name,
"orderBy": order_by,
"tags": tags,
}
),
Expand Down Expand Up @@ -169,6 +173,7 @@ async def list(
limit: typing.Optional[int] = None,
user_id: typing.Optional[str] = None,
name: typing.Optional[str] = None,
order_by: str,
tags: typing.Optional[typing.Union[str, typing.List[str]]] = None,
) -> Traces:
"""
Expand All @@ -183,6 +188,8 @@ async def list(

- name: typing.Optional[str].

- order_by: str. Format of the string sort_by=timestamp.asc (id, timestamp, name, userId, release, version, public, bookmarked, sessionId)

- tags: typing.Optional[typing.Union[str, typing.List[str]]]. Only traces that include all of these tags will be returned.
"""
_response = await self._client_wrapper.httpx_client.request(
Expand All @@ -196,6 +203,7 @@ async def list(
"limit": limit,
"userId": user_id,
"name": name,
"orderBy": order_by,
"tags": tags,
}
),
Expand Down
3 changes: 2 additions & 1 deletion langfuse/api/resources/trace/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file was auto-generated by Fern from our API Definition.

from .sort import Sort
from .traces import Traces

__all__ = ["Traces"]
__all__ = ["Sort", "Traces"]
36 changes: 36 additions & 0 deletions langfuse/api/resources/trace/types/sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ....core.datetime_utils import serialize_datetime

try:
import pydantic.v1 as pydantic # type: ignore
except ImportError:
import pydantic # type: ignore


class Sort(pydantic.BaseModel):
id: str

def json(self, **kwargs: typing.Any) -> str:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().json(**kwargs_with_defaults)

def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
kwargs_with_defaults: typing.Any = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
return super().dict(**kwargs_with_defaults)

class Config:
frozen = True
smart_union = True
json_encoders = {dt.datetime: serialize_datetime}
3 changes: 3 additions & 0 deletions langfuse/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ModelUsage(TypedDict):
input: Optional[int]
output: Optional[int]
total: Optional[int]
input_cost: Optional[float]
output_cost: Optional[float]
total_cost: Optional[float]


class PromptClient:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,15 @@ def test_create_generation():
[
LlmUsage(promptTokens=51, completionTokens=0, totalTokens=100),
LlmUsage(promptTokens=51, totalTokens=100),
{"input": 51, "output": 0, "total": 100, "unit": "TOKENS"},
{
"input": 51,
"output": 0,
"total": 100,
"unit": "TOKENS",
"input_cost": 100,
"output_cost": 200,
"total_cost": 300,
},
{"input": 51, "total": 100},
],
)
Expand Down