prompt_factory.py centralizes all prompt engineering variants used by the KG extractor. Each method (zero-shot, few-shot, CoT, etc.) returns the same nodes/edges output format so downstream parsers can remain consistent.
from kgextractor.prompt_factory import KGPromptFactory
factory = KGPromptFactory()
prompt_text = factory.build_prompt("few_shot", sample_text)build_prompt accepts any method named in KGPromptFactory.methods. To preview every prompt for a passage run the module directly:
python kgextractor/prompt_factory.pySet PROMPT_FACTORY_RUN_LLM=1 to actually call the configured models; otherwise it only prints the prompts.
PROMPT_FACTORY_MODEL: generation model (defaults togpt-5-miniwhen running the script,gpt-4o-miniinside helper calls).PROMPT_FACTORY_EVAL_MODEL: for now it is the same asPROMPT_FACTORY_MODEL.PROMPT_FACTORY_TEMPERATURE: optional float forwarded to OpenAI. Leave unset for models that enforce their built-in temperature (e.g., GPT‑5).PROMPT_FACTORY_RUN_LLM: set to1to enable live LLM calls insidemain().PROMPT_FACTORY_API_BASE: base REST endpoint for OpenAI-compatible services (falls back toOPENAI_BASE_URL/OPENAI_API_BASEif unset).PROMPT_FACTORY_API_KEY: alternative env name for the API key; otherwiseOPENAI_API_KEYis used.PROMPT_FACTORY_API_HEADERS: Optional. JSON object string with extra headers (e.g.,{"api-key": "..."}) for custom gateways.PROMPT_FACTORY_ORGANIZATION: Optional. overrides the organization header (falls back toOPENAI_ORGANIZATION).
When PROMPT_FACTORY_RUN_LLM=1, the script:
- Builds each prompt for a sample passage.
- Calls the generation model via
run_prompt_via_openai. - Parses nodes/edges and re-sends them to the evaluator prompt (
evaluate_graph_with_llm). - Stores prompt, generation, and feedback under
results/<model>/prompt_test_<method>_<model>.txt.
Add new prompt styles by:
- Implementing a
get_<name>_prompt(self, text: str) -> str. - Registering it in the
mappingdict insidebuild_prompt. - Optionally add examples to
_init_examplesto reuse across strategies.