File size: 1,489 Bytes
cd6775d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""查询分割统一入口(进程内函数版,无需启动任何本地服务)。

    from decompose import icl_decompose, unsupervised_decompose, supervised_decompose
    subs = icl_decompose("your question here")     # -> ['sub q1', 'sub q2', ...]

命令行:
    python decompose.py icl "Who directed the highest-grossing film of 1997?"
    python decompose.py supervised "..."
    python decompose.py unsupervised "..."

这是对 `qd_baselines` 包的薄封装:①监督式(本地 Llama+LoRA)、②无监督(本地 XLM)、
③ICL(gpt-4o-mini,可插拔)。所需环境变量见 .env.example。
④ SearChain 是检索反馈闭环,仍为服务版,见 使用说明.md 第 4 节。
"""

import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from qd_baselines import (  # noqa: E402
    supervised_decompose,
    unsupervised_decompose,
    icl_decompose,
    METHODS,
)

__all__ = ["supervised_decompose", "unsupervised_decompose", "icl_decompose", "METHODS"]


if __name__ == "__main__":
    import json

    method = sys.argv[1] if len(sys.argv) > 1 else "icl"
    query = sys.argv[2] if len(sys.argv) > 2 else \
        "Who directed the highest-grossing film of 1997?"
    if method not in METHODS:
        sys.exit(f"未知方法 '{method}',可选:{list(METHODS)}")
    subs = METHODS[method](query)
    print(json.dumps({"method": method, "query": query, "sub_queries": subs},
                     ensure_ascii=False, indent=2))