-
Notifications
You must be signed in to change notification settings - Fork 0
async #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async #1
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
# 評価器モジュール - 統一インターフェース | ||
# 評価器モジュール - 統一インターフェース (すべて非同期バージョンを使用) | ||
|
||
from .base import BaseEvaluator | ||
from .ragas_ollama import RagasOllamaEvaluator # Re-enabled with compatible versions | ||
# from .academic_evaluator import AcademicEvaluator # Removed in favor of async version | ||
from .factory import EvaluatorFactory, EvaluatorManager | ||
from .async_base import AsyncBaseEvaluator | ||
from .async_academic_evaluator import AsyncAcademicEvaluator | ||
from .async_ragas_evaluator import AsyncRagasEvaluator | ||
from .async_factory import AsyncEvaluatorFactory, AsyncEvaluatorManager | ||
from .base_evaluator import BaseEvaluator as AsyncBaseEvaluator | ||
from .academic_evaluator import AcademicEvaluator | ||
from .ragas_evaluator import RagasEvaluator | ||
from .factory import EvaluatorFactory, EvaluatorManager # Legacy classes | ||
from .evaluator_factory import EvaluatorFactory as AsyncEvaluatorFactory, EvaluatorManager as AsyncEvaluatorManager | ||
|
||
# 注: すべての評価器は非同期APIをサポートしています | ||
|
||
__all__ = [ | ||
'BaseEvaluator', | ||
'RagasOllamaEvaluator', # Re-enabled with compatible versions | ||
'AsyncRagasEvaluator', # Renamed from AsyncRagasOllamaEvaluator | ||
# 'AcademicEvaluator', # Removed in favor of async version | ||
'EvaluatorFactory', | ||
'EvaluatorManager', | ||
'AsyncBaseEvaluator', | ||
'AsyncAcademicEvaluator', | ||
'AsyncRagasOllamaEvaluator', | ||
'AcademicEvaluator', | ||
'RagasEvaluator', | ||
'EvaluatorFactory', # Legacy | ||
'EvaluatorManager', # Legacy | ||
'AsyncEvaluatorFactory', | ||
'AsyncEvaluatorManager' | ||
] |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,28 +1,28 @@ | ||||||||||||||||||||||||||||||||||||||||||
# 异步评估器工厂 - 异步评估器的创建和管理 | ||||||||||||||||||||||||||||||||||||||||||
# 评估器工厂 - 评估器的创建和管理 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
from typing import Dict, List, Any, Optional | ||||||||||||||||||||||||||||||||||||||||||
from .async_base import AsyncBaseEvaluator | ||||||||||||||||||||||||||||||||||||||||||
from .async_academic_evaluator import AsyncAcademicEvaluator | ||||||||||||||||||||||||||||||||||||||||||
from .async_ragas_evaluator import AsyncRagasEvaluator | ||||||||||||||||||||||||||||||||||||||||||
from .base_evaluator import BaseEvaluator | ||||||||||||||||||||||||||||||||||||||||||
from .academic_evaluator import AcademicEvaluator | ||||||||||||||||||||||||||||||||||||||||||
from .ragas_evaluator import RagasEvaluator | ||||||||||||||||||||||||||||||||||||||||||
import asyncio | ||||||||||||||||||||||||||||||||||||||||||
import logging | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
logger = logging.getLogger(__name__) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
class AsyncEvaluatorFactory: | ||||||||||||||||||||||||||||||||||||||||||
"""异步评估器工厂类""" | ||||||||||||||||||||||||||||||||||||||||||
class EvaluatorFactory: | ||||||||||||||||||||||||||||||||||||||||||
"""评估器工厂类""" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# 可用的异步评估器类型 | ||||||||||||||||||||||||||||||||||||||||||
# 可用的评估器类型 | ||||||||||||||||||||||||||||||||||||||||||
EVALUATOR_TYPES = { | ||||||||||||||||||||||||||||||||||||||||||
"async_academic": AsyncAcademicEvaluator, | ||||||||||||||||||||||||||||||||||||||||||
"async_ragas": AsyncRagasEvaluator | ||||||||||||||||||||||||||||||||||||||||||
"academic": AcademicEvaluator, | ||||||||||||||||||||||||||||||||||||||||||
"ragas": RagasEvaluator | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# 默认评估器优先级 | ||||||||||||||||||||||||||||||||||||||||||
DEFAULT_PRIORITY = ["async_ragas", "async_academic"] | ||||||||||||||||||||||||||||||||||||||||||
DEFAULT_PRIORITY = ["ragas", "academic"] | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
|
# 可用的评估器类型 | |
EVALUATOR_TYPES = { | |
"async_academic": AsyncAcademicEvaluator, | |
"async_ragas": AsyncRagasEvaluator | |
"academic": AcademicEvaluator, | |
"ragas": RagasEvaluator | |
} | |
# 默认评估器优先级 | |
DEFAULT_PRIORITY = ["async_ragas", "async_academic"] | |
DEFAULT_PRIORITY = ["ragas", "academic"] | |
# 可用的评估器类型 | |
EVALUATOR_TYPES: ClassVar[Dict[str, Type[BaseEvaluator]]] = { | |
"academic": AcademicEvaluator, | |
"ragas": RagasEvaluator, | |
} | |
# 默认评估器优先级(使用不可变元组) | |
DEFAULT_PRIORITY: ClassVar[Tuple[str, ...]] = ("ragas", "academic") |
🧰 Tools
🪛 Ruff (0.12.2)
16-19: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
22-22: Mutable class attributes should be annotated with typing.ClassVar
(RUF012)
🤖 Prompt for AI Agents
In evaluators/evaluator_factory.py around lines 15 to 23, the class-level
EVALUATOR_TYPES and DEFAULT_PRIORITY are currently mutable and lack proper
typing; change their declarations to use typing.ClassVar with explicit types
(EVALUATOR_TYPES: ClassVar[Mapping[str, Type[BaseEvaluator]]] and
DEFAULT_PRIORITY: ClassVar[Tuple[str, ...]]), replace the mutable dict with an
immutable Mapping (or wrap with types.MappingProxyType) and use a tuple (or
frozenset/tuple) for DEFAULT_PRIORITY to prevent instance-level mutation and
ensure correct static typing.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
避免 bare except;记录异常上下文
bare except 会吞掉系统异常。改为捕获 Exception 并记录。
- except:
- info[name] = {
+ except Exception as e:
+ logger.debug("获取评估器信息失败: %s (%s)", name, e)
+ info[name] = {
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
except: | |
info[name] = { | |
"name": name, | |
"supported_metrics": [], | |
"description": cls._get_evaluator_description(name), | |
"async": True | |
"description": cls._get_evaluator_description(name) | |
} | |
except Exception as e: | |
logger.debug("获取评估器信息失败: %s (%s)", name, e) | |
info[name] = { | |
"name": name, | |
"supported_metrics": [], | |
"description": cls._get_evaluator_description(name) | |
} |
🧰 Tools
🪛 Ruff (0.12.2)
87-87: Do not use bare except
(E722)
🤖 Prompt for AI Agents
In evaluators/evaluator_factory.py around lines 87 to 92, replace the bare
"except:" with "except Exception as e" and record the exception context before
continuing to populate info[name]; use the module logger (or import logging) and
call logger.exception or logging.exception with a message that includes the
evaluator name so the stack trace and error message are preserved, then keep the
existing info[name] assignment unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken import: .base does not exist.
from .base import BaseEvaluator will ImportError; also you want to re-export BaseEvaluator twice. Import solely from base_evaluator and alias.
📝 Committable suggestion
🤖 Prompt for AI Agents