mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
Fix: v0.26.1 model provider (#16073)
### What problem does this PR solve? Fix: - Pass session_id to langfuse. - Get correct status for add model_type. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -140,6 +140,22 @@ class _StubRetriever:
|
||||
return answer, set()
|
||||
|
||||
|
||||
class _FakePropagateAttributesContext:
|
||||
"""No-op context manager for fake propagate_attributes."""
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
def _fake_propagate_attributes(**kwargs):
|
||||
"""Fake propagate_attributes (Langfuse v4) that records kwargs and returns a no-op context manager."""
|
||||
_propagate_attributes_calls.append(kwargs)
|
||||
return _FakePropagateAttributesContext()
|
||||
|
||||
|
||||
class _FakeLangfuseObservation:
|
||||
def __init__(self):
|
||||
self.updates = []
|
||||
@@ -152,6 +168,9 @@ class _FakeLangfuseObservation:
|
||||
self.ended = True
|
||||
|
||||
|
||||
_propagate_attributes_calls = []
|
||||
|
||||
|
||||
class _FakeLangfuseClient:
|
||||
instances = []
|
||||
fail_start_observation = False
|
||||
@@ -460,6 +479,8 @@ def test_async_chat_langfuse_uses_start_observation(monkeypatch):
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(dialog_service, "Langfuse", _FakeLangfuseClient)
|
||||
_propagate_attributes_calls.clear()
|
||||
monkeypatch.setattr(dialog_service, "propagate_attributes", _fake_propagate_attributes)
|
||||
monkeypatch.setattr(
|
||||
dialog_service,
|
||||
"get_models",
|
||||
@@ -504,6 +525,7 @@ def test_async_chat_langfuse_uses_start_observation(monkeypatch):
|
||||
@pytest.mark.p2
|
||||
def test_async_chat_langfuse_observation_includes_session_id(monkeypatch):
|
||||
_FakeLangfuseClient.instances = []
|
||||
_propagate_attributes_calls.clear()
|
||||
monkeypatch.setattr(_FakeLangfuseClient, "fail_start_observation", False)
|
||||
chat_mdl = _StreamingChatModel("Session traces should be grouped.")
|
||||
retriever = _StubRetriever()
|
||||
@@ -526,6 +548,7 @@ def test_async_chat_langfuse_observation_includes_session_id(monkeypatch):
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(dialog_service, "Langfuse", _FakeLangfuseClient)
|
||||
monkeypatch.setattr(dialog_service, "propagate_attributes", _fake_propagate_attributes)
|
||||
monkeypatch.setattr(
|
||||
dialog_service,
|
||||
"get_models",
|
||||
@@ -553,7 +576,7 @@ def test_async_chat_langfuse_observation_includes_session_id(monkeypatch):
|
||||
assert any(e.get("final") is True for e in events)
|
||||
langfuse = _FakeLangfuseClient.instances[0]
|
||||
assert langfuse.observation_kwargs["trace_context"] == {"trace_id": "trace-id"}
|
||||
assert langfuse.observation_kwargs["session_id"] == "session-1"
|
||||
assert _propagate_attributes_calls[0]["session_id"] == "session-1"
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
@@ -629,6 +652,8 @@ def test_async_chat_continues_when_langfuse_observation_start_fails(monkeypatch)
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(dialog_service, "Langfuse", _FakeLangfuseClient)
|
||||
_propagate_attributes_calls.clear()
|
||||
monkeypatch.setattr(dialog_service, "propagate_attributes", _fake_propagate_attributes)
|
||||
monkeypatch.setattr(
|
||||
dialog_service,
|
||||
"get_models",
|
||||
|
||||
Reference in New Issue
Block a user