File size: 1,196 Bytes
47d3d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a45ef56
 
 
 
47d3d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Blueprint, jsonify
from datasets import load_dataset
import json

bp = Blueprint("sft_diff", __name__, url_prefix="/api/sft-diff")

HF_REPO = "timchen0618/browsecomp-plus-sft-diff-v1"

_cache: list | None = None


def _load():
    global _cache
    if _cache is not None:
        return _cache
    ds = load_dataset(HF_REPO, split="train")
    rows = []
    for row in ds:
        rows.append({
            "query_id":      str(row["query_id"]),
            "excerpt":       row["excerpt"],
            "messages_gpt":  json.loads(row["messages_json"])      if row.get("messages_json")      else None,
            "messages_qwen": json.loads(row["messages_json_qwen"]) if row.get("messages_json_qwen") else None,
        })
    _cache = rows
    return rows


@bp.get("/")
def get_data():
    try:
        rows = _load()
        return jsonify({"rows": rows})
    except Exception as e:
        return jsonify({"error": str(e)}), 500


@bp.post("/reload")
def reload_data():
    global _cache
    _cache = None
    try:
        rows = _load()
        return jsonify({"status": "ok", "count": len(rows)})
    except Exception as e:
        return jsonify({"error": str(e)}), 500