feat(graph): enhance graph extraction prompt rendering and language context handling

- Added a new method to render graph extraction prompts with shared placeholders for language.
- Updated entity and relationship extraction methods to utilize the new rendering function, improving prompt customization.
- Enhanced question generation task to include language context, ensuring prompts are generated in the correct language.
- Improved error handling for empty prompt configurations in question generation, enhancing robustness.
This commit is contained in:
wizardchen
2026-03-20 13:37:31 +08:00
committed by lyingbug
parent 08ac3937ac
commit 59d2f6b54c
2 changed files with 30 additions and 44 deletions
+10 -2
View File
@@ -85,6 +85,14 @@ func NewGraphBuilder(config *config.Config, chatModel chat.Chat) types.GraphBuil
}
}
// renderGraphExtractionPrompt applies shared placeholders (e.g. {{language}}, {{lang}}) to graph extraction templates.
func (b *graphBuilder) renderGraphExtractionPrompt(ctx context.Context, template string) string {
lang := types.LanguageNameFromContext(ctx)
return types.RenderPromptPlaceholders(template, types.PlaceholderValues{
"language": lang,
})
}
// extractEntities extracts entities from text chunks
// It uses LLM to analyze text content and identify relevant entities
func (b *graphBuilder) extractEntities(ctx context.Context, chunk *types.Chunk) ([]*types.Entity, error) {
@@ -101,7 +109,7 @@ func (b *graphBuilder) extractEntities(ctx context.Context, chunk *types.Chunk)
messages := []chat.Message{
{
Role: "system",
Content: b.config.Conversation.ExtractEntitiesPrompt,
Content: b.renderGraphExtractionPrompt(ctx, b.config.Conversation.ExtractEntitiesPrompt),
},
{
Role: "user",
@@ -212,7 +220,7 @@ func (b *graphBuilder) extractRelationships(ctx context.Context,
messages := []chat.Message{
{
Role: "system",
Content: b.config.Conversation.ExtractRelationshipsPrompt,
Content: b.renderGraphExtractionPrompt(ctx, b.config.Conversation.ExtractRelationshipsPrompt),
},
{
Role: "user",