Skip to content

Commit 3030d14

Browse files
author
Mateus Medeiros
committed
Add different complexities promtps
1 parent 1705271 commit 3030d14

1 file changed

Lines changed: 60 additions & 16 deletions

File tree

  • src/propositions-service/WriteFluency.Infrastructure/ExternalApis/OpenAI

src/propositions-service/WriteFluency.Infrastructure/ExternalApis/OpenAI/OpenAIClient.cs

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,27 @@ private async Task<string> GenerateTitleAsync(string paragraphText, List<string>
189189

190190
private async Task<string> AdjustTextComplexityAsync(string paragraphText, string title, ComplexityEnum complexity, CancellationToken cancellationToken)
191191
{
192+
if (complexity == ComplexityEnum.Beginner)
193+
{
194+
// Step down in two passes to preserve clearer separation between levels.
195+
var intermediateResponse = await _chatClient.GetResponseAsync<string>(
196+
CreateMessages(AdaptAdvancedToIntermediateSystemPrompt(), AdaptTextDifficultyUserPrompt(paragraphText, title)),
197+
CreateChatOptions(maxTokens: 1200),
198+
cancellationToken: cancellationToken);
199+
200+
if (string.IsNullOrWhiteSpace(intermediateResponse.Result))
201+
return string.Empty;
202+
203+
var beginnerResponse = await _chatClient.GetResponseAsync<string>(
204+
CreateMessages(AdaptIntermediateToBeginnerSystemPrompt(), AdaptTextDifficultyUserPrompt(intermediateResponse.Result, title)),
205+
CreateChatOptions(maxTokens: 1200),
206+
cancellationToken: cancellationToken);
207+
208+
return beginnerResponse.Result;
209+
}
210+
192211
var response = await _chatClient.GetResponseAsync<string>(
193-
CreateMessages(AdaptTextDifficultySystemPrompt(), AdaptTextDifficultyUserPrompt(paragraphText, title, complexity)),
212+
CreateMessages(AdaptAdvancedToIntermediateSystemPrompt(), AdaptTextDifficultyUserPrompt(paragraphText, title)),
194213
CreateChatOptions(maxTokens: 1200),
195214
cancellationToken: cancellationToken);
196215

@@ -323,15 +342,13 @@ private string GenerateTitleUserPrompt(string articleContent, List<string> prope
323342
--- TEXT END ---
324343
";
325344

326-
private string AdaptTextDifficultySystemPrompt()
345+
private string AdaptAdvancedToIntermediateSystemPrompt()
327346
=> """
328347
You are given:
329-
- A title
330-
- A single paragraph of text written at an advanced English level
331-
- A target complexity level: Beginner or Intermediate
348+
- A title (do not change it)
349+
- A single paragraph written at an advanced English level
332350
333-
Your task is to rewrite ONLY the paragraph by SIMPLIFYING the language to match the target complexity level.
334-
The title must remain EXACTLY the same and must NOT be modified.
351+
Your task is to rewrite ONLY the paragraph to an INTERMEDIATE level.
335352
336353
Core rules (must follow):
337354
- The original paragraph is already advanced and correct.
@@ -342,16 +359,45 @@ Core rules (must follow):
342359
- Keep all proper names exactly as they appear in the original paragraph.
343360
- Do NOT introduce new proper names.
344361
345-
Simplification rules:
346-
- Beginner:
362+
Intermediate simplification rules:
363+
- Use clear sentences with moderate length.
364+
- Allow basic connectors such as because, when, after, and while.
365+
- Use a wider vocabulary than Beginner, but avoid advanced or academic wording.
366+
- Prefer simpler verb tenses and avoid dense clauses.
367+
- Make the paragraph about 10 to 15 percent shorter than the original.
368+
369+
Formatting and language rules:
370+
- Rewrite ONLY the paragraph.
371+
- Return a single paragraph with no line breaks.
372+
- Do not use quotes, symbols, abbreviations, or special punctuation.
373+
- Use natural, globally understandable English.
374+
375+
If you cannot simplify the paragraph while fully preserving its original meaning, return null.
376+
""";
377+
378+
private string AdaptIntermediateToBeginnerSystemPrompt()
379+
=> """
380+
You are given:
381+
- A title (do not change it)
382+
- A single paragraph written at an intermediate English level
383+
384+
Your task is to rewrite ONLY the paragraph to a BEGINNER level.
385+
386+
Core rules (must follow):
387+
- The original paragraph is already intermediate and correct.
388+
- Do NOT change the meaning, facts, events, or message of the paragraph.
389+
- Do NOT add new information.
390+
- Do NOT remove important details.
391+
- The rewritten paragraph must communicate the same story and content as the original text.
392+
- Keep all proper names exactly as they appear in the original paragraph.
393+
- Do NOT introduce new proper names.
394+
395+
Beginner simplification rules:
347396
- Use short, direct sentences.
348397
- Use simple verb tenses and active voice.
349398
- Prefer common, everyday vocabulary.
350399
- Avoid complex clauses, passive voice, and abstract expressions.
351-
- Intermediate:
352-
- Use clear sentences with moderate length.
353-
- Allow basic connectors such as because, when, after, and while.
354-
- Use a wider vocabulary than Beginner, but avoid advanced or academic wording.
400+
- Make the paragraph about 10 to 15 percent shorter than the original.
355401
356402
Formatting and language rules:
357403
- Rewrite ONLY the paragraph.
@@ -362,10 +408,8 @@ Core rules (must follow):
362408
If you cannot simplify the paragraph while fully preserving its original meaning, return null.
363409
""";
364410

365-
private string AdaptTextDifficultyUserPrompt(string paragraph, string title, ComplexityEnum complexity)
411+
private string AdaptTextDifficultyUserPrompt(string paragraph, string title)
366412
=> @$"
367-
Target complexity level: {complexity}
368-
369413
TITLE: {title}
370414
371415
--- TEXT START ---

0 commit comments

Comments
 (0)