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

Function process_llm_batch

CommonKG/create_kg.py:34–60  ·  view source on GitHub ↗

处理单个批次的LLM请求

(item_batch, llm_processer, ref_kg_path)

Source from the content-addressed store, hash-verified

32
33
34def process_llm_batch(item_batch, llm_processer, ref_kg_path):
35 """
36 处理单个批次的LLM请求
37 """
38 doc_name, source_id, text, match_words = (
39 item_batch["doc_name"],
40 item_batch["source_id"],
41 item_batch["text"],
42 item_batch["match_words"]
43 )
44
45 # 生成大模型推理输入文件
46 prompt = llm_processer.extract_triple_prompt(text, match_words, ref_kg_path)
47 # 大模型推理
48 response = llm_processer.infer(prompt)
49 # 推理结果后处理(三元组过滤)
50 infer_triples, head_entities, tail_entities = Triple.get_triple(match_words, response)
51 # 再次调用大模型对实体进行验证
52 verify_entities = llm_processer.entity_evaluate(tail_entities)
53
54 return {
55 "doc_name": doc_name,
56 "source_id": source_id,
57 "infer_triples": infer_triples,
58 "head_entities": head_entities,
59 "verify_entities": verify_entities
60 }
61
62
63def extract_desc(triple_path, corpus_path, task_conf, llm_processer):

Callers

nothing calls this directly

Calls 4

extract_triple_promptMethod · 0.80
inferMethod · 0.80
get_tripleMethod · 0.80
entity_evaluateMethod · 0.80

Tested by

no test coverage detected