| | | 1 | | using System.Text.Json; |
| | | 2 | | using EHonda.KicktippAi.Core; |
| | | 3 | | |
| | | 4 | | namespace OpenAiIntegration; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Shared helpers for building prompt inputs used by prediction and reconstruction flows. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class PredictionPromptComposer |
| | | 10 | | { |
| | | 11 | | public static string BuildSystemPrompt(string template, IEnumerable<DocumentContext> contextDocuments) |
| | | 12 | | { |
| | 1 | 13 | | var contextList = contextDocuments.ToList(); |
| | 1 | 14 | | if (!contextList.Any()) |
| | | 15 | | { |
| | 1 | 16 | | return template; |
| | | 17 | | } |
| | | 18 | | |
| | 1 | 19 | | var contextSection = "\n"; |
| | 1 | 20 | | foreach (var doc in contextList) |
| | | 21 | | { |
| | 1 | 22 | | contextSection += "---\n"; |
| | 1 | 23 | | contextSection += $"{doc.Name}\n\n"; |
| | 1 | 24 | | contextSection += $"{doc.Content}\n"; |
| | | 25 | | } |
| | | 26 | | |
| | 1 | 27 | | contextSection += "---"; |
| | 1 | 28 | | return template + contextSection; |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public static string CreateMatchJson(Match match) |
| | | 32 | | { |
| | 1 | 33 | | return JsonSerializer.Serialize(new |
| | 1 | 34 | | { |
| | 1 | 35 | | homeTeam = match.HomeTeam, |
| | 1 | 36 | | awayTeam = match.AwayTeam, |
| | 1 | 37 | | startsAt = match.StartsAt.ToString() |
| | 1 | 38 | | }, new JsonSerializerOptions |
| | 1 | 39 | | { |
| | 1 | 40 | | Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping |
| | 1 | 41 | | }); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public static string CreateBonusQuestionJson(BonusQuestion question) |
| | | 45 | | { |
| | 1 | 46 | | var questionData = new |
| | 1 | 47 | | { |
| | 1 | 48 | | text = question.Text, |
| | 1 | 49 | | options = question.Options.Select(o => new { id = o.Id, text = o.Text }).ToArray(), |
| | 1 | 50 | | maxSelections = question.MaxSelections |
| | 1 | 51 | | }; |
| | | 52 | | |
| | 1 | 53 | | return JsonSerializer.Serialize(questionData, new JsonSerializerOptions |
| | 1 | 54 | | { |
| | 1 | 55 | | Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping |
| | 1 | 56 | | }); |
| | | 57 | | } |
| | | 58 | | } |