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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user