|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | + |
| 7 | +namespace Microsoft.KernelMemory.InteractiveSetup.Doctor; |
| 8 | + |
| 9 | +public static class Check |
| 10 | +{ |
| 11 | + public static void Run() |
| 12 | + { |
| 13 | + KernelMemoryConfig? config = AppSettings.ReadConfig(); |
| 14 | + |
| 15 | + if (config == null) |
| 16 | + { |
| 17 | + Console.WriteLine("No configuration found."); |
| 18 | + return; |
| 19 | + } |
| 20 | + |
| 21 | + var stats = new List<Tuple<string, string>>(); |
| 22 | + var services = new HashSet<string>(); |
| 23 | + var warnings = new List<Tuple<string, string>>(); |
| 24 | + var errors = new List<Tuple<string, string>>(); |
| 25 | + |
| 26 | + Orchestration.Run(config, stats, services, warnings, errors); |
| 27 | + stats.AddSeparator(); |
| 28 | + EmbeddingGeneration.Run(config, stats, services, warnings, errors); |
| 29 | + Storage.Run(config, stats, services, warnings, errors); |
| 30 | + stats.AddSeparator(); |
| 31 | + |
| 32 | + // Partitioning |
| 33 | + stats.Add("Text partitioning", $"Line:{config.DataIngestion.TextPartitioning.MaxTokensPerLine}; Paragraph:{config.DataIngestion.TextPartitioning.MaxTokensPerParagraph}; Overlapping:{config.DataIngestion.TextPartitioning.OverlappingTokens}"); |
| 34 | + |
| 35 | + // Image OCR |
| 36 | + stats.Add("Image OCR", string.IsNullOrWhiteSpace(config.DataIngestion.ImageOcrType) ? "Disabled" : config.DataIngestion.ImageOcrType); |
| 37 | + |
| 38 | + // Text Generation |
| 39 | + if (string.IsNullOrWhiteSpace(config.TextGeneratorType)) |
| 40 | + { |
| 41 | + errors.Add("Text Generation", "No text generation service configured"); |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + stats.Add("Text Generation", config.TextGeneratorType); |
| 46 | + } |
| 47 | + |
| 48 | + // Moderation |
| 49 | + stats.Add("Moderation", string.IsNullOrWhiteSpace(config.ContentModerationType) ? "Disabled" : config.ContentModerationType); |
| 50 | + if (string.IsNullOrWhiteSpace(config.ContentModerationType)) |
| 51 | + { |
| 52 | + warnings.Add("Moderation", "No moderation service configured"); |
| 53 | + } |
| 54 | + |
| 55 | + ShowStats("Service configuration", stats); |
| 56 | + Services.CheckAndShow(config, services, warnings, errors); |
| 57 | + ShowStats("Warnings", warnings); |
| 58 | + ShowStats("Errors", errors); |
| 59 | + Environment.Exit(0); |
| 60 | + } |
| 61 | + |
| 62 | + private static void ShowStats(string title, List<Tuple<string, string>> stats) |
| 63 | + { |
| 64 | + var columnWidth = 1 + stats.Select(stat => stat.Item1.Length).Prepend(0).Max(); |
| 65 | + |
| 66 | + Console.WriteLine($"\n\u001b[1;37m### {title}\u001b[0m\n"); |
| 67 | + var count = 0; |
| 68 | + foreach (var kv in stats) |
| 69 | + { |
| 70 | + if (string.IsNullOrWhiteSpace(kv.Item1)) |
| 71 | + { |
| 72 | + Console.WriteLine(); |
| 73 | + continue; |
| 74 | + } |
| 75 | + |
| 76 | + Console.WriteLine($"{kv.Item1.PadRight(columnWidth)}: {kv.Item2}"); |
| 77 | + count++; |
| 78 | + } |
| 79 | + |
| 80 | + if (count == 0) |
| 81 | + { |
| 82 | + Console.WriteLine("None."); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments