diff --git a/ols/app/endpoints/feedback.py b/ols/app/endpoints/feedback.py index 4a604dc57..f99a11c8b 100644 --- a/ols/app/endpoints/feedback.py +++ b/ols/app/endpoints/feedback.py @@ -66,7 +66,12 @@ def store_feedback(user_id: str, feedback: dict) -> None: storage_path.mkdir(parents=True, exist_ok=True) current_time = str(datetime.utcnow()) - data_to_store = {"user_id": user_id, "timestamp": current_time, **feedback} + data_to_store = { + "user_id": user_id, + "timestamp": current_time, + "ols_config": config.ols_config.model_dump(), + **feedback + } # stores feedback in a file under unique uuid feedback_file_path = storage_path / f"{get_suid()}.json" diff --git a/ols/app/endpoints/ols.py b/ols/app/endpoints/ols.py index 7c1f77277..8ff59feed 100644 --- a/ols/app/endpoints/ols.py +++ b/ols/app/endpoints/ols.py @@ -840,6 +840,7 @@ def store_transcript( "truncated": truncated, "tool_calls": merge_tools_info(tool_calls, tool_results), "attachments": [attachment.model_dump() for attachment in attachments], + "ols_config": config.ols_config.model_dump(), } # stores feedback in a file under unique uuid diff --git a/tests/unit/app/endpoints/test_feedback.py b/tests/unit/app/endpoints/test_feedback.py index 7d4d68c24..57ab27b1a 100644 --- a/tests/unit/app/endpoints/test_feedback.py +++ b/tests/unit/app/endpoints/test_feedback.py @@ -59,8 +59,41 @@ def test_store_feedback(feedback_location): feedback.store_feedback(user_id, feedback_data) stored_data = load_fake_feedback("fake-uuid") - assert stored_data == { + expected_data = { "user_id": "12345678-abcd-0000-0123-456789abcdef", "timestamp": "2000-01-01 01:23:45", + "ols_config": config.ols_config.model_dump(), **feedback_data, } + assert stored_data == expected_data + + +def test_store_feedback_includes_ols_config(feedback_location): + """Test that ols_config is included in stored feedback.""" + user_id = "test-user-id" + feedback_data = {"rating": 5, "comment": "Great response"} + + with patch("ols.app.endpoints.feedback.datetime") as mocked_datetime: + mocked_datetime.utcnow = lambda: datetime(2023, 5, 1, 12, 0, 0) + with patch("ols.app.endpoints.feedback.get_suid", return_value="test-uuid"): + feedback.store_feedback(user_id, feedback_data) + + stored_data = load_fake_feedback("test-uuid") + + # Verify ols_config is present + assert "ols_config" in stored_data + + # Verify ols_config contains expected configuration data + ols_config_in_feedback = stored_data["ols_config"] + expected_ols_config = config.ols_config.model_dump() + assert ols_config_in_feedback == expected_ols_config + + # Verify it contains key configuration sections + assert "default_provider" in ols_config_in_feedback + assert "default_model" in ols_config_in_feedback + assert "user_data_collection" in ols_config_in_feedback + + # Verify other feedback data is still present + assert stored_data["user_id"] == user_id + assert stored_data["rating"] == 5 + assert stored_data["comment"] == "Great response" diff --git a/tests/unit/app/endpoints/test_ols.py b/tests/unit/app/endpoints/test_ols.py index ae28ae214..c0d2dbd01 100644 --- a/tests/unit/app/endpoints/test_ols.py +++ b/tests/unit/app/endpoints/test_ols.py @@ -1035,7 +1035,7 @@ def test_store_transcript(transcripts_location): # we don't really care about the timestamp, so let's just set it to # a fixed value transcript["metadata"]["timestamp"] = "fake-timestamp" - assert transcript == { + expected_transcript = { "metadata": { "provider": None, "model": None, @@ -1069,7 +1069,59 @@ def test_store_transcript(transcripts_location): "content": "this is attachment", } ], + "ols_config": config.ols_config.model_dump(), } + assert transcript == expected_transcript + + +def test_store_transcript_includes_ols_config(transcripts_location): + """Test that ols_config is included in stored transcript.""" + user_id = suid.get_suid() + conversation_id = suid.get_suid() + query_is_valid = True + query = "Test query" + llm_request = LLMRequest(query=query, conversation_id=conversation_id) + response = "Test response" + rag_chunks = [] + truncated = False + tool_calls = [] + tool_results = [] + attachments = [] + + ols.store_transcript( + user_id, + conversation_id, + query_is_valid, + query, + llm_request, + response, + rag_chunks, + truncated, + tool_calls, + tool_results, + attachments, + ) + + transcript_dir = Path(transcripts_location) / user_id / conversation_id + transcripts = list(transcript_dir.glob("*.json")) + assert len(transcripts) == 1 + + # Load and verify the transcript contains ols_config + with open(transcripts[0]) as f: + transcript = json.loads(f.read()) + + # Verify ols_config is present + assert "ols_config" in transcript + + # Verify ols_config contains expected configuration data + ols_config_in_transcript = transcript["ols_config"] + expected_ols_config = config.ols_config.model_dump() + assert ols_config_in_transcript == expected_ols_config + + # Verify it contains key configuration sections + assert "default_provider" in ols_config_in_transcript + assert "default_model" in ols_config_in_transcript + assert "user_data_collection" in ols_config_in_transcript def test_calc_input_tokens_no_token_counter():