langfuse.types

@private

 1"""@private"""
 2
 3from datetime import datetime
 4from typing import Any, Dict, List, Literal, Optional, Protocol, TypedDict, Union
 5
 6from pydantic import BaseModel
 7from langfuse.api import MediaContentType, UsageDetails
 8from langfuse.model import MapValue, ModelUsage, PromptClient
 9
10SpanLevel = Literal["DEBUG", "DEFAULT", "WARNING", "ERROR"]
11
12ScoreDataType = Literal["NUMERIC", "CATEGORICAL", "BOOLEAN"]
13
14
15class TraceMetadata(TypedDict):
16    name: Optional[str]
17    user_id: Optional[str]
18    session_id: Optional[str]
19    version: Optional[str]
20    release: Optional[str]
21    metadata: Optional[Any]
22    tags: Optional[List[str]]
23    public: Optional[bool]
24
25
26class ObservationParams(TraceMetadata, TypedDict):
27    input: Optional[Any]
28    output: Optional[Any]
29    level: Optional[SpanLevel]
30    status_message: Optional[str]
31    start_time: Optional[datetime]
32    end_time: Optional[datetime]
33    completion_start_time: Optional[datetime]
34    model: Optional[str]
35    model_parameters: Optional[Dict[str, MapValue]]
36    usage: Optional[Union[BaseModel, ModelUsage]]
37    usage_details: Optional[UsageDetails]
38    cost_details: Optional[Dict[str, float]]
39    prompt: Optional[PromptClient]
40
41
42class MaskFunction(Protocol):
43    """A function that masks data.
44
45    Keyword Args:
46        data: The data to mask.
47
48    Returns:
49        The masked data that must be serializable to JSON.
50    """
51
52    def __call__(self, *, data: Any) -> Any: ...
53
54
55class ParsedMediaReference(TypedDict):
56    """A parsed media reference.
57
58    Attributes:
59        media_id: The media ID.
60        source: The original source of the media, e.g. a file path, bytes, base64 data URI, etc.
61        content_type: The content type of the media.
62    """
63
64    media_id: str
65    source: str
66    content_type: MediaContentType
SpanLevel = typing.Literal['DEBUG', 'DEFAULT', 'WARNING', 'ERROR']
ScoreDataType = typing.Literal['NUMERIC', 'CATEGORICAL', 'BOOLEAN']
class TraceMetadata(typing.TypedDict):
16class TraceMetadata(TypedDict):
17    name: Optional[str]
18    user_id: Optional[str]
19    session_id: Optional[str]
20    version: Optional[str]
21    release: Optional[str]
22    metadata: Optional[Any]
23    tags: Optional[List[str]]
24    public: Optional[bool]
name: Optional[str]
user_id: Optional[str]
session_id: Optional[str]
version: Optional[str]
release: Optional[str]
metadata: Optional[Any]
tags: Optional[List[str]]
public: Optional[bool]
class ObservationParams(TraceMetadata, typing.TypedDict):
27class ObservationParams(TraceMetadata, TypedDict):
28    input: Optional[Any]
29    output: Optional[Any]
30    level: Optional[SpanLevel]
31    status_message: Optional[str]
32    start_time: Optional[datetime]
33    end_time: Optional[datetime]
34    completion_start_time: Optional[datetime]
35    model: Optional[str]
36    model_parameters: Optional[Dict[str, MapValue]]
37    usage: Optional[Union[BaseModel, ModelUsage]]
38    usage_details: Optional[UsageDetails]
39    cost_details: Optional[Dict[str, float]]
40    prompt: Optional[PromptClient]
input: Optional[Any]
output: Optional[Any]
level: Optional[Literal['DEBUG', 'DEFAULT', 'WARNING', 'ERROR']]
status_message: Optional[str]
start_time: Optional[datetime.datetime]
end_time: Optional[datetime.datetime]
completion_start_time: Optional[datetime.datetime]
model: Optional[str]
model_parameters: Optional[Dict[str, Union[str, NoneType, int, bool, List[str]]]]
usage: Union[pydantic.main.BaseModel, langfuse.model.ModelUsage, NoneType]
usage_details: Union[Dict[str, int], langfuse.api.OpenAiUsageSchema, NoneType]
cost_details: Optional[Dict[str, float]]
class MaskFunction(typing.Protocol):
43class MaskFunction(Protocol):
44    """A function that masks data.
45
46    Keyword Args:
47        data: The data to mask.
48
49    Returns:
50        The masked data that must be serializable to JSON.
51    """
52
53    def __call__(self, *, data: Any) -> Any: ...

A function that masks data.

Keyword Args:

data: The data to mask.

Returns:

The masked data that must be serializable to JSON.

MaskFunction(*args, **kwargs)
1927def _no_init_or_replace_init(self, *args, **kwargs):
1928    cls = type(self)
1929
1930    if cls._is_protocol:
1931        raise TypeError('Protocols cannot be instantiated')
1932
1933    # Already using a custom `__init__`. No need to calculate correct
1934    # `__init__` to call. This can lead to RecursionError. See bpo-45121.
1935    if cls.__init__ is not _no_init_or_replace_init:
1936        return
1937
1938    # Initially, `__init__` of a protocol subclass is set to `_no_init_or_replace_init`.
1939    # The first instantiation of the subclass will call `_no_init_or_replace_init` which
1940    # searches for a proper new `__init__` in the MRO. The new `__init__`
1941    # replaces the subclass' old `__init__` (ie `_no_init_or_replace_init`). Subsequent
1942    # instantiation of the protocol subclass will thus use the new
1943    # `__init__` and no longer call `_no_init_or_replace_init`.
1944    for base in cls.__mro__:
1945        init = base.__dict__.get('__init__', _no_init_or_replace_init)
1946        if init is not _no_init_or_replace_init:
1947            cls.__init__ = init
1948            break
1949    else:
1950        # should not happen
1951        cls.__init__ = object.__init__
1952
1953    cls.__init__(self, *args, **kwargs)
class ParsedMediaReference(typing.TypedDict):
56class ParsedMediaReference(TypedDict):
57    """A parsed media reference.
58
59    Attributes:
60        media_id: The media ID.
61        source: The original source of the media, e.g. a file path, bytes, base64 data URI, etc.
62        content_type: The content type of the media.
63    """
64
65    media_id: str
66    source: str
67    content_type: MediaContentType

A parsed media reference.

Attributes:
  • media_id: The media ID.
  • source: The original source of the media, e.g. a file path, bytes, base64 data URI, etc.
  • content_type: The content type of the media.
media_id: str
source: str