MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / main

Function main

CommonKG/create_kg.py:348–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

346
347
348def main():
349 ## 读取配置文件
350 conf_path = "CommonKG/config/create_kg_conf_test.yaml"
351 with open(conf_path, "r", encoding="utf-8") as file:
352 args = yaml.safe_load(file)
353
354 logger.info(f"args:\n{args}\n")
355
356 task_conf = args["task_conf"] ## 任务参数
357
358 # 迭代提取次数
359 llm_conf = args["llm_conf"] ## llm参数
360 llm_processer = LLM_Processor(llm_conf)
361
362
363 # 输入路径处理(支持文件/文件夹)
364 input_path = task_conf["corpus_path"]
365 output_dir = task_conf["output_dir"]
366 if os.path.isfile(input_path):
367 files_to_process = [input_path]
368 elif os.path.isdir(input_path):
369 files_to_process = [os.path.join(input_path, f) for f in os.listdir(input_path) if f.endswith(".jsonl")]
370 else:
371 raise ValueError(f"Invalid input path: {input_path}")
372
373 # 批量处理
374 success_count = 0
375
376 # 移动chunk文件
377 for corpus_path in tqdm(files_to_process, desc="Processing files"):
378 if process_single_file(corpus_path, task_conf, llm_processer, output_dir):
379 success_count += 1
380
381 logger.info(f"Processed {success_count}/{len(files_to_process)} files successfully")
382
383
384

Callers 1

create_kg.pyFile · 0.70

Calls 2

LLM_ProcessorClass · 0.90
process_single_fileFunction · 0.85

Tested by

no test coverage detected