Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dingo/model/llm/rag/llm_rag_answer_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def eval(cls, input_data: Data) -> ModelRes:
result = ModelRes()
result.score = score

# 根据分数判断是否通过(默认阈值5,满分10分)
threshold = 5
# 根据分数判断是否通过
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
# 检查是否有自定义的strictness参数
cls.strictness = cls.dynamic_config.parameters.get('strictness', 3)
Comment on lines +269 to 273
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码可读性并避免重复访问属性,建议将 cls.dynamic_config.parameters 存入一个局部变量中。这样后续对参数的访问会更简洁,也方便您在后续代码(如276行)中复用该变量。

Suggested change
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
# 检查是否有自定义的strictness参数
cls.strictness = cls.dynamic_config.parameters.get('strictness', 3)
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
parameters = cls.dynamic_config.parameters
threshold = parameters.get('threshold')
# 检查是否有自定义的strictness参数
cls.strictness = parameters.get('strictness', 3)


Expand All @@ -277,7 +277,7 @@ def eval(cls, input_data: Data) -> ModelRes:
if embedding_model_name:
cls.init_embedding_model(embedding_model_name)

if score >= threshold:
if threshold is None or score >= threshold:
result.eval_status = False
result.eval_details = {
"label": ["QUALITY_GOOD.ANSWER_RELEVANCY_PASS"],
Expand Down
8 changes: 4 additions & 4 deletions dingo/model/llm/rag/llm_rag_context_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def process_response(cls, responses: List[str]) -> ModelRes:
result = ModelRes()
result.score = score

# 根据分数判断是否通过(默认阈值5,满分10分)
threshold = 5
# 根据分数判断是否通过
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
Comment on lines +258 to +260
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和简洁性,可以稍微重构一下获取 threshold 的逻辑。通过使用 getattr 来安全地获取 parameters,可以使代码更紧凑、更健壮。

        parameters = getattr(cls.dynamic_config, 'parameters', None)
        threshold = parameters.get('threshold') if parameters else None


if score >= threshold:
if threshold is None or score >= threshold:
result.eval_status = False
result.eval_details = {
"label": ["QUALITY_GOOD.CONTEXT_PRECISION_PASS"],
Expand Down
8 changes: 4 additions & 4 deletions dingo/model/llm/rag/llm_rag_context_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ def process_response(cls, response: str) -> ModelRes:
result = ModelRes()
result.score = score

# 根据分数判断是否通过(默认阈值5,满分10分)
threshold = 5
# 根据分数判断是否通过
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
Comment on lines +204 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和简洁性,可以稍微重构一下获取 threshold 的逻辑。通过使用 getattr 来安全地获取 parameters,可以使代码更紧凑、更健壮。

        parameters = getattr(cls.dynamic_config, 'parameters', None)
        threshold = parameters.get('threshold') if parameters else None


if score >= threshold:
if threshold is None or score >= threshold:
result.eval_status = False
result.eval_details = {
"label": ["QUALITY_GOOD.CONTEXT_RECALL_PASS"],
Expand Down
8 changes: 4 additions & 4 deletions dingo/model/llm/rag/llm_rag_context_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ def process_response(cls, response: str) -> ModelRes:
result = ModelRes()
result.score = score

# 根据分数判断是否通过(默认阈值5,满分10分)
threshold = 5
# 根据分数判断是否通过
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
Comment on lines +204 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和简洁性,可以稍微重构一下获取 threshold 的逻辑。通过使用 getattr 来安全地获取 parameters,可以使代码更紧凑、更健壮。

        parameters = getattr(cls.dynamic_config, 'parameters', None)
        threshold = parameters.get('threshold') if parameters else None


if score >= threshold:
if threshold is None or score >= threshold:
result.eval_status = False
result.eval_details = {
"label": ["QUALITY_GOOD.CONTEXT_RELEVANCY_PASS"],
Expand Down
8 changes: 4 additions & 4 deletions dingo/model/llm/rag/llm_rag_faithfulness.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ def process_response(cls, response: str) -> ModelRes:
result = ModelRes()
result.score = score

# 根据分数判断是否通过(默认阈值5,满分10分)
threshold = 5
# 根据分数判断是否通过
threshold = None
if hasattr(cls, 'dynamic_config') and cls.dynamic_config.parameters:
threshold = cls.dynamic_config.parameters.get('threshold', 5)
threshold = cls.dynamic_config.parameters.get('threshold')
Comment on lines +288 to +290
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和简洁性,可以稍微重构一下获取 threshold 的逻辑。通过使用 getattr 来安全地获取 parameters,可以使代码更紧凑、更健壮。

        parameters = getattr(cls.dynamic_config, 'parameters', None)
        threshold = parameters.get('threshold') if parameters else None


if score >= threshold:
if threshold is None or score >= threshold:
result.eval_status = False
result.eval_details = {
"label": ["QUALITY_GOOD.FAITHFULNESS_PASS"],
Expand Down