dataflow-kg 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataflow/__init__.py +15 -0
- dataflow/cli.py +547 -0
- dataflow/cli_funcs/__init__.py +8 -0
- dataflow/cli_funcs/cli_env.py +86 -0
- dataflow/cli_funcs/cli_eval.py +467 -0
- dataflow/cli_funcs/cli_init.py +54 -0
- dataflow/cli_funcs/cli_pdf.py +526 -0
- dataflow/cli_funcs/cli_text.py +671 -0
- dataflow/cli_funcs/copy_funcs.py +98 -0
- dataflow/cli_funcs/eval_pipeline/eval_api.py +243 -0
- dataflow/cli_funcs/eval_pipeline/eval_local.py +245 -0
- dataflow/cli_funcs/paths.py +46 -0
- dataflow/cli_funcs/pdf2model_pipeline/llama_factory_trainer.py +369 -0
- dataflow/cli_funcs/pdf2model_pipeline/path_to_jsonl_script.py +237 -0
- dataflow/cli_funcs/pdf2model_pipeline/pdf_to_qa_pipeline.py +118 -0
- dataflow/cli_funcs/text2model_pipeline/llama_factory_trainer.py +369 -0
- dataflow/cli_funcs/text2model_pipeline/merge_filter_qa_pairs.py +300 -0
- dataflow/cli_funcs/text2model_pipeline/text_to_qa_pipeline.py +110 -0
- dataflow/core/__init__.py +18 -0
- dataflow/core/llm_serving.py +35 -0
- dataflow/core/operator.py +28 -0
- dataflow/core/prompt.py +107 -0
- dataflow/core/wrapper.py +14 -0
- dataflow/example/FinKGRiskPipeline/input.json +6 -0
- dataflow/example/GeoKGSpatiotemporalEventPipeline/input.json +5 -0
- dataflow/example/GraphRAGPipeline/input.json +14 -0
- dataflow/example/GraphReasoningPipeline/input.json +15 -0
- dataflow/example/HyperRelationKGPipeline/input.json +11 -0
- dataflow/example/KG2QAPipeline/input.json +11 -0
- dataflow/example/KGEvaluationPipeline/input.json +29 -0
- dataflow/example/KGExtractionPipeline/input.json +10 -0
- dataflow/example/LegalKGPipeline/input.json +10 -0
- dataflow/example/MedicalKGPipeline/input.json +12 -0
- dataflow/example/MultimodalKGPipeline/input.json +6 -0
- dataflow/example/ScholarKGPipeline/input.json +12 -0
- dataflow/example/TemporalKGPipeline/input.json +8 -0
- dataflow/logger.py +128 -0
- dataflow/operators/__init__.py +4 -0
- dataflow/operators/commonsense_kg/__init__.py +27 -0
- dataflow/operators/commonsense_kg/eval/cskg_triple_adaptability_eval.py +136 -0
- dataflow/operators/commonsense_kg/eval/cskg_triple_rationale_eval.py +139 -0
- dataflow/operators/commonsense_kg/filter/cskg_rel_triple_set_sampling.py +350 -0
- dataflow/operators/commonsense_kg/filter/cskg_triple_adaptability_filtering.py +89 -0
- dataflow/operators/commonsense_kg/filter/cskg_triple_rationale_filtering.py +87 -0
- dataflow/operators/commonsense_kg/generate/cskg_rel_triple_qa_generator.py +140 -0
- dataflow/operators/commonsense_kg/generate/cskg_triple_extractor.py +259 -0
- dataflow/operators/commonsense_kg/refine/cskg_triple_concept_generalization.py +187 -0
- dataflow/operators/domain_kg/financial_kg/__init__.py +21 -0
- dataflow/operators/domain_kg/financial_kg/filter/finkg_4tuple_ontology_filtering.py +142 -0
- dataflow/operators/domain_kg/financial_kg/generate/finkg_4tuple_extractor.py +220 -0
- dataflow/operators/domain_kg/financial_kg/generate/finkg_entity_risk_assessment.py +573 -0
- dataflow/operators/domain_kg/financial_kg/generate/finkg_event_impact_tracing.py +760 -0
- dataflow/operators/domain_kg/financial_kg/generate/finkg_investment_analysis.py +487 -0
- dataflow/operators/domain_kg/financial_kg/generate/finkg_marketaux_news_retriever.py +399 -0
- dataflow/operators/domain_kg/geospatial_kg/__init__.py +34 -0
- dataflow/operators/domain_kg/geospatial_kg/eval/geokg_event_consistence_eval.py +130 -0
- dataflow/operators/domain_kg/geospatial_kg/eval/geokg_event_rationale_eval.py +130 -0
- dataflow/operators/domain_kg/geospatial_kg/eval/geokg_event_summary.py +116 -0
- dataflow/operators/domain_kg/geospatial_kg/filter/geokg_event_consistence_filtering.py +88 -0
- dataflow/operators/domain_kg/geospatial_kg/filter/geokg_event_location_filtering.py +92 -0
- dataflow/operators/domain_kg/geospatial_kg/filter/geokg_event_rationale_filtering.py +88 -0
- dataflow/operators/domain_kg/geospatial_kg/filter/geokg_event_time_filtering.py +177 -0
- dataflow/operators/domain_kg/geospatial_kg/generate/geokg_4tuple_extractor.py +292 -0
- dataflow/operators/domain_kg/geospatial_kg/generate/geokg_event_extractor.py +184 -0
- dataflow/operators/domain_kg/geospatial_kg/refine/geokg_entity_link2database.py +320 -0
- dataflow/operators/domain_kg/geospatial_kg/refine/geokg_rel_4tuple_inference.py +157 -0
- dataflow/operators/domain_kg/legal_kg/__init__.py +21 -0
- dataflow/operators/domain_kg/legal_kg/eval/legalkg_case_similarity_eval.py +106 -0
- dataflow/operators/domain_kg/legal_kg/filter/legalkg_case_similarity_filtering.py +75 -0
- dataflow/operators/domain_kg/legal_kg/generate/legalkg_case_judgement_generator.py +135 -0
- dataflow/operators/domain_kg/legal_kg/generate/legalkg_triple_extractor.py +309 -0
- dataflow/operators/domain_kg/medical_kg/__init__.py +19 -0
- dataflow/operators/domain_kg/medical_kg/filter/medkg_triple_metapath_sampling.py +288 -0
- dataflow/operators/domain_kg/medical_kg/generate/medkg_triple_drug_action_mechanism_discovery.py +350 -0
- dataflow/operators/domain_kg/medical_kg/generate/medkg_triple_drug_repositioning_discovery.py +319 -0
- dataflow/operators/domain_kg/medical_kg/generate/medkg_triple_extractor.py +344 -0
- dataflow/operators/domain_kg/scholar_kg/__init__.py +16 -0
- dataflow/operators/domain_kg/scholar_kg/generate/schokg_query_reasoning.py +348 -0
- dataflow/operators/domain_kg/scholar_kg/generate/schokg_recommend.py +347 -0
- dataflow/operators/domain_kg/scholar_kg/generate/schokg_triple_extractor.py +353 -0
- dataflow/operators/domain_kg/utils/__init__.py +22 -0
- dataflow/operators/domain_kg/utils/domain_kg_tuple_ontology_filtering.py +168 -0
- dataflow/operators/domain_kg/utils/finkg_get_ontology.py +317 -0
- dataflow/operators/domain_kg/utils/geokg_get_ontology.py +198 -0
- dataflow/operators/domain_kg/utils/legalkg_get_ontology.py +140 -0
- dataflow/operators/domain_kg/utils/medkg_get_anatomy_biology_ontology.py +190 -0
- dataflow/operators/domain_kg/utils/medkg_get_disease_diagnosis_ontology.py +188 -0
- dataflow/operators/domain_kg/utils/medkg_get_drug_therapy_ontology.py +189 -0
- dataflow/operators/domain_kg/utils/medkg_get_microbe_pathogen_ontology.py +131 -0
- dataflow/operators/domain_kg/utils/medkg_get_test_measurement_ontology.py +171 -0
- dataflow/operators/domain_kg/utils/schokg_get_ontology.py +95 -0
- dataflow/operators/general_kg/__init__.py +58 -0
- dataflow/operators/general_kg/eval/kg_qa_concise_eval.py +149 -0
- dataflow/operators/general_kg/eval/kg_qa_correlation_eval.py +148 -0
- dataflow/operators/general_kg/eval/kg_qa_natural_eval.py +148 -0
- dataflow/operators/general_kg/eval/kg_rel_triple_consistency_eval.py +380 -0
- dataflow/operators/general_kg/eval/kg_rel_triple_nx_visual.py +184 -0
- dataflow/operators/general_kg/eval/kg_rel_triple_strength_eval.py +238 -0
- dataflow/operators/general_kg/eval/kg_rel_triple_topology_eval.py +233 -0
- dataflow/operators/general_kg/eval/kg_subgraph_connectivity_eval.py +155 -0
- dataflow/operators/general_kg/eval/kg_subgraph_consistence_eval.py +140 -0
- dataflow/operators/general_kg/eval/kg_subgraph_scale_eval.py +133 -0
- dataflow/operators/general_kg/filter/kg_attri_tuple_sampling.py +201 -0
- dataflow/operators/general_kg/filter/kg_entity_validation.py +143 -0
- dataflow/operators/general_kg/filter/kg_qa_concise_filtering.py +89 -0
- dataflow/operators/general_kg/filter/kg_qa_correlation_filtering.py +88 -0
- dataflow/operators/general_kg/filter/kg_qa_natural_filtering.py +88 -0
- dataflow/operators/general_kg/filter/kg_rel_triple_strength_filtering.py +88 -0
- dataflow/operators/general_kg/filter/kg_rel_tuple_path_sampling.py +235 -0
- dataflow/operators/general_kg/filter/kg_rel_tuple_subgraph_sampling.py +330 -0
- dataflow/operators/general_kg/filter/kg_subgraph_connectivity_filtering.py +75 -0
- dataflow/operators/general_kg/filter/kg_subgraph_consistence_filtering.py +75 -0
- dataflow/operators/general_kg/filter/kg_subgraph_scale_filtering.py +75 -0
- dataflow/operators/general_kg/filter/kg_tuple_remove_repeated.py +118 -0
- dataflow/operators/general_kg/filter/kg_tuple_validation.py +156 -0
- dataflow/operators/general_kg/generate/kg_attri_triple_qa_generator.py +146 -0
- dataflow/operators/general_kg/generate/kg_entity_extractor.py +186 -0
- dataflow/operators/general_kg/generate/kg_rel_triple_conversation_generator.py +130 -0
- dataflow/operators/general_kg/generate/kg_rel_triple_inference.py +166 -0
- dataflow/operators/general_kg/generate/kg_rel_triple_path_qa_generator.py +172 -0
- dataflow/operators/general_kg/generate/kg_rel_triple_subgraph_qa_generator.py +160 -0
- dataflow/operators/general_kg/generate/kg_triple_extractor.py +269 -0
- dataflow/operators/general_kg/generate/kg_triple_merge.py +206 -0
- dataflow/operators/general_kg/generate/kg_tuple2text.py +102 -0
- dataflow/operators/general_kg/refinement/kg_entity_alignment.py +130 -0
- dataflow/operators/general_kg/refinement/kg_entity_classification.py +151 -0
- dataflow/operators/general_kg/refinement/kg_entity_disambiguation.py +198 -0
- dataflow/operators/general_kg/refinement/kg_entity_link2database.py +180 -0
- dataflow/operators/general_kg/refinement/kg_entity_normalization.py +150 -0
- dataflow/operators/general_kg/refinement/kg_triple_disambiguation.py +185 -0
- dataflow/operators/general_kg/refinement/kg_tuple_normalization.py +174 -0
- dataflow/operators/graph_rag/__init__.py +26 -0
- dataflow/operators/graph_rag/eval/graphrag_answer_plausibility_eval.py +162 -0
- dataflow/operators/graph_rag/eval/graphrag_answer_token_eval.py +109 -0
- dataflow/operators/graph_rag/eval/graphrag_question_difficulty_eval.py +157 -0
- dataflow/operators/graph_rag/eval/graphrag_truth_eval.py +141 -0
- dataflow/operators/graph_rag/filter/graphrag_answer_plausibility_filtering.py +86 -0
- dataflow/operators/graph_rag/filter/graphrag_answer_token_filtering.py +86 -0
- dataflow/operators/graph_rag/generate/graphrag_get_answer.py +129 -0
- dataflow/operators/graph_rag/generate/graphrag_prompt_generator.py +255 -0
- dataflow/operators/graph_rag/generate/graphrag_query_extractor.py +158 -0
- dataflow/operators/graph_reasoning/__init__.py +24 -0
- dataflow/operators/graph_reasoning/eval/reasoning_path_length_eval.py +88 -0
- dataflow/operators/graph_reasoning/eval/reasoning_path_redundancy_eval.py +143 -0
- dataflow/operators/graph_reasoning/filter/reasoning_path_length_filtering.py +103 -0
- dataflow/operators/graph_reasoning/filter/reasoning_path_redundancy_filtering.py +89 -0
- dataflow/operators/graph_reasoning/generate/reasoning_constrained_path_search.py +169 -0
- dataflow/operators/graph_reasoning/generate/reasoning_path_search.py +192 -0
- dataflow/operators/graph_reasoning/generate/reasoning_rel_generator.py +154 -0
- dataflow/operators/hyper_relation_kg/__init__.py +26 -0
- dataflow/operators/hyper_relation_kg/eval/hrkg_rel_triple_attri_summary.py +108 -0
- dataflow/operators/hyper_relation_kg/eval/hrkg_rel_triple_completeness_eval.py +126 -0
- dataflow/operators/hyper_relation_kg/eval/hrkg_rel_triple_consistency_eval.py +126 -0
- dataflow/operators/hyper_relation_kg/filter/hrkg_rel_triple_attri_filtering.py +97 -0
- dataflow/operators/hyper_relation_kg/filter/hrkg_rel_triple_completeness_filtering.py +81 -0
- dataflow/operators/hyper_relation_kg/filter/hrkg_rel_triple_consistency_filtering.py +81 -0
- dataflow/operators/hyper_relation_kg/generate/hrkg_rel_triple_extractor.py +216 -0
- dataflow/operators/hyper_relation_kg/generate/hrkg_rel_triple_path_qa_generator.py +173 -0
- dataflow/operators/hyper_relation_kg/generate/hrkg_rel_triple_subgraph_qa_generator.py +173 -0
- dataflow/operators/multi_model_kg/__init__.py +24 -0
- dataflow/operators/multi_model_kg/filter/mmkg_visual_triple_path_sampling.py +285 -0
- dataflow/operators/multi_model_kg/filter/mmkg_visual_triple_subgraph_sampling.py +321 -0
- dataflow/operators/multi_model_kg/generate/mmkg_visual_triple_extractor.py +178 -0
- dataflow/operators/multi_model_kg/generate/mmkg_visual_triple_path_qa_generator.py +145 -0
- dataflow/operators/multi_model_kg/generate/mmkg_visual_triple_subgraph_qa_generator.py +140 -0
- dataflow/operators/multi_model_kg/refine/mmkg_entity_link2database.py +96 -0
- dataflow/operators/multi_model_kg/refine/mmkg_entity_link2img.py +288 -0
- dataflow/operators/pdf2text/__init__.py +21 -0
- dataflow/operators/pdf2text/generate/kbc_chunk_generator.py +155 -0
- dataflow/operators/pdf2text/generate/kbc_chunk_generator_batch.py +175 -0
- dataflow/operators/pdf2text/generate/kbc_text_cleaner.py +137 -0
- dataflow/operators/pdf2text/generate/kbc_text_cleaner_batch.py +148 -0
- dataflow/operators/pdf2text/generate/mineru_operators.py +626 -0
- dataflow/operators/temporal_kg/__init__.py +28 -0
- dataflow/operators/temporal_kg/eval/tkg_4tuple_time_summary.py +160 -0
- dataflow/operators/temporal_kg/filter/tkg_4tuple_time_sampling.py +212 -0
- dataflow/operators/temporal_kg/generate/tkg_4tuple_extractor.py +229 -0
- dataflow/operators/temporal_kg/generate/tkg_4tuple_merge.py +177 -0
- dataflow/operators/temporal_kg/generate/tkg_attri_4tuple_qa_generator.py +140 -0
- dataflow/operators/temporal_kg/generate/tkg_rel_4tuple_conversation_generator.py +119 -0
- dataflow/operators/temporal_kg/generate/tkg_rel_4tuple_path_qa_generator.py +150 -0
- dataflow/operators/temporal_kg/generate/tkg_rel_4tuple_subgraph_qa_generator.py +140 -0
- dataflow/operators/temporal_kg/refinement/tkg_4tuple_disambiguation.py +164 -0
- dataflow/pipeline/Pipeline.py +532 -0
- dataflow/pipeline/__init__.py +5 -0
- dataflow/pipeline/nodes.py +94 -0
- dataflow/prompts/application_kg/graph_rag.py +359 -0
- dataflow/prompts/application_kg/graph_reasoning.py +222 -0
- dataflow/prompts/core_kg/attri_triple.py +1040 -0
- dataflow/prompts/core_kg/rel_triple_eval.py +816 -0
- dataflow/prompts/core_kg/rel_triple_filter.py +306 -0
- dataflow/prompts/core_kg/rel_triple_generate.py +1238 -0
- dataflow/prompts/core_kg/rel_triple_refinement.py +538 -0
- dataflow/prompts/diverse_kg/cskg.py +1077 -0
- dataflow/prompts/diverse_kg/finkg.py +1374 -0
- dataflow/prompts/diverse_kg/geokg.py +1140 -0
- dataflow/prompts/diverse_kg/hrkg.py +745 -0
- dataflow/prompts/diverse_kg/legalkg.py +612 -0
- dataflow/prompts/diverse_kg/medkg.py +366 -0
- dataflow/prompts/diverse_kg/mmkg.py +577 -0
- dataflow/prompts/diverse_kg/schokg.py +365 -0
- dataflow/prompts/diverse_kg/tkg.py +1431 -0
- dataflow/serving/LocalSentenceLLMServing.py +184 -0
- dataflow/serving/__init__.py +28 -0
- dataflow/serving/api_google_vertexai_serving.py +992 -0
- dataflow/serving/api_llm_serving_request.py +225 -0
- dataflow/serving/api_vlm_serving_openai.py +376 -0
- dataflow/serving/google_api_serving.py +53 -0
- dataflow/serving/light_rag_serving.py +146 -0
- dataflow/serving/lite_llm_serving.py +437 -0
- dataflow/serving/local_model_llm_serving.py +437 -0
- dataflow/serving/local_model_vlm_serving.py +361 -0
- dataflow/serving/localhost_llm_api_serving.py +242 -0
- dataflow/serving/localmodel_lalm_serving.py +256 -0
- dataflow/statics/pipelines/__init__.py +0 -0
- dataflow/statics/pipelines/api_pipelines/finkg_risk_pipeline.py +93 -0
- dataflow/statics/pipelines/api_pipelines/geokg_spatiotemporal_event_pipeline.py +134 -0
- dataflow/statics/pipelines/api_pipelines/graph_rag_pipeline.py +108 -0
- dataflow/statics/pipelines/api_pipelines/graph_reasoning_pipeline.py +90 -0
- dataflow/statics/pipelines/api_pipelines/hyper_kg_qa_pipeline.py +79 -0
- dataflow/statics/pipelines/api_pipelines/kg_evaluation_visualization_pipeline.py +164 -0
- dataflow/statics/pipelines/api_pipelines/kg_extraction_pipeline.py +93 -0
- dataflow/statics/pipelines/api_pipelines/kg_qa_pipeline.py +131 -0
- dataflow/statics/pipelines/api_pipelines/legalkg_application_pipeline.py +100 -0
- dataflow/statics/pipelines/api_pipelines/medkg_application_pipeline.py +72 -0
- dataflow/statics/pipelines/api_pipelines/multimodal_kg_pipeline.py +126 -0
- dataflow/statics/pipelines/api_pipelines/schokg_application_pipeline.py +73 -0
- dataflow/statics/pipelines/api_pipelines/tkg_qa_pipeline.py +96 -0
- dataflow/statics/pipelines/gpu_pipelines/graph_rag_pipeline.py +135 -0
- dataflow/statics/pipelines/gpu_pipelines/graph_reasoning_pipeline.py +109 -0
- dataflow/statics/pipelines/gpu_pipelines/hyper_kg_qa_pipeline.py +98 -0
- dataflow/statics/pipelines/gpu_pipelines/kg_extraction_pipeline.py +110 -0
- dataflow/statics/pipelines/gpu_pipelines/kg_qa_pipeline.py +144 -0
- dataflow/statics/pipelines/gpu_pipelines/tkg_qa_pipeline.py +112 -0
- dataflow/utils/__init__.py +5 -0
- dataflow/utils/core_kg/embedding_serving.py +426 -0
- dataflow/utils/diverse_kg/wikidata_client.py +241 -0
- dataflow/utils/registry.py +364 -0
- dataflow/utils/storage.py +875 -0
- dataflow/utils/utils.py +28 -0
- dataflow/version.py +23 -0
- dataflow/wrapper/__init__.py +6 -0
- dataflow/wrapper/auto_op.py +105 -0
- dataflow/wrapper/batch_wrapper.py +98 -0
- dataflow_kg-0.9.0.dist-info/METADATA +313 -0
- dataflow_kg-0.9.0.dist-info/RECORD +250 -0
- dataflow_kg-0.9.0.dist-info/WHEEL +5 -0
- dataflow_kg-0.9.0.dist-info/entry_points.txt +2 -0
- dataflow_kg-0.9.0.dist-info/licenses/LICENSE +201 -0
- dataflow_kg-0.9.0.dist-info/top_level.txt +1 -0
dataflow/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .utils import *
|
|
2
|
+
from .version import __version__, version_info
|
|
3
|
+
from .logger import get_logger
|
|
4
|
+
from .operators import *
|
|
5
|
+
from .prompts import *
|
|
6
|
+
__all__ = [
|
|
7
|
+
'__version__',
|
|
8
|
+
'version_info',
|
|
9
|
+
'get_logger',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def hello():
|
|
15
|
+
return "Hello from open-dataflow!"
|
dataflow/cli.py
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# dataflow/cli.py - Enhanced with local model judge support and eval init/run
|
|
3
|
+
# ===============================================================
|
|
4
|
+
# DataFlow 命令行入口
|
|
5
|
+
# dataflow -v 查看版本并检查更新
|
|
6
|
+
# dataflow init [...] 初始化脚本/配置
|
|
7
|
+
# dataflow env 查看环境
|
|
8
|
+
# WEBUI 已经暂时移除!!!!!
|
|
9
|
+
# dataflow webui operators [opts] 启动算子/管线 UI
|
|
10
|
+
# dataflow webui agent [opts] 启动 DataFlow-Agent UI(已整合后端)
|
|
11
|
+
# dataflow pdf2model init/train PDF to Model 训练流程
|
|
12
|
+
# dataflow text2model init/train Text to Model 训练流程
|
|
13
|
+
# dataflow chat 聊天界面
|
|
14
|
+
# dataflow eval init 初始化评估配置文件
|
|
15
|
+
# dataflow eval api 运行API模型评估
|
|
16
|
+
# dataflow eval local 运行本地模型评估
|
|
17
|
+
# ===============================================================
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import argparse
|
|
21
|
+
import requests
|
|
22
|
+
import sys
|
|
23
|
+
import re
|
|
24
|
+
import yaml
|
|
25
|
+
import json
|
|
26
|
+
import subprocess
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
from colorama import init as color_init, Fore, Style
|
|
29
|
+
from dataflow.cli_funcs import cli_env, cli_init # 项目已有工具
|
|
30
|
+
from dataflow.version import __version__ # 版本号
|
|
31
|
+
|
|
32
|
+
color_init(autoreset=True)
|
|
33
|
+
PYPI_API_URL = "https://pypi.org/pypi/open-dataflow/json"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ---------------- 版本检查 ----------------
|
|
37
|
+
def version_and_check_for_updates() -> None:
|
|
38
|
+
width = os.get_terminal_size().columns
|
|
39
|
+
print(Fore.BLUE + "=" * width + Style.RESET_ALL)
|
|
40
|
+
print(f"open-dataflow-kg codebase version: {__version__}")
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
r = requests.get(PYPI_API_URL, timeout=5)
|
|
44
|
+
r.raise_for_status()
|
|
45
|
+
remote = r.json()["info"]["version"]
|
|
46
|
+
print("\tChecking for updates...")
|
|
47
|
+
print(f"\tLocal version : {__version__}")
|
|
48
|
+
print(f"\tPyPI version : {remote}")
|
|
49
|
+
if remote != __version__:
|
|
50
|
+
print(Fore.YELLOW + f"New version available: {remote}."
|
|
51
|
+
" Run 'pip install -U open-dataflow-kg' to upgrade."
|
|
52
|
+
+ Style.RESET_ALL)
|
|
53
|
+
else:
|
|
54
|
+
print(Fore.GREEN + f"You are using the latest version: {__version__}" + Style.RESET_ALL)
|
|
55
|
+
except requests.exceptions.RequestException as e:
|
|
56
|
+
print(Fore.RED + "Failed to query PyPI – check your network." + Style.RESET_ALL)
|
|
57
|
+
print("Error:", e)
|
|
58
|
+
print(Fore.BLUE + "=" * width + Style.RESET_ALL)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# ---------------- 智能聊天功能 ----------------
|
|
62
|
+
def check_current_dir_for_model():
|
|
63
|
+
"""检查当前目录的模型文件,优先识别微调模型"""
|
|
64
|
+
current_dir = Path.cwd()
|
|
65
|
+
|
|
66
|
+
# 检查 LoRA 适配器文件
|
|
67
|
+
adapter_files = [
|
|
68
|
+
"adapter_config.json",
|
|
69
|
+
"adapter_model.bin",
|
|
70
|
+
"adapter_model.safetensors"
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
# 检查基础模型文件
|
|
74
|
+
model_files = [
|
|
75
|
+
"config.json",
|
|
76
|
+
"pytorch_model.bin",
|
|
77
|
+
"model.safetensors",
|
|
78
|
+
"tokenizer.json",
|
|
79
|
+
"tokenizer_config.json"
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
# 优先检查adapter(微调模型)
|
|
83
|
+
# 如果有adapter文件,就只返回微调模型,不管有没有基础模型文件
|
|
84
|
+
if any((current_dir / f).exists() for f in adapter_files):
|
|
85
|
+
return [("fine_tuned_model", current_dir)]
|
|
86
|
+
|
|
87
|
+
# 只有在没有adapter文件时,才检查base model
|
|
88
|
+
if any((current_dir / f).exists() for f in model_files):
|
|
89
|
+
return [("base_model", current_dir)]
|
|
90
|
+
|
|
91
|
+
return []
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_latest_trained_model(cache_path="./"):
|
|
95
|
+
"""查找最新训练的模型,支持text2model和pdf2model,按时间戳排序"""
|
|
96
|
+
current_dir = Path.cwd()
|
|
97
|
+
cache_path_obj = Path(cache_path)
|
|
98
|
+
if not cache_path_obj.is_absolute():
|
|
99
|
+
cache_path_obj = current_dir / cache_path_obj
|
|
100
|
+
|
|
101
|
+
saves_dir = cache_path_obj / ".cache" / "saves"
|
|
102
|
+
if not saves_dir.exists():
|
|
103
|
+
return None, None
|
|
104
|
+
|
|
105
|
+
all_models = []
|
|
106
|
+
|
|
107
|
+
for dir_path in saves_dir.iterdir():
|
|
108
|
+
if not dir_path.is_dir():
|
|
109
|
+
continue
|
|
110
|
+
|
|
111
|
+
model_type = None
|
|
112
|
+
timestamp = None
|
|
113
|
+
|
|
114
|
+
# 检查text2model格式 (text2model_cache_YYYYMMDD_HHMMSS)
|
|
115
|
+
if dir_path.name.startswith('text2model_cache_'):
|
|
116
|
+
timestamp_part = dir_path.name.replace('text2model_cache_', '')
|
|
117
|
+
if len(timestamp_part) == 15 and timestamp_part[8] == '_':
|
|
118
|
+
date_part = timestamp_part[:8]
|
|
119
|
+
time_part = timestamp_part[9:]
|
|
120
|
+
if date_part.isdigit() and time_part.isdigit() and len(time_part) == 6:
|
|
121
|
+
model_type = 'text2model'
|
|
122
|
+
timestamp = timestamp_part
|
|
123
|
+
|
|
124
|
+
# 检查pdf2model格式 (pdf2model_cache_YYYYMMDD_HHMMSS)
|
|
125
|
+
elif dir_path.name.startswith('pdf2model_cache_'):
|
|
126
|
+
timestamp_part = dir_path.name.replace('pdf2model_cache_', '')
|
|
127
|
+
if len(timestamp_part) == 15 and timestamp_part[8] == '_':
|
|
128
|
+
date_part = timestamp_part[:8]
|
|
129
|
+
time_part = timestamp_part[9:]
|
|
130
|
+
if date_part.isdigit() and time_part.isdigit() and len(time_part) == 6:
|
|
131
|
+
model_type = 'pdf2model'
|
|
132
|
+
timestamp = timestamp_part
|
|
133
|
+
|
|
134
|
+
# 检查其他可能的模型目录
|
|
135
|
+
else:
|
|
136
|
+
# 尝试从目录名提取时间戳
|
|
137
|
+
timestamp_match = re.search(r'(\d{8}_\d{6})', dir_path.name)
|
|
138
|
+
if timestamp_match:
|
|
139
|
+
model_type = 'pdf2model' # 默认为pdf2model
|
|
140
|
+
timestamp = timestamp_match.group(1)
|
|
141
|
+
elif 'qwen' in dir_path.name.lower() or 'model' in dir_path.name.lower():
|
|
142
|
+
# 如果找不到时间戳但看起来像模型目录,使用修改时间
|
|
143
|
+
model_type = 'pdf2model' # 默认为pdf2model
|
|
144
|
+
mtime = dir_path.stat().st_mtime
|
|
145
|
+
# 将修改时间转换为timestamp格式以便排序
|
|
146
|
+
import datetime
|
|
147
|
+
dt = datetime.datetime.fromtimestamp(mtime)
|
|
148
|
+
timestamp = dt.strftime("%Y%m%d_%H%M%S")
|
|
149
|
+
|
|
150
|
+
if model_type and timestamp:
|
|
151
|
+
all_models.append((dir_path, model_type, timestamp))
|
|
152
|
+
|
|
153
|
+
if not all_models:
|
|
154
|
+
return None, None
|
|
155
|
+
|
|
156
|
+
# 按时间戳排序,最新的在前(不管是什么类型的模型)
|
|
157
|
+
all_models.sort(key=lambda x: x[2], reverse=True)
|
|
158
|
+
latest_model_path, model_type, timestamp = all_models[0]
|
|
159
|
+
|
|
160
|
+
return latest_model_path, model_type
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def call_dataflow_chat(model_path, model_type=None):
|
|
164
|
+
"""调用dataflow的聊天功能(用于微调模型)"""
|
|
165
|
+
# 判断模型类型
|
|
166
|
+
if model_type is None:
|
|
167
|
+
# 从路径判断类型
|
|
168
|
+
path_str = str(model_path)
|
|
169
|
+
if 'text2model' in path_str:
|
|
170
|
+
model_type = 'text2model'
|
|
171
|
+
elif 'pdf2model' in path_str:
|
|
172
|
+
model_type = 'pdf2model'
|
|
173
|
+
else:
|
|
174
|
+
# 无法判断,默认尝试text2model
|
|
175
|
+
model_type = 'text2model'
|
|
176
|
+
|
|
177
|
+
if model_type == 'text2model':
|
|
178
|
+
try:
|
|
179
|
+
from dataflow.cli_funcs.cli_text import cli_text2model_chat
|
|
180
|
+
return cli_text2model_chat(str(model_path))
|
|
181
|
+
except ImportError:
|
|
182
|
+
print("Cannot find text model chat function")
|
|
183
|
+
return False
|
|
184
|
+
elif model_type == 'pdf2model':
|
|
185
|
+
try:
|
|
186
|
+
from dataflow.cli_funcs.cli_pdf import cli_pdf2model_chat
|
|
187
|
+
return cli_pdf2model_chat(str(model_path))
|
|
188
|
+
except ImportError:
|
|
189
|
+
print("Cannot find PDF model chat function")
|
|
190
|
+
return False
|
|
191
|
+
else:
|
|
192
|
+
print(f"Unknown model type: {model_type}")
|
|
193
|
+
return False
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def call_llamafactory_chat(model_path):
|
|
197
|
+
"""调用llamafactory的聊天功能(用于基础模型)"""
|
|
198
|
+
import subprocess
|
|
199
|
+
|
|
200
|
+
chat_cmd = [
|
|
201
|
+
"llamafactory-cli", "chat",
|
|
202
|
+
"--model_name_or_path", str(model_path)
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
try:
|
|
206
|
+
result = subprocess.run(chat_cmd, check=True)
|
|
207
|
+
return True
|
|
208
|
+
except subprocess.CalledProcessError as e:
|
|
209
|
+
print(f"LlamaFactory chat failed: {e}")
|
|
210
|
+
return False
|
|
211
|
+
except FileNotFoundError:
|
|
212
|
+
print("llamafactory-cli not found. Please install LlamaFactory:")
|
|
213
|
+
print("pip install llamafactory[torch,metrics]")
|
|
214
|
+
return False
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def smart_chat_command(model_path=None, cache_path="./"):
|
|
218
|
+
"""智能聊天命令,统一处理各种模型类型,不自动下载"""
|
|
219
|
+
|
|
220
|
+
if model_path:
|
|
221
|
+
# 如果明确指定了模型路径,直接使用
|
|
222
|
+
model_path_obj = Path(model_path)
|
|
223
|
+
if not model_path_obj.exists():
|
|
224
|
+
print(f"Specified model path does not exist: {model_path}")
|
|
225
|
+
return False
|
|
226
|
+
|
|
227
|
+
print(f"{Fore.CYAN}Using specified model: {model_path}{Style.RESET_ALL}")
|
|
228
|
+
|
|
229
|
+
# 检查是否有adapter文件
|
|
230
|
+
adapter_files = [
|
|
231
|
+
"adapter_config.json",
|
|
232
|
+
"adapter_model.bin",
|
|
233
|
+
"adapter_model.safetensors"
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
has_adapter = any((model_path_obj / f).exists() for f in adapter_files)
|
|
237
|
+
|
|
238
|
+
if has_adapter:
|
|
239
|
+
# 有adapter,使用dataflow chat
|
|
240
|
+
return call_dataflow_chat(model_path)
|
|
241
|
+
else:
|
|
242
|
+
# 没有adapter,使用llamafactory chat
|
|
243
|
+
return call_llamafactory_chat(model_path)
|
|
244
|
+
|
|
245
|
+
# 检查当前目录
|
|
246
|
+
detected_models = check_current_dir_for_model()
|
|
247
|
+
|
|
248
|
+
if detected_models:
|
|
249
|
+
# 优先使用fine_tuned_model(adapter)
|
|
250
|
+
for model_type, path in detected_models:
|
|
251
|
+
if model_type == "fine_tuned_model":
|
|
252
|
+
print(f"{Fore.GREEN}Found trained model in current directory: {path.name}{Style.RESET_ALL}")
|
|
253
|
+
return call_dataflow_chat(path)
|
|
254
|
+
|
|
255
|
+
# 如果没有adapter,使用base_model
|
|
256
|
+
for model_type, path in detected_models:
|
|
257
|
+
if model_type == "base_model":
|
|
258
|
+
print(f"{Fore.YELLOW}Found base model in current directory: {path.name}{Style.RESET_ALL}")
|
|
259
|
+
print(f"{Fore.CYAN}Starting chat interface...{Style.RESET_ALL}")
|
|
260
|
+
return call_llamafactory_chat(path)
|
|
261
|
+
|
|
262
|
+
# 检查缓存中的训练模型
|
|
263
|
+
latest_model, model_type = get_latest_trained_model(cache_path)
|
|
264
|
+
|
|
265
|
+
if latest_model:
|
|
266
|
+
model_name = Path(latest_model).name
|
|
267
|
+
print(f"{Fore.GREEN}Found trained model from cache: {model_name}{Style.RESET_ALL}")
|
|
268
|
+
print(f"{Fore.CYAN}Starting chat interface...{Style.RESET_ALL}")
|
|
269
|
+
|
|
270
|
+
# 检查缓存中的模型是否有adapter文件
|
|
271
|
+
latest_model_path = Path(latest_model)
|
|
272
|
+
adapter_files = [
|
|
273
|
+
"adapter_config.json",
|
|
274
|
+
"adapter_model.bin",
|
|
275
|
+
"adapter_model.safetensors"
|
|
276
|
+
]
|
|
277
|
+
|
|
278
|
+
has_adapter = any((latest_model_path / f).exists() for f in adapter_files)
|
|
279
|
+
if has_adapter:
|
|
280
|
+
return call_dataflow_chat(latest_model, model_type)
|
|
281
|
+
else:
|
|
282
|
+
print(f"No adapter files found in {latest_model}")
|
|
283
|
+
print("This doesn't appear to be a trained model directory.")
|
|
284
|
+
return False
|
|
285
|
+
|
|
286
|
+
# 如果什么都没找到,给出提示而不下载
|
|
287
|
+
print("No model found in current directory or cache.")
|
|
288
|
+
print()
|
|
289
|
+
print("Options:")
|
|
290
|
+
print("1. Train a model first:")
|
|
291
|
+
print(" dataflow text2model init && dataflow text2model train")
|
|
292
|
+
print(" dataflow pdf2model init && dataflow pdf2model train")
|
|
293
|
+
print()
|
|
294
|
+
print("2. Use an existing model:")
|
|
295
|
+
print(" dataflow chat --model /path/to/your/model")
|
|
296
|
+
print()
|
|
297
|
+
print("3. Download a model manually and place it in current directory")
|
|
298
|
+
return False
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
# ---------------- 新的eval命令处理函数 ----------------
|
|
302
|
+
def handle_python_config_init():
|
|
303
|
+
"""处理Python配置文件初始化"""
|
|
304
|
+
try:
|
|
305
|
+
from dataflow.cli_funcs.cli_eval import DataFlowEvalCLI
|
|
306
|
+
|
|
307
|
+
cli = DataFlowEvalCLI()
|
|
308
|
+
success = cli.init_eval_files() # 使用正确的方法名(复数)且无参数
|
|
309
|
+
|
|
310
|
+
if success:
|
|
311
|
+
print("Configuration files initialized successfully")
|
|
312
|
+
else:
|
|
313
|
+
print("Configuration files initialization failed")
|
|
314
|
+
|
|
315
|
+
return success
|
|
316
|
+
|
|
317
|
+
except ImportError as e:
|
|
318
|
+
print(f"Python config evaluation module unavailable: {e}")
|
|
319
|
+
print("Please check if dataflow.cli_funcs.cli_eval module exists")
|
|
320
|
+
return False
|
|
321
|
+
except Exception as e:
|
|
322
|
+
print(f"Configuration file initialization failed: {e}")
|
|
323
|
+
return False
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def handle_python_config_eval(eval_type: str, args=None):
|
|
327
|
+
"""处理Python配置文件评估模式"""
|
|
328
|
+
try:
|
|
329
|
+
from dataflow.cli_funcs.cli_eval import DataFlowEvalCLI
|
|
330
|
+
|
|
331
|
+
cli = DataFlowEvalCLI()
|
|
332
|
+
|
|
333
|
+
# 使用默认文件名
|
|
334
|
+
eval_file = f"eval_{eval_type}.py"
|
|
335
|
+
|
|
336
|
+
print(f"Starting {eval_type} model evaluation: {eval_file}")
|
|
337
|
+
|
|
338
|
+
# 传递命令行参数到评估器
|
|
339
|
+
success = cli.run_eval_file(eval_file)
|
|
340
|
+
|
|
341
|
+
if success:
|
|
342
|
+
print(f"{eval_type.upper()} model evaluation completed successfully")
|
|
343
|
+
else:
|
|
344
|
+
print(f"{eval_type.upper()} model evaluation failed")
|
|
345
|
+
|
|
346
|
+
return success
|
|
347
|
+
|
|
348
|
+
except ImportError as e:
|
|
349
|
+
print(f"Python config evaluation module unavailable: {e}")
|
|
350
|
+
print("Please check if dataflow.cli_funcs.cli_eval module exists")
|
|
351
|
+
return False
|
|
352
|
+
except Exception as e:
|
|
353
|
+
print(f"Python config evaluation failed: {e}")
|
|
354
|
+
return False
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def handle_eval_command(args):
|
|
361
|
+
"""处理评估命令 - 支持自动检测和模型指定"""
|
|
362
|
+
try:
|
|
363
|
+
eval_action = getattr(args, 'eval_action', None)
|
|
364
|
+
|
|
365
|
+
# 处理 init 子命令
|
|
366
|
+
if eval_action == 'init':
|
|
367
|
+
return handle_python_config_init()
|
|
368
|
+
|
|
369
|
+
# 处理 api 子命令
|
|
370
|
+
elif eval_action == 'api':
|
|
371
|
+
return handle_python_config_eval('api', args)
|
|
372
|
+
|
|
373
|
+
# 处理 local 子命令
|
|
374
|
+
elif eval_action == 'local':
|
|
375
|
+
return handle_python_config_eval('local', args)
|
|
376
|
+
|
|
377
|
+
# 如果没有指定子命令,显示帮助
|
|
378
|
+
else:
|
|
379
|
+
print("DataFlow Evaluation Tool")
|
|
380
|
+
print()
|
|
381
|
+
print("Available commands:")
|
|
382
|
+
print(" dataflow eval init # Initialize evaluation config files")
|
|
383
|
+
print(" dataflow eval api # Run API model evaluation (auto-detect models)")
|
|
384
|
+
print(" dataflow eval local # Run local model evaluation (auto-detect models)")
|
|
385
|
+
print()
|
|
386
|
+
print("Complete evaluation workflow:")
|
|
387
|
+
print(" 1. dataflow eval local # Auto-detect and evaluate local models")
|
|
388
|
+
print(" 2. View generated evaluation report # model_comparison_report.json")
|
|
389
|
+
print()
|
|
390
|
+
print("Config file descriptions:")
|
|
391
|
+
print(" - eval_api.py: API evaluator config (GPT-4o etc.)")
|
|
392
|
+
print(" - eval_local.py: Local evaluator config")
|
|
393
|
+
return False
|
|
394
|
+
|
|
395
|
+
except Exception as e:
|
|
396
|
+
print(f"Evaluation command execution failed: {e}")
|
|
397
|
+
import traceback
|
|
398
|
+
traceback.print_exc()
|
|
399
|
+
return False
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
# ---------------- CLI 主函数 ----------------
|
|
403
|
+
def build_arg_parser() -> argparse.ArgumentParser:
|
|
404
|
+
"""构建参数解析器"""
|
|
405
|
+
parser = argparse.ArgumentParser(
|
|
406
|
+
prog="dfkg",
|
|
407
|
+
description=f"DataFlow-KG Command-Line Interface (v{__version__})",
|
|
408
|
+
)
|
|
409
|
+
parser.add_argument("-v", "--version", action="store_true", help="Show version and exit")
|
|
410
|
+
|
|
411
|
+
# ============ 顶层子命令 ============ #
|
|
412
|
+
top = parser.add_subparsers(dest="command", required=False)
|
|
413
|
+
|
|
414
|
+
# --- init ---
|
|
415
|
+
p_init = top.add_parser("init", help="Initialize scripts/configs in current dir")
|
|
416
|
+
p_init_sub = p_init.add_subparsers(dest="subcommand", required=False)
|
|
417
|
+
p_init_sub.add_parser("all", help="Init all components").set_defaults(subcommand="all")
|
|
418
|
+
p_init_sub.add_parser("reasoning", help="Init reasoning components").set_defaults(subcommand="reasoning")
|
|
419
|
+
|
|
420
|
+
# --- env ---
|
|
421
|
+
top.add_parser("env", help="Show environment information")
|
|
422
|
+
|
|
423
|
+
# --- chat ---
|
|
424
|
+
p_chat = top.add_parser("chat", help="Start chat interface with trained model")
|
|
425
|
+
p_chat.add_argument("--model", default=None, help="Model path (default: use latest trained model from cache)")
|
|
426
|
+
p_chat.add_argument("--cache", default="./", help="Cache directory path")
|
|
427
|
+
|
|
428
|
+
# --- eval 命令
|
|
429
|
+
p_eval = top.add_parser("eval", help="Model evaluation using BenchDatasetEvaluator")
|
|
430
|
+
eval_sub = p_eval.add_subparsers(dest="eval_action", help="Evaluation actions")
|
|
431
|
+
|
|
432
|
+
# eval init 子命令
|
|
433
|
+
eval_init = eval_sub.add_parser("init", help="Initialize evaluation configuration file")
|
|
434
|
+
|
|
435
|
+
# eval api 子命令
|
|
436
|
+
eval_api = eval_sub.add_parser("api", help="Run API model evaluation")
|
|
437
|
+
|
|
438
|
+
# eval local 子命令
|
|
439
|
+
eval_local = eval_sub.add_parser("local", help="Run local model evaluation")
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
# --- pdf2model ---
|
|
443
|
+
p_pdf2model = top.add_parser("pdf2model", help="PDF to model training pipeline")
|
|
444
|
+
p_pdf2model.add_argument("--cache", default="./", help="Cache directory path")
|
|
445
|
+
p_pdf2model_sub = p_pdf2model.add_subparsers(dest="pdf2model_action", required=True)
|
|
446
|
+
|
|
447
|
+
p_pdf2model_init = p_pdf2model_sub.add_parser("init", help="Initialize PDF to model pipeline")
|
|
448
|
+
|
|
449
|
+
p_pdf2model_train = p_pdf2model_sub.add_parser("train", help="Start training after PDF processing")
|
|
450
|
+
p_pdf2model_train.add_argument("--lf_yaml", default=None,
|
|
451
|
+
help="LlamaFactory config file (default: {cache}/.cache/train_config.yaml)")
|
|
452
|
+
|
|
453
|
+
# --- text2model ---
|
|
454
|
+
p_text2model = top.add_parser("text2model", help="Train model from JSON/JSONL data")
|
|
455
|
+
p_text2model_sub = p_text2model.add_subparsers(dest="text2model_action", required=True)
|
|
456
|
+
|
|
457
|
+
p_text2model_init = p_text2model_sub.add_parser("init", help="Initialize text2model pipeline")
|
|
458
|
+
p_text2model_init.add_argument("--cache", default="./", help="Cache directory path")
|
|
459
|
+
|
|
460
|
+
p_text2model_train = p_text2model_sub.add_parser("train", help="Start training after text processing")
|
|
461
|
+
p_text2model_train.add_argument('input_dir', nargs='?', default='./',
|
|
462
|
+
help='Input directory to scan (default: ./)')
|
|
463
|
+
p_text2model_train.add_argument('--input-keys', default=None,
|
|
464
|
+
help='Fields to process (default: text)')
|
|
465
|
+
p_text2model_train.add_argument("--lf_yaml", default=None,
|
|
466
|
+
help="LlamaFactory config file (default: {cache}/.cache/train_config.yaml)")
|
|
467
|
+
|
|
468
|
+
# --- webui ---
|
|
469
|
+
p_webui = top.add_parser("webui", help="Launch Gradio WebUI")
|
|
470
|
+
p_webui.add_argument("-H", "--host", default="127.0.0.1", help="Bind host (default 127.0.0.1)")
|
|
471
|
+
p_webui.add_argument("-P", "--port", type=int, default=7862, help="Port (default 7862)")
|
|
472
|
+
p_webui.add_argument("--show-error", action="store_true", help="Show Gradio error tracebacks")
|
|
473
|
+
|
|
474
|
+
# webui 二级子命令:operators / agent
|
|
475
|
+
w_sub = p_webui.add_subparsers(dest="ui_mode", required=False)
|
|
476
|
+
w_sub.add_parser("operators", help="Launch operator / pipeline UI")
|
|
477
|
+
w_sub.add_parser("agent", help="Launch DataFlow-Agent UI (backend included)")
|
|
478
|
+
w_sub.add_parser("pdf", help="Launch PDF Knowledge Base Cleaning UI")
|
|
479
|
+
|
|
480
|
+
return parser
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def main() -> None:
|
|
484
|
+
"""主入口函数"""
|
|
485
|
+
parser = build_arg_parser()
|
|
486
|
+
args = parser.parse_args()
|
|
487
|
+
|
|
488
|
+
# ---------- 顶层逻辑分发 ----------
|
|
489
|
+
if args.version:
|
|
490
|
+
version_and_check_for_updates()
|
|
491
|
+
return
|
|
492
|
+
|
|
493
|
+
if args.command == "init":
|
|
494
|
+
cli_init(subcommand=args.subcommand or "base")
|
|
495
|
+
|
|
496
|
+
elif args.command == "env":
|
|
497
|
+
cli_env()
|
|
498
|
+
|
|
499
|
+
elif args.command == "eval":
|
|
500
|
+
handle_eval_command(args)
|
|
501
|
+
|
|
502
|
+
elif args.command == "pdf2model":
|
|
503
|
+
if args.pdf2model_action == "init":
|
|
504
|
+
from dataflow.cli_funcs.cli_pdf import cli_pdf2model_init
|
|
505
|
+
cli_pdf2model_init(cache_path=args.cache)
|
|
506
|
+
elif args.pdf2model_action == "train":
|
|
507
|
+
from dataflow.cli_funcs.cli_pdf import cli_pdf2model_train
|
|
508
|
+
# If no lf_yaml specified, use default path relative to cache
|
|
509
|
+
lf_yaml = args.lf_yaml or f"{args.cache}/.cache/train_config.yaml"
|
|
510
|
+
cli_pdf2model_train(lf_yaml=lf_yaml, cache_path=args.cache)
|
|
511
|
+
|
|
512
|
+
elif args.command == "text2model":
|
|
513
|
+
from dataflow.cli_funcs.cli_text import cli_text2model_init, cli_text2model_train
|
|
514
|
+
|
|
515
|
+
if args.text2model_action == "init":
|
|
516
|
+
cli_text2model_init(cache_path=getattr(args, 'cache', './'))
|
|
517
|
+
elif args.text2model_action == "train":
|
|
518
|
+
# 如果没有指定lf_yaml,使用默认路径
|
|
519
|
+
lf_yaml = getattr(args, 'lf_yaml', None) or "./.cache/train_config.yaml"
|
|
520
|
+
cli_text2model_train(input_keys=getattr(args, 'input_keys', None), lf_yaml=lf_yaml)
|
|
521
|
+
|
|
522
|
+
elif args.command == "chat":
|
|
523
|
+
smart_chat_command(model_path=args.model, cache_path=args.cache)
|
|
524
|
+
|
|
525
|
+
elif args.command == "webui":
|
|
526
|
+
# 默认使用 operators
|
|
527
|
+
mode = args.ui_mode or "operators"
|
|
528
|
+
if mode == "operators":
|
|
529
|
+
print("Currently webui is under maintenance. Please check back later.")
|
|
530
|
+
# from dataflow.webui.operator_pipeline import demo
|
|
531
|
+
# demo.launch(
|
|
532
|
+
# server_name=args.host,
|
|
533
|
+
# server_port=args.port,
|
|
534
|
+
# show_error=args.show_error,
|
|
535
|
+
# )
|
|
536
|
+
elif mode == "agent":
|
|
537
|
+
print("Agent UI is deprecated in Dataflow main repo, please use the dedicated https://github.com/OpenDCAI/DataFlow-Agent repo.")
|
|
538
|
+
elif mode == "pdf":
|
|
539
|
+
print("Currently webui is under maintenance. Please check back later.")
|
|
540
|
+
# from dataflow.webui import kbclean_webui
|
|
541
|
+
# kbclean_webui.create_ui().launch()
|
|
542
|
+
else:
|
|
543
|
+
parser.error(f"Unknown ui_mode {mode!r}")
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
if __name__ == "__main__":
|
|
547
|
+
main()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import torch
|
|
3
|
+
import platform
|
|
4
|
+
from colorama import init, Fore, Style
|
|
5
|
+
from dataflow import __version__
|
|
6
|
+
import importlib.metadata
|
|
7
|
+
from .paths import DataFlowPath
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def is_torch_cuda_available():
|
|
11
|
+
"""
|
|
12
|
+
Check if CUDA is available for PyTorch.
|
|
13
|
+
"""
|
|
14
|
+
return torch.cuda.is_available()
|
|
15
|
+
|
|
16
|
+
def get_env_info():
|
|
17
|
+
info = {
|
|
18
|
+
"`Dataflow` version": __version__,
|
|
19
|
+
"`Dataflow` install path": DataFlowPath.get_dataflow_dir(),
|
|
20
|
+
"Platform": platform.platform(),
|
|
21
|
+
"Python version": platform.python_version(),
|
|
22
|
+
"PyTorch version": torch.__version__,
|
|
23
|
+
"Torchvision version": torch.__version__,
|
|
24
|
+
}
|
|
25
|
+
if is_torch_cuda_available():
|
|
26
|
+
info["PyTorch version"] += " (GPU)"
|
|
27
|
+
info["GPU type"] = torch.cuda.get_device_name()
|
|
28
|
+
info["GPU number"] = torch.cuda.device_count()
|
|
29
|
+
info["GPU memory"] = f"{torch.cuda.mem_get_info()[1] / (1024**3):.2f}GB"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
import deepspeed # type: ignore
|
|
34
|
+
|
|
35
|
+
info["DeepSpeed version"] = deepspeed.__version__
|
|
36
|
+
except Exception:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
import bitsandbytes # type: ignore
|
|
41
|
+
|
|
42
|
+
info["Bitsandbytes version"] = bitsandbytes.__version__
|
|
43
|
+
except Exception:
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
import vllm
|
|
48
|
+
|
|
49
|
+
info["vLLM version"] = vllm.__version__
|
|
50
|
+
except Exception:
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
import sglang
|
|
55
|
+
info["SGLang version"] = sglang.__version__
|
|
56
|
+
except Exception:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
mineru_version = importlib.metadata.version("mineru")
|
|
61
|
+
info["MinerU version"] = mineru_version
|
|
62
|
+
except Exception:
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
import subprocess
|
|
67
|
+
# get the dir of imdlbenco package
|
|
68
|
+
imdlbenco_dir = os.path.dirname(os.path.abspath(__file__))
|
|
69
|
+
# move to this dir and get the git commit hash in a subprocess
|
|
70
|
+
# but don't change the current working directory
|
|
71
|
+
os.chdir(imdlbenco_dir)
|
|
72
|
+
commit_info = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, check=True)
|
|
73
|
+
commit_hash = commit_info.stdout.strip()
|
|
74
|
+
info["Git commit"] = commit_hash
|
|
75
|
+
except Exception:
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
print(Fore.BLUE + "=" * os.get_terminal_size().columns + Style.RESET_ALL)
|
|
79
|
+
print("\n" + "\n".join([f"- {key}: {value}" for key, value in info.items()]) + "\n")
|
|
80
|
+
print(Fore.BLUE + "=" * os.get_terminal_size().columns + Style.RESET_ALL)
|
|
81
|
+
|
|
82
|
+
def cli_env():
|
|
83
|
+
get_env_info()
|
|
84
|
+
|
|
85
|
+
if __name__ == "__main__":
|
|
86
|
+
print(get_env_info())
|