This commit is contained in:
eviltik 2026-10-19 19:55:05 +00:00 • committed by GitHub
commit 8440d6bbbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -815,6 +815,7 @@ def _output_choices(response: Mapping[str, object]) -> tuple[Mapping[str, object
or _search_choices(response)
or _image_choices(response)
or _binary_choices(response)
or _passthrough_choices(response)
)
@ -924,6 +925,13 @@ def _image_location(item: Mapping[str, object]) -> str | None:
return f"b64_json image ({len(encoded) * 3 // 4 - encoded[-2:].count('=')} bytes)"
def _passthrough_choices(response: Mapping[str, object]) -> tuple[_Choice, ...]:
body: Final = response.get("response")
mapping: Final = as_str_mapping(body)
text: Final = json.dumps(dict(mapping)) if mapping is not None else as_str(body)
return (_text_choice(text),) if text else ()
def _binary_choices(response: Mapping[str, object]) -> tuple[_Choice, ...]:
size: Final = as_int(response.get("num_bytes"))
if size is None:

View file

@ -702,6 +702,8 @@ def test_langfuse_mapper_renders_an_ocr_call_with_the_page_markdown_as_output():
("amoderation", {"results": [{"flagged": True, "categories": {"violence": True}}]}, "flagged: violence"),
("aimage_generation", {"data": [{"b64_json": "QUJDRA=="}]}, "b64_json image (4 bytes)"),
("aspeech", {"object": "binary", "content_type": "audio/mpeg", "num_bytes": 9}, "audio/mpeg (9 bytes)"),
("pass_through_endpoint", {"response": '{"answers": {"q": 0.9}}'}, '{"answers": {"q": 0.9}}'),
("pass_through_endpoint", {"response": {"answers": {"q": 0.9}}}, '{"answers": {"q": 0.9}}'),
],
)
def test_langfuse_mapper_renders_every_non_chat_route_output_as_an_assistant_message(