Skip to content

fix: save generated data to configured dataset - #229

Open
Iams4kura wants to merge 2 commits into
xming521:masterfrom
Iams4kura:bugfix/honor-configured-dataset-output-20260826t040210z
Open

fix: save generated data to configured dataset#229
Iams4kura wants to merge 2 commits into
xming521:masterfrom
Iams4kura:bugfix/honor-configured-dataset-output-20260826t040210z

Conversation

@Iams4kura

@Iams4kura Iams4kura commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • Fixes: When dataset_dir or the dataset_info file mapping is customized, cutoff_len is calculated from stale or unrelated data because the newly generated samples remain in the default sft-my.json file.
  • Root cause: DataProcessor.save_result hardcodes ./dataset/res_csv/sft/sft-my.json, while the cutoff_len subprocess and training configuration resolve the selected dataset through dataset_dir and dataset_info.json.

Regression evidence

  • Before: PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -q tests/test_qa_generator.py::test_save_result_updates_configured_dataset_file exited 1

  • After: PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -q tests/test_qa_generator.py::test_save_result_updates_configured_dataset_file exited 0

Verification

  • PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest -q tests/test_qa_generator.py
  • uv run --no-sync ruff check .
  • uv run --no-sync ruff format --check .
  • uv run --no-sync pyright tests/test_qa_generator.py

Scope

  • 2 files changed, +85 / -4 lines

Sourcery 摘要

通过配置的数据集映射保存生成的 QA 结果,以便下游处理使用当前数据。

错误修复:

  • 将生成的 QA 数据保存到所选数据集配置的文件中,而不是硬编码的默认路径。
  • 处理完成后报告解析出的数据集输出路径,并拒绝不包含有效文件名的数据集映射。

测试:

  • 为自定义数据集映射和无效数据集条目添加回归测试。
Original summary in English

Summary by Sourcery

Save generated QA results through the configured dataset mapping so downstream processing uses the current data.

Bug Fixes:

  • Save generated QA data to the file configured for the selected dataset instead of a hardcoded default path.
  • Report the resolved dataset output path after processing and reject dataset mappings without a valid file name.

Tests:

  • Add regression coverage for customized dataset mappings and invalid dataset entries.

@sourcery-ai

sourcery-ai Bot commented Aug 26, 2026

Copy link
Copy Markdown

审查者指南

更新 QA 生成逻辑,使其根据配置的数据集目录和 dataset_info 映射,将输出保存到选定的文件中,返回并记录实际路径,并增加回归测试以防止写入过时的硬编码默认数据集。

配置的 QA 数据集输出的时序图

sequenceDiagram
    participant Generator as QA_Generator
    participant DatasetInfo as dataset_info.json
    participant File as ConfiguredDatasetFile
    participant CDF as cutoff_len_script

    Generator->>DatasetInfo: read dataset_info.json
    DatasetInfo-->>Generator: file_name for configured dataset
    Generator->>File: write generated QA data
    File-->>Generator: output_path
    Generator->>CDF: _execute_length_cdf_script()
    Generator-->>Generator: log output_path
Loading

文件级变更

变更 详细信息 文件
从配置的数据集元数据解析生成数据集的输出路径,而不是使用硬编码的默认路径。
  • 从配置的数据集目录读取 dataset_info.json。
  • 查找所选数据集的 file_name,并在缺失时明确报错。
  • 将生成的 QA 数据写入解析出的路径,并返回该路径。
  • 在成功日志中使用返回的路径,使诊断信息与实际输出保持一致。
weclone/data/qa_generator.py
增加针对自定义数据集目录和数据集映射的回归测试。
  • 创建一个包含过时现有数据和元数据的隔离配置数据集。
  • 验证生成的内容会替换配置文件、返回的路径正确,并且不会创建默认输出。
  • 模拟可选导入,使测试能够在不依赖无关运行时依赖的情况下执行 DataProcessor。
tests/test_qa_generator.py

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以回复审查评论并使用 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时(重新)生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会非常有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你想从新的审查开始,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Updates QA generation to save output to the file selected by the configured dataset directory and dataset_info mapping, returns and logs the actual path, and adds regression coverage preventing writes to the stale hardcoded default dataset.

Sequence diagram for configured QA dataset output

sequenceDiagram
    participant Generator as QA_Generator
    participant DatasetInfo as dataset_info.json
    participant File as ConfiguredDatasetFile
    participant CDF as cutoff_len_script

    Generator->>DatasetInfo: read dataset_info.json
    DatasetInfo-->>Generator: file_name for configured dataset
    Generator->>File: write generated QA data
    File-->>Generator: output_path
    Generator->>CDF: _execute_length_cdf_script()
    Generator-->>Generator: log output_path
Loading

File-Level Changes

Change Details Files
Resolve the generated dataset output path from the configured dataset metadata instead of a hardcoded default.
  • Read dataset_info.json from the configured dataset directory.
  • Look up the selected dataset’s file_name and fail clearly when it is missing.
  • Write generated QA data to the resolved path and return that path.
  • Use the returned path in the success log so diagnostics match the actual output.
weclone/data/qa_generator.py
Add regression coverage for customized dataset directories and dataset mappings.
  • Create an isolated configured dataset with stale existing data and metadata.
  • Verify generated content replaces the configured file, the returned path is correct, and no default output is created.
  • Stub optional imports so the test exercises DataProcessor without unrelated runtime dependencies.
tests/test_qa_generator.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

您好——我发现了 1 个问题

面向 AI Agent 的提示
请处理此代码审查中的评论:

## 单独的评论

### 评论 1
<location path="weclone/data/qa_generator.py" line_range="704-705" />
<code_context>
+        with open(dataset_info_path, "r", encoding="utf-8") as f:
+            dataset_info = json.load(f)
+
+        file_name = dataset_info.get(self.c.dataset, {}).get("file_name")
+        if not file_name:
+            raise ValueError(f"Dataset '{self.c.dataset}' must define file_name in {dataset_info_path}")
+
</code_context>
<issue_to_address>
**问题 (bug_risk):**`dataset_info.json` 中选定的数据集条目为 `null` 或其他非对象值时,`dataset_info.get(self.c.dataset, {}).get("file_name")` 会引发 `AttributeError`,而不是使用预期的 `ValueError` 报告无效的数据集配置。

**触发条件:** 自定义的 `dataset_info.json` 包含选定的数据集名称,但其对应的值是格式错误的非对象值。

**建议修复:** 在调用 `.get` 之前验证选定的条目是否为映射,并对格式错误的条目抛出相同的描述性 `ValueError````suggestion
        dataset_entry = dataset_info.get(self.c.dataset, {})
        if not isinstance(dataset_entry, dict):
            raise ValueError(f"Dataset '{self.c.dataset}' must define file_name in {dataset_info_path}")
        file_name = dataset_entry.get("file_name")
```
</issue_to_address>

Sourcery 对开源项目免费——如果您喜欢我们的审查,请考虑分享给他人 ✨
帮助我变得更有用!请对每条评论点击 👍 或 👎,我会利用反馈来改进审查结果。
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="weclone/data/qa_generator.py" line_range="704-705" />
<code_context>
+        with open(dataset_info_path, "r", encoding="utf-8") as f:
+            dataset_info = json.load(f)
+
+        file_name = dataset_info.get(self.c.dataset, {}).get("file_name")
+        if not file_name:
+            raise ValueError(f"Dataset '{self.c.dataset}' must define file_name in {dataset_info_path}")
+
</code_context>
<issue_to_address>
**issue (bug_risk):** When the selected dataset entry in `dataset_info.json` is `null` or another non-object value, `dataset_info.get(self.c.dataset, {}).get("file_name")` raises `AttributeError` instead of reporting the invalid dataset configuration with the intended `ValueError`.

**Triggers:** When a customized `dataset_info.json` contains the selected dataset name with a malformed non-object value.

**Suggested fix:** Validate that the selected entry is a mapping before calling `.get`, and raise the same descriptive `ValueError` for malformed entries.

```suggestion
        dataset_entry = dataset_info.get(self.c.dataset, {})
        if not isinstance(dataset_entry, dict):
            raise ValueError(f"Dataset '{self.c.dataset}' must define file_name in {dataset_info_path}")
        file_name = dataset_entry.get("file_name")
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread weclone/data/qa_generator.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant