Skip to content

Commit b677d0a

Browse files
authored
feat(media): broaden content type support (#1011)
1 parent e5e3995 commit b677d0a

File tree

120 files changed

+4187
-1497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+4187
-1497
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
fail-fast: false
3939
matrix:
4040
python-version:
41-
- "3.8"
4241
- "3.9"
4342
- "3.10"
4443
- "3.11"
44+
4545
name: Test on Python version ${{ matrix.python-version }}
4646
steps:
4747
- uses: actions/checkout@v3
@@ -90,7 +90,7 @@ jobs:
9090
rm -rf .env
9191
9292
echo "::group::Run server"
93-
TELEMETRY_ENABLED=false CLICKHOUSE_CLUSTER_ENABLED=false LANGFUSE_ASYNC_INGESTION_PROCESSING=false LANGFUSE_ASYNC_CLICKHOUSE_INGESTION_PROCESSING=false LANGFUSE_READ_FROM_POSTGRES_ONLY=true LANGFUSE_READ_FROM_CLICKHOUSE_ONLY=false docker compose -f docker-compose.v3preview.yml up -d
93+
TELEMETRY_ENABLED=false CLICKHOUSE_CLUSTER_ENABLED=false LANGFUSE_ASYNC_INGESTION_PROCESSING=false LANGFUSE_ASYNC_CLICKHOUSE_INGESTION_PROCESSING=false LANGFUSE_READ_FROM_POSTGRES_ONLY=true LANGFUSE_RETURN_FROM_CLICKHOUSE=false docker compose -f docker-compose.v3preview.yml up -d
9494
echo "::endgroup::"
9595
9696
# Add this step to check the health of the container

langfuse/_task_manager/media_manager.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,52 @@ def _process_data_recursively(data: Any, level: int):
127127

128128
return media
129129

130+
# Anthropic
131+
if (
132+
isinstance(data, dict)
133+
and "type" in data
134+
and data["type"] == "base64"
135+
and "media_type" in data
136+
and "data" in data
137+
):
138+
media = LangfuseMedia(
139+
base64_data_uri=f"data:{data['media_type']};base64," + data["data"],
140+
)
141+
142+
self._process_media(
143+
media=media,
144+
trace_id=trace_id,
145+
observation_id=observation_id,
146+
field=field,
147+
)
148+
149+
data["data"] = media
150+
151+
return data
152+
153+
# Vertex
154+
if (
155+
isinstance(data, dict)
156+
and "type" in data
157+
and data["type"] == "media"
158+
and "mime_type" in data
159+
and "data" in data
160+
):
161+
media = LangfuseMedia(
162+
base64_data_uri=f"data:{data['mime_type']};base64," + data["data"],
163+
)
164+
165+
self._process_media(
166+
media=media,
167+
trace_id=trace_id,
168+
observation_id=observation_id,
169+
field=field,
170+
)
171+
172+
data["data"] = media
173+
174+
return data
175+
130176
if isinstance(data, list):
131177
return [_process_data_recursively(item, level + 1) for item in data]
132178

langfuse/api/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pip install finto
1616
Instantiate and use the client with the following:
1717

1818
```python
19-
from finto import CreateCommentRequest
20-
from finto.client import FernLangfuse
19+
from langfuse.api import CreateCommentRequest
20+
from langfuse.api.client import FernLangfuse
2121

2222
client = FernLangfuse(
2323
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -45,8 +45,8 @@ The SDK also exports an `async` client so that you can make non-blocking calls t
4545
```python
4646
import asyncio
4747

48-
from finto import CreateCommentRequest
49-
from finto.client import AsyncFernLangfuse
48+
from langfuse.api import CreateCommentRequest
49+
from langfuse.api.client import AsyncFernLangfuse
5050

5151
client = AsyncFernLangfuse(
5252
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -116,7 +116,7 @@ The SDK defaults to a 60 second timeout. You can configure this with a timeout o
116116

117117
```python
118118

119-
from finto.client import FernLangfuse
119+
from langfuse.api.client import FernLangfuse
120120

121121
client = FernLangfuse(..., { timeout=20.0 }, )
122122

@@ -131,9 +131,10 @@ client.comments.create(...,{
131131

132132
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
133133
and transports.
134+
134135
```python
135136
import httpx
136-
from finto.client import FernLangfuse
137+
from langfuse.api.client import FernLangfuse
137138

138139
client = FernLangfuse(
139140
...,

langfuse/api/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class FernLangfuse:
5151
5252
Examples
5353
--------
54-
from finto.client import FernLangfuse
54+
from langfuse.api.client import FernLangfuse
5555
5656
client = FernLangfuse(
5757
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -140,7 +140,7 @@ class AsyncFernLangfuse:
140140
141141
Examples
142142
--------
143-
from finto.client import AsyncFernLangfuse
143+
from langfuse.api.client import AsyncFernLangfuse
144144
145145
client = AsyncFernLangfuse(
146146
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",

langfuse/api/core/api_error.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class ApiError(Exception):
77
status_code: typing.Optional[int]
88
body: typing.Any
99

10-
def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None):
10+
def __init__(
11+
self, *, status_code: typing.Optional[int] = None, body: typing.Any = None
12+
):
1113
self.status_code = status_code
1214
self.body = body
1315

langfuse/api/core/client_wrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(
1717
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
1818
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
1919
base_url: str,
20-
timeout: typing.Optional[float] = None
20+
timeout: typing.Optional[float] = None,
2121
):
2222
self._x_langfuse_sdk_name = x_langfuse_sdk_name
2323
self._x_langfuse_sdk_version = x_langfuse_sdk_version
@@ -71,7 +71,7 @@ def __init__(
7171
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
7272
base_url: str,
7373
timeout: typing.Optional[float] = None,
74-
httpx_client: httpx.Client
74+
httpx_client: httpx.Client,
7575
):
7676
super().__init__(
7777
x_langfuse_sdk_name=x_langfuse_sdk_name,
@@ -101,7 +101,7 @@ def __init__(
101101
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
102102
base_url: str,
103103
timeout: typing.Optional[float] = None,
104-
httpx_client: httpx.AsyncClient
104+
httpx_client: httpx.AsyncClient,
105105
):
106106
super().__init__(
107107
x_langfuse_sdk_name=x_langfuse_sdk_name,

langfuse/api/core/datetime_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def serialize_datetime(v: dt.datetime) -> str:
1313
"""
1414

1515
def _serialize_zoned_datetime(v: dt.datetime) -> str:
16-
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
16+
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(
17+
None
18+
):
1719
# UTC is a special case where we use "Z" at the end instead of "+00:00"
1820
return v.isoformat().replace("+00:00", "Z")
1921
else:

langfuse/api/core/file.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
# (filename, file (or bytes), content_type)
1414
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]],
1515
# (filename, file (or bytes), content_type, headers)
16-
typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str], typing.Mapping[str, str]],
16+
typing.Tuple[
17+
typing.Optional[str],
18+
FileContent,
19+
typing.Optional[str],
20+
typing.Mapping[str, str],
21+
],
1722
]
1823

1924

2025
def convert_file_dict_to_httpx_tuples(
21-
d: typing.Dict[str, typing.Union[File, typing.List[File]]]
26+
d: typing.Dict[str, typing.Union[File, typing.List[File]]],
2227
) -> typing.List[typing.Tuple[str, File]]:
2328
"""
2429
The format we use is a list of tuples, where the first element is the

0 commit comments

Comments
 (0)