blob: 1c48b93a27d87917b703e40a81abb5837e88a4a0 (
plain)
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
|
using System.Text.Json;
namespace Tango.Portal.Chat.Web.Services
{
public sealed class SchemaRegistry
{
private readonly IWebHostEnvironment _env;
private readonly ILogger<SchemaRegistry> _log;
private string? _cached;
public SchemaRegistry(IWebHostEnvironment env, ILogger<SchemaRegistry> log)
{
_env = env; _log = log;
}
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 string GetPlannerPrompt()
{
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);
}
}
}
|