Skip to content

feat(llm): support semi-automated prompt generation#281

Merged
imbajin merged 12 commits intoapache:mainfrom
LRriver:dev_prompt
Jul 1, 2025
Merged

feat(llm): support semi-automated prompt generation#281
imbajin merged 12 commits intoapache:mainfrom
LRriver:dev_prompt

Conversation

@LRriver
Copy link
Copy Markdown
Contributor

@LRriver LRriver commented Jun 25, 2025

Overview

This PR aims to introduce a semi-automated Prompt generation feature #253. This functionality leverages the capabilities of large language models (LLMs), allowing users to generate a highly customized Prompt for knowledge graph extraction by simply providing the original text, a description of the desired scenario, and selecting one example from a few system-provided examples that best matches their scenario. The generated Prompt serves as a reference for users, reducing the difficulty for them to get started.

Main Changes

  • New Operator: prompt_generate.py

    • Adds the PromptGenerate operator, which is responsible for constructing the meta-prompt by combining user inputs with a selected few-shot example, invoking the LLM, and returning the generated prompt.
  • Built-in Prompt Examples & Configuration:

    • Adds prompt_examples.json, a centralized file to store multiple, high-quality, structured few-shot examples for different domains.
    • Updates prompt_config.py with a new meta-prompt template (generate_extract_prompt_template) designed to guide the LLM in this generation task.
  • UI & Workflow Updates:

    • Updates vector_graph_block.py to add a collapsible "Assist in generating graph extraction prompts" section in the “Build RAG Index” tab.
    • This new UI section includes a dropdown for selecting few-shot examples and a dynamic preview area that updates on selection.
    • Fixes a UI "cold start" bug by implementing a demo.load() event to ensure the preview for the default example is displayed on initial page load.

Also refer hugegraph#30 (comment)

Sequence Diagram

sequenceDiagram
    participant User
    participant UI as Gradio UI
    participant PromptGen as PromptGenerate
    participant LLM as LLM后端
    participant Resource as 示例资源

    User->>UI: 选择示例、输入场景与文本,点击生成提示
    UI->>PromptGen: 调用 generate_prompt_for_ui()
    PromptGen->>Resource: 加载 few-shot 示例
    PromptGen->>LLM: 组装元提示,调用 LLM.generate()
    LLM-->>PromptGen: 返回生成的抽取提示
    PromptGen-->>UI: 返回生成的抽取提示
    UI-->>User: 展示生成的抽取提示
Loading

New UI interface features

New interface location

image
Expected scenario/direction and few-shot

image
image
prompt generate by LLM

image

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 25, 2025
@github-actions github-actions Bot added the llm label Jun 25, 2025
@dosubot dosubot Bot added the enhancement New feature or request label Jun 25, 2025
LRriver and others added 7 commits July 1, 2025 00:38
Reordered and deduplicated imports for consistency in base_prompt_config.py, vector_graph_block.py, and prompt_generate.py. Made minor code style improvements and fixed typos in comments to enhance readability and maintainability.
@imbajin imbajin changed the title feat(prompt_gen ):Add semi-automated prompt generation feature feat(llm): support semi-automated prompt generation Jul 1, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 1, 2025
@imbajin imbajin merged commit 52a666e into apache:main Jul 1, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer llm size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants