Skip to content

Commit e479452

Browse files
committed
fix ut
1 parent 64173d1 commit e479452

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ The current built-in detection rules and model methods focus on common data qual
435435
- [RedPajama-Data](https://github.com/togethercomputer/RedPajama-Data)
436436
- [mlflow](https://github.com/mlflow/mlflow)
437437
- [deepeval](https://github.com/confident-ai/deepeval)
438+
- [ragas](https://github.com/explodinggradients/ragas)
438439

439440
# Contribution
440441

README_ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ result = executor.execute()
428428
- [RedPajama-Data](https://github.com/togethercomputer/RedPajama-Data)
429429
- [mlflow](https://github.com/mlflow/mlflow)
430430
- [deepeval](https://github.com/confident-ai/deepeval)
431+
- [ragas](https://github.com/explodinggradients/ragas)
431432

432433
# 貢献
433434

README_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ result = executor.execute()
431431
- [RedPajama-Data](https://github.com/togethercomputer/RedPajama-Data)
432432
- [mlflow](https://github.com/mlflow/mlflow)
433433
- [deepeval](https://github.com/confident-ai/deepeval)
434+
- [ragas](https://github.com/explodinggradients/ragas)
434435

435436
# 贡献
436437

dingo/model/llm/llm_rag_context_precision.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def build_messages(cls, input_data: Data) -> List:
3737
question = input_data.prompt or input_data.raw_data.get("question", "")
3838
answer = input_data.content or input_data.raw_data.get("answer", "")
3939

40+
if not answer:
41+
raise ValueError("Context Precision评估需要answer字段")
42+
4043
# 处理contexts
4144
contexts = None
4245
if input_data.context:

test/scripts/model/llm/test_rag_metrics.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pytest test/scripts/model/llm/test_rag_metrics.py -v
1313
"""
1414

15-
from unittest.mock import Mock, patch
15+
from unittest.mock import patch
1616

1717
import pytest
1818

@@ -376,11 +376,14 @@ def test_process_response_low_relevancy(self):
376376
class TestIntegration:
377377
"""集成测试(使用 mock)"""
378378

379-
@patch('dingo.model.llm.llm_rag_faithfulness.LLMRAGFaithfulness.call_llm')
380-
def test_faithfulness_end_to_end(self, mock_call_llm):
379+
@patch('dingo.model.llm.base_openai.BaseOpenAI.send_messages')
380+
@patch('dingo.model.llm.base_openai.BaseOpenAI.create_client')
381+
def test_faithfulness_end_to_end(self, mock_create_client, mock_send_messages):
381382
"""测试忠实度端到端评估"""
383+
# Mock 客户端创建
384+
mock_create_client.return_value = None
382385
# Mock LLM 响应
383-
mock_call_llm.return_value = '{"score": 8, "reason": "答案基本忠实于上下文。"}'
386+
mock_send_messages.return_value = '{"score": 8, "reason": "答案基本忠实于上下文。"}'
384387

385388
data = Data(
386389
data_id="test_integration",
@@ -393,12 +396,16 @@ def test_faithfulness_end_to_end(self, mock_call_llm):
393396

394397
assert result.score == 8
395398
assert result.error_status is False
396-
assert mock_call_llm.called
399+
assert mock_send_messages.called
397400

398-
@patch('dingo.model.llm.llm_rag_answer_relevancy.LLMRAGAnswerRelevancy.call_llm')
399-
def test_answer_relevancy_end_to_end(self, mock_call_llm):
401+
@patch('dingo.model.llm.base_openai.BaseOpenAI.send_messages')
402+
@patch('dingo.model.llm.base_openai.BaseOpenAI.create_client')
403+
def test_answer_relevancy_end_to_end(self, mock_create_client, mock_send_messages):
400404
"""测试答案相关性端到端评估"""
401-
mock_call_llm.return_value = '{"score": 9, "reason": "答案直接回答问题。"}'
405+
# Mock 客户端创建
406+
mock_create_client.return_value = None
407+
# Mock LLM 响应
408+
mock_send_messages.return_value = '{"score": 9, "reason": "答案直接回答问题。"}'
402409

403410
data = Data(
404411
data_id="test_integration_2",
@@ -410,12 +417,16 @@ def test_answer_relevancy_end_to_end(self, mock_call_llm):
410417

411418
assert result.score == 9
412419
assert result.error_status is False
413-
assert mock_call_llm.called
420+
assert mock_send_messages.called
414421

415-
@patch('dingo.model.llm.llm_rag_context_relevancy.LLMRAGContextRelevancy.call_llm')
416-
def test_context_relevancy_end_to_end(self, mock_call_llm):
422+
@patch('dingo.model.llm.base_openai.BaseOpenAI.send_messages')
423+
@patch('dingo.model.llm.base_openai.BaseOpenAI.create_client')
424+
def test_context_relevancy_end_to_end(self, mock_create_client, mock_send_messages):
417425
"""测试上下文相关性端到端评估"""
418-
mock_call_llm.return_value = '{"score": 6, "reason": "半数上下文相关。"}'
426+
# Mock 客户端创建
427+
mock_create_client.return_value = None
428+
# Mock LLM 响应
429+
mock_send_messages.return_value = '{"score": 6, "reason": "半数上下文相关。"}'
419430

420431
data = Data(
421432
data_id="test_integration_3",
@@ -430,7 +441,7 @@ def test_context_relevancy_end_to_end(self, mock_call_llm):
430441

431442
assert result.score == 6
432443
assert result.error_status is False # 默认阈值是5
433-
assert mock_call_llm.called
444+
assert mock_send_messages.called
434445

435446

436447
class TestEdgeCases:
@@ -521,5 +532,5 @@ def test_missing_score_in_response(self):
521532
LLMRAGFaithfulness.process_response(response)
522533

523534

524-
if __name__ == "__main__":
525-
pytest.main([__file__, "-v", "-s"])
535+
# 使用 pytest 命令运行测试,而不是直接运行此文件
536+
# pytest test/scripts/model/llm/test_rag_metrics.py -v

web-static/assets/main-Dha4eK9H.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50070,7 +50070,7 @@ const genVirtualStyle = (token2) => {
5007050070
[`${componentCls}-tbody-virtual`]: {
5007150071
[`${componentCls}-tbody-virtual-holder-inner`]: {
5007250072
[`
50073-
& > ${componentCls}-row,
50073+
& > ${componentCls}-row,
5007450074
& > div:not(${componentCls}-row) > ${componentCls}-row
5007550075
`]: {
5007650076
display: "flex",

web-static/assets/main-O6AZuAtl.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,4 +1605,4 @@ body #root {
16051605
}.index-module__main-home___zg1x- {
16061606
width: calc(100% - var(--sidebar-width));
16071607
height: 100%;
1608-
}
1608+
}

0 commit comments

Comments
 (0)