blob: 3ba6ad0c588776925c2d0b14d16d5a71cb1eb156 (
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
|
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);
}
}
}
|