diff --git a/My1kWordsEe/Models/SampleWord.cs b/My1kWordsEe/Models/SampleWord.cs index d4bb06d..49d75de 100644 --- a/My1kWordsEe/Models/SampleWord.cs +++ b/My1kWordsEe/Models/SampleWord.cs @@ -37,6 +37,12 @@ public string[] EnWords /// public required string EnExplanation { get; init; } + + /// + /// Explaining the word in Estonian + /// + public string? EeExplanation { get; init; } + /// /// Sample pronunciation of the word /// diff --git a/My1kWordsEe/Services/Ai/OpenAiClient.cs b/My1kWordsEe/Services/Ai/OpenAiClient.cs index b7dc223..3591752 100644 --- a/My1kWordsEe/Services/Ai/OpenAiClient.cs +++ b/My1kWordsEe/Services/Ai/OpenAiClient.cs @@ -119,9 +119,10 @@ public static async Task> GetWordMetadata(this OpenAiClient o "Teie väljund on sõna metaandmed JSON-is vastavalt antud lepingule:\n" + "```\n{\n" + "\"ee_word\": \"\",\n" + - "\"en_word\": \"\"\n" + - "\"en_words\": []\n" + - "\"en_explanation\": \"\"\n" + + "\"en_word\": \"\",\n" + + "\"en_words\": [],\n" + + "\"en_explanation\": \"\",\n" + + "\"ee_explanation\": \"\"\n" + "}\n```\n"; var response = await openAiClient.CompleteAsync(prompt, eeWord, new ChatCompletionOptions @@ -158,14 +159,15 @@ public static async Task> GetWordMetadata(this OpenAiClient o EnWord = wordMetadata.EnWord, EnWords = wordMetadata.EnWords, EnExplanation = wordMetadata.EnExplanation, + EeExplanation = wordMetadata.EeExplanation, }); } - public static async Task> GetSampleSentence(this OpenAiClient openAiClient, string eeWord, string[]? existingSamples = null) + public static async Task> GetSampleSentence(this OpenAiClient openAiClient, string eeWord, string explanation, string[]? existingSamples = null) { var prompt = "Sa oled keeleõppe süsteemi abiline, mis aitab õppida enim levinud eesti keele sõnu.\n" + - "Sinu sisend on üks sõna eesti keeles.\n" + + "Sinu sisend on üks eestikeelne sõna ja selle rakenduse kontekst: ().\n" + "Sinu ülesanne on kirjutada selle kasutamise kohta lihtne lühike näitelause, kasutades seda sõna.\n" + "Lauses kasuta kõige levinuimaid ja lihtsamaid sõnu eesti keeles et toetada keeleõpet.\n" + "Eelistan SVO-lausete sõnajärge, kus esikohal on subjekt (S), seejärel tegusõna (V) ja objekt (O)\n" + @@ -178,7 +180,7 @@ public static async Task> GetSampleSentence(this OpenAiClient o ? "PS: Ärge korrake järgmisi näidiseid, olge erinevad:\n" + string.Join(",", existingSamples.Select(s => $"'{s}'")) : string.Empty); - return await openAiClient.CompleteJsonAsync(prompt, eeWord); + return await openAiClient.CompleteJsonAsync(prompt, $"{eeWord} (${explanation})"); } private class WordMetadata @@ -192,6 +194,9 @@ private class WordMetadata [JsonPropertyName("en_explanation")] public required string EnExplanation { get; set; } + [JsonPropertyName("ee_explanation")] + public required string EeExplanation { get; set; } + [JsonPropertyName("en_words")] public required string[] EnWords { get; set; } = Array.Empty(); } diff --git a/My1kWordsEe/Services/Cqs/AddSampleSentenceCommand.cs b/My1kWordsEe/Services/Cqs/AddSampleSentenceCommand.cs index 9f6b53d..eb40207 100644 --- a/My1kWordsEe/Services/Cqs/AddSampleSentenceCommand.cs +++ b/My1kWordsEe/Services/Cqs/AddSampleSentenceCommand.cs @@ -35,6 +35,7 @@ public async Task> Invoke(SampleWord word) var sentence = await this.openAiService.GetSampleSentence( eeWord: word.EeWord, + explanation: word.EeExplanation ?? word.EnExplanation, existingSamples: word.Samples.Select(s => s.EeSentence).ToArray()); if (sentence.IsFailure) {