Skip to content

Commit b888074

Browse files
authored
Merge branch 'main' into fix/control-flow-exception-check-in-error-handlers
2 parents 526832d + 5974a46 commit b888074

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

langfuse/openai.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ def _extract_streamed_response_api_response(chunks: Any) -> Any:
591591
for raw_chunk in chunks:
592592
chunk = raw_chunk.__dict__
593593
if raw_response := chunk.get("response", None):
594-
usage = chunk.get("usage", None)
594+
usage = chunk.get("usage", None) or getattr(raw_response, "usage", None)
595+
595596
response = raw_response.__dict__
596597
model = response.get("model")
597598

@@ -613,7 +614,7 @@ def _extract_streamed_response_api_response(chunks: Any) -> Any:
613614

614615
def _extract_streamed_openai_response(resource: Any, chunks: Any) -> Any:
615616
completion: Any = defaultdict(lambda: None) if resource.type == "chat" else ""
616-
model, usage = None, None
617+
model, usage, finish_reason = None, None, None
617618

618619
for chunk in chunks:
619620
if _is_openai_v1():
@@ -629,6 +630,7 @@ def _extract_streamed_openai_response(resource: Any, chunks: Any) -> Any:
629630
choice = choice.__dict__
630631
if resource.type == "chat":
631632
delta = choice.get("delta", None)
633+
finish_reason = choice.get("finish_reason", None)
632634

633635
if _is_openai_v1():
634636
delta = delta.__dict__
@@ -727,7 +729,7 @@ def get_response_for_chat() -> Any:
727729
model,
728730
get_response_for_chat() if resource.type == "chat" else completion,
729731
usage,
730-
None,
732+
{"finish_reason": finish_reason} if finish_reason is not None else None,
731733
)
732734

733735

langfuse/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""@private"""
22

3-
__version__ = "3.14.1"
3+
__version__ = "3.14.3"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "langfuse"
33

4-
version = "3.14.1"
4+
version = "3.14.3"
55
description = "A client library for accessing langfuse"
66
authors = ["langfuse <developers@langfuse.com>"]
77
license = "MIT"

0 commit comments

Comments
 (0)