1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
using System.Text.Json;
namespace Tango.Portal.Chat.Web.Services
{
public sealed class SchemaRegistry
{
private readonly IWebHostEnvironment _env;
private readonly ILogger<SchemaRegistry> _log;
private readonly AIInstructionService _instructionService;
private string? _cached;
public SchemaRegistry(IWebHostEnvironment env, ILogger<SchemaRegistry> log, AIInstructionService instructionService)
{
_env = env;
_log = log;
_instructionService = instructionService;
}
public string GetSchemaJson()
{
if (!string.IsNullOrEmpty(_cached)) return _cached!;
var path = Path.Combine(_env.ContentRootPath, "Data", "schema.json");
if (!File.Exists(path))
{
_log.LogWarning("Schema file not found at {Path}. Returning empty schema.", path);
_cached = "{\"tables\":{}}";
return _cached!;
}
_cached = File.ReadAllText(path);
// Basic sanity check
JsonDocument.Parse(_cached);
return _cached!;
}
public async Task<string> GetPlannerPromptAsync()
{
var path = Path.Combine(_env.ContentRootPath, "Data", "planner_prompt.txt");
if (!File.Exists(path))
{
_log.LogWarning("Planner prompt file not found at {Path}. Returning empty prompt.", path);
return string.Empty;
}
var basePrompt = File.ReadAllText(path);
var aiInstructions = await _instructionService.GetInstructionsTextAsync();
if (!string.IsNullOrWhiteSpace(aiInstructions))
{
return $"{basePrompt}\n\nAdditional Instructions:\n{aiInstructions}";
}
return basePrompt;
}
public string GetPlannerPrompt()
{
// Keep synchronous version for backward compatibility
var path = Path.Combine(_env.ContentRootPath, "Data", "planner_prompt.txt");
if (!File.Exists(path))
{
_log.LogWarning("Planner prompt file not found at {Path}. Returning empty prompt.", path);
return string.Empty;
}
return File.ReadAllText(path);
}
public string GetPlotySample()
{
var path = Path.Combine(_env.ContentRootPath, "Data", "ploty_sample.txt");
if (!File.Exists(path))
{
_log.LogWarning("Ploty sample file not found at {Path}. Returning empty prompt.", path);
return string.Empty;
}
return File.ReadAllText(path);
}
}
}
|