|
| 1 | +namespace GraphRag.Config; |
| 2 | + |
| 3 | +public sealed class ClaimExtractionConfig |
| 4 | +{ |
| 5 | + private const string DefaultDescription = "Any claims or facts that could be relevant to information discovery."; |
| 6 | + |
| 7 | + public bool Enabled { get; set; } |
| 8 | + |
| 9 | + public string ModelId { get; set; } = "default_chat_model"; |
| 10 | + |
| 11 | + public string? Prompt { get; set; } |
| 12 | + |
| 13 | + public string Description { get; set; } = DefaultDescription; |
| 14 | + |
| 15 | + public int MaxGleanings { get; set; } = 1; |
| 16 | + |
| 17 | + public Dictionary<string, object?>? Strategy { get; set; } |
| 18 | + = new(StringComparer.OrdinalIgnoreCase); |
| 19 | + |
| 20 | + public Dictionary<string, object?> GetResolvedStrategy(string? rootDirectory = null) |
| 21 | + { |
| 22 | + if (Strategy is { Count: > 0 }) |
| 23 | + { |
| 24 | + return new Dictionary<string, object?>(Strategy, StringComparer.OrdinalIgnoreCase); |
| 25 | + } |
| 26 | + |
| 27 | + string? promptPayload = null; |
| 28 | + if (!string.IsNullOrWhiteSpace(Prompt)) |
| 29 | + { |
| 30 | + var baseDir = string.IsNullOrWhiteSpace(rootDirectory) |
| 31 | + ? Directory.GetCurrentDirectory() |
| 32 | + : rootDirectory!; |
| 33 | + var fullPath = Path.IsPathRooted(Prompt!) |
| 34 | + ? Prompt! |
| 35 | + : Path.Combine(baseDir, Prompt!); |
| 36 | + |
| 37 | + if (!File.Exists(fullPath)) |
| 38 | + { |
| 39 | + throw new FileNotFoundException($"Claim extraction prompt '{fullPath}' could not be found.", fullPath); |
| 40 | + } |
| 41 | + |
| 42 | + promptPayload = File.ReadAllText(fullPath); |
| 43 | + } |
| 44 | + |
| 45 | + return new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase) |
| 46 | + { |
| 47 | + ["model_id"] = ModelId, |
| 48 | + ["extraction_prompt"] = promptPayload, |
| 49 | + ["claim_description"] = Description, |
| 50 | + ["max_gleanings"] = MaxGleanings |
| 51 | + }; |
| 52 | + } |
| 53 | +} |
0 commit comments