-
Notifications
You must be signed in to change notification settings - Fork 69
feat: v2.2.2 #383
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
Merged
Merged
feat: v2.2.2 #383
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6bd591f
feat(llm): add 15-minute overall timeout to ArticleFactChecker
seancoding-day c86b4fb
fix: LLMHtmlExtractCompareV2 metric (#376)
e06084 da0b464
feat: table、equation质检prompt
shijinpjlab 40fbd67
feat: fix lint
shijinpjlab 69ea31d
Merge pull request #377 from shijinpjlab/dev_0331
shijinpjlab 99cd744
feat: BaseTextQuality根据score来判断
shijinpjlab 2dcae95
Merge pull request #379 from shijinpjlab/dev_0401
shijinpjlab 26302ce
feat: EvaluatorLLMArgs删除parameters属性,允许扩展
shijinpjlab d315842
metric: update LLMTextQualityV5 (#380)
e06084 24f1e25
feat: fix ci test
shijinpjlab 86f16e4
feat: 脚本删除parameters参数,md文件更新
shijinpjlab 47954af
Merge pull request #381 from shijinpjlab/dev_0401_config
shijinpjlab f6ae80d
Merge pull request #382 from MigoXLab/main
shijinpjlab c2a2f3c
feat: version 2.2.2
shijinpjlab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,21 +343,21 @@ class ArticleFactChecker(BaseAgent): | |
| "config": { | ||
| "key": "your-openai-api-key", | ||
| "model": "gpt-4o-mini", | ||
| "parameters": { | ||
| "agent_config": { | ||
| "max_iterations": 10, | ||
| "tools": { | ||
| "claims_extractor": { | ||
| "api_key": "your-openai-api-key", | ||
| "max_claims": 50, | ||
| "claim_types": ["factual", "institutional", "statistical", "attribution"] | ||
| }, | ||
| "tavily_search": { | ||
| "api_key": "your-tavily-api-key", | ||
| "max_results": 5 | ||
| }, | ||
| "arxiv_search": {"max_results": 5} | ||
| } | ||
| "agent_config": { | ||
| "max_iterations": 10, | ||
| "overall_timeout": 900, | ||
| "max_concurrent_claims": 5, | ||
| "tools": { | ||
| "claims_extractor": { | ||
| "api_key": "your-openai-api-key", | ||
| "max_claims": 50, | ||
| "claim_types": ["factual", "institutional", "statistical", "attribution"] | ||
| }, | ||
| "tavily_search": { | ||
| "api_key": "your-tavily-api-key", | ||
| "max_results": 5 | ||
| }, | ||
| "arxiv_search": {"max_results": 5} | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -372,6 +372,9 @@ class ArticleFactChecker(BaseAgent): | |
| ] | ||
| max_iterations = 10 # Allow more iterations for comprehensive checking | ||
| max_concurrent_claims = 5 # Default parallel claim verification slots | ||
| overall_timeout = 900 # 15-minute wall-clock timeout for entire evaluation | ||
| _MIN_OVERALL_TIMEOUT = 30 # Floor: 30 seconds | ||
| _MAX_OVERALL_TIMEOUT = 7200 # Ceiling: 2 hours | ||
|
|
||
| _required_fields = [RequiredField.CONTENT] # Article text | ||
|
|
||
|
|
@@ -394,8 +397,8 @@ def _get_output_dir(cls) -> Optional[str]: | |
| Returns: | ||
| Output directory path (created if needed), or None if saving is disabled. | ||
| """ | ||
| params = cls.dynamic_config.parameters or {} | ||
| agent_cfg = params.get('agent_config') or {} | ||
| extra_params = cls.dynamic_config.model_extra | ||
| agent_cfg = extra_params.get('agent_config') or {} | ||
|
|
||
| explicit_path = agent_cfg.get('output_path') | ||
| if explicit_path: | ||
|
|
@@ -816,24 +819,42 @@ def eval(cls, input_data: Data) -> EvalDetail: | |
| output_dir = cls._get_output_dir() | ||
|
|
||
| if cls.dynamic_config: | ||
| if cls.dynamic_config.parameters is None: | ||
| cls.dynamic_config.parameters = {} | ||
| cls.dynamic_config.parameters.setdefault("temperature", 0) | ||
| if 'temperature' not in cls.dynamic_config.model_extra: | ||
| cls.dynamic_config.temperature = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if output_dir and input_data.content: | ||
| cls._save_article_content(output_dir, input_data.content) | ||
|
|
||
| timeout = cls._get_overall_timeout() | ||
|
|
||
| async def _run_with_timeout() -> EvalDetail: | ||
| return await asyncio.wait_for( | ||
| cls._async_eval(input_data, start_time, output_dir), | ||
| timeout=timeout, | ||
| ) | ||
|
|
||
| try: | ||
| return asyncio.run(cls._async_eval(input_data, start_time, output_dir)) | ||
| return asyncio.run(_run_with_timeout()) | ||
| except asyncio.TimeoutError: | ||
| elapsed = time.time() - start_time | ||
| log.warning(f"ArticleFactChecker: overall timeout exceeded ({elapsed:.1f}s / {timeout:.0f}s limit)") | ||
| return cls._create_overall_timeout_result(elapsed, timeout) | ||
| except RuntimeError as e: | ||
| # Fallback when called inside an already-running event loop (e.g. Jupyter, tests) | ||
| if "cannot run" in str(e).lower() or "already running" in str(e).lower(): | ||
| import concurrent.futures | ||
| with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool: | ||
| future = pool.submit( | ||
| lambda: asyncio.run(cls._async_eval(input_data, start_time, output_dir)) | ||
| ) | ||
| return future.result() | ||
| future = pool.submit(lambda: asyncio.run(_run_with_timeout())) | ||
| try: | ||
| # Extra margin so asyncio.wait_for fires before this outer timeout | ||
| return future.result(timeout=timeout + 30) | ||
| except (asyncio.TimeoutError, concurrent.futures.TimeoutError): | ||
| elapsed = time.time() - start_time | ||
| log.warning( | ||
| f"ArticleFactChecker: overall timeout exceeded " | ||
| f"({elapsed:.1f}s / {timeout:.0f}s limit, fallback path)" | ||
| ) | ||
| return cls._create_overall_timeout_result(elapsed, timeout) | ||
| raise | ||
|
|
||
| # --- Two-Phase Async Architecture Methods --- | ||
|
|
@@ -922,8 +943,8 @@ async def _async_extract_claims(cls, input_data: Data) -> List[Dict]: | |
| """ | ||
| from dingo.model.llm.agent.tools.claims_extractor import ClaimsExtractor, ClaimsExtractorConfig | ||
|
|
||
| params = cls.dynamic_config.parameters or {} | ||
| agent_cfg = params.get('agent_config') or {} | ||
| extra_params = cls.dynamic_config.model_extra | ||
| agent_cfg = extra_params.get('agent_config') or {} | ||
| extractor_cfg = agent_cfg.get('tools', {}).get('claims_extractor', {}) | ||
|
|
||
| config_kwargs: Dict[str, Any] = { | ||
|
|
@@ -1019,10 +1040,30 @@ async def _async_verify_single_claim( | |
| @classmethod | ||
| def _get_max_concurrent_claims(cls) -> int: | ||
| """Read max_concurrent_claims from agent_config or use class default.""" | ||
| params = cls.dynamic_config.parameters or {} | ||
| agent_cfg = params.get('agent_config') or {} | ||
| extra_params = cls.dynamic_config.model_extra | ||
| agent_cfg = extra_params.get('agent_config') or {} | ||
| return agent_cfg.get('max_concurrent_claims', cls.max_concurrent_claims) | ||
|
|
||
| @classmethod | ||
| def _get_overall_timeout(cls) -> float: | ||
| """Read overall_timeout from agent_config or use class default (900s). | ||
|
|
||
| Returns: | ||
| Positive timeout in seconds, clamped to [30, 7200]. | ||
| """ | ||
| extra_params = cls.dynamic_config.model_extra | ||
| agent_cfg = extra_params.get('agent_config') or {} | ||
| raw = agent_cfg.get('overall_timeout', cls.overall_timeout) | ||
| try: | ||
| timeout = float(raw) | ||
| except (TypeError, ValueError): | ||
| log.warning(f"Invalid overall_timeout={raw!r}, using default {cls.overall_timeout}s") | ||
| return float(cls.overall_timeout) | ||
| clamped = max(cls._MIN_OVERALL_TIMEOUT, min(timeout, cls._MAX_OVERALL_TIMEOUT)) | ||
| if clamped != timeout: | ||
| log.warning(f"overall_timeout={timeout} out of range, clamped to {clamped}s") | ||
| return float(clamped) | ||
|
|
||
| @classmethod | ||
| def _parse_claim_json_robust(cls, output: Optional[str]) -> Dict[str, Any]: | ||
| """ | ||
|
|
@@ -1795,6 +1836,38 @@ def _create_error_result(cls, error_message: str) -> EvalDetail: | |
| ] | ||
| return result | ||
|
|
||
| @classmethod | ||
| def _create_overall_timeout_result(cls, elapsed: float, timeout: float) -> EvalDetail: | ||
| """ | ||
| Create error result when overall wall-clock timeout is exceeded. | ||
|
|
||
| Args: | ||
| elapsed: Actual elapsed time in seconds | ||
| timeout: Configured timeout limit in seconds | ||
|
|
||
| Returns: | ||
| EvalDetail with timeout error status | ||
| """ | ||
| minutes, seconds = divmod(int(timeout), 60) | ||
| limit_str = f"{minutes}m{seconds}s" if minutes else f"{int(timeout)}s" | ||
| result = EvalDetail(metric=cls.__name__) | ||
| result.status = True | ||
| result.label = [f"{QualityLabel.QUALITY_BAD_PREFIX}AGENT_OVERALL_TIMEOUT"] | ||
| result.reason = [ | ||
| "Article Fact-Checking Failed: Overall Timeout Exceeded", | ||
| "=" * 70, | ||
| f"Execution exceeded the {int(timeout)}s ({limit_str}) wall-clock limit.", | ||
| f"Elapsed time: {elapsed:.1f}s", | ||
| "", | ||
| "Recommendations:", | ||
| f" 1. Increase overall_timeout (current: {int(timeout)}s) in agent_config", | ||
| " 2. Reduce max_claims in claims_extractor config (e.g., 50 -> 20)", | ||
| " 3. Use a faster model (e.g., gpt-4o-mini instead of gpt-4o)", | ||
| " 4. Reduce max_concurrent_claims to lower API rate-limit pressure", | ||
| " 5. Split long articles into shorter sections", | ||
| ] | ||
| return result | ||
|
|
||
| @classmethod | ||
| def plan_execution(cls, input_data: Data) -> List[Dict[str, Any]]: | ||
| """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,22 +82,18 @@ def send_messages(cls, messages: List): | |
| else: | ||
| model_name = cls.client.models.list().data[0].id | ||
|
|
||
| params = cls.dynamic_config.parameters | ||
| cls.validate_config(params) | ||
| extra_params = cls.dynamic_config.model_extra | ||
| cls.validate_config(extra_params) | ||
|
|
||
| completions = cls.client.chat.completions.create( | ||
| model=model_name, | ||
| messages=messages, | ||
| temperature=params.get("temperature", 0.3) if params else 0.3, | ||
| top_p=params.get("top_p", 1) if params else 1, | ||
| max_tokens=params.get("max_tokens", 4000) if params else 4000, | ||
| presence_penalty=params.get("presence_penalty", 0) if params else 0, | ||
| frequency_penalty=params.get("frequency_penalty", 0) if params else 0, | ||
| **extra_params, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
|
|
||
| if completions.choices[0].finish_reason == "length": | ||
| raise ExceedMaxTokens( | ||
| f"Exceed max tokens: {params.get('max_tokens', 4000) if params else 4000}" | ||
| f"Exceed max tokens: {extra_params.get('max_tokens', 4000)}" | ||
| ) | ||
|
|
||
| return str(completions.choices[0].message.content) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Accessing
model_extradirectly can raise aTypeErrorif no extra fields were provided during initialization, as Pydantic v2 setsmodel_extratoNonein that case. It is safer to use(cls.dynamic_config.model_extra or {}).