Skip to content

Commit

Permalink
Marketing Text Empty Response Fix (#690)
Browse files Browse the repository at this point in the history
#### Summary 
While generating marketing text, if you choose format "Tag Line +
Paragraph", there is an empty response shown. This PR fixes the issue by
making 2 LLM calls, one for each "Tag Line" and Paragraph. This is a
short term mitigation to avoid changing prompts.

#### Work Item(s) 

Fixes
[AB#504345](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/504345)

Co-authored-by: Qasim Ikram <qaikram@microsoft.com>
  • Loading branch information
qasimikram and qikram authored Mar 5, 2024
1 parent ff165fb commit 4fdfab0
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ codeunit 2012 "Entity Text Impl."

Session.LogMessage('0000JVG', TelemetryGenerationRequestedTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', TelemetryCategoryLbl);

Suggestion := GenerateAndReviewCompletion(SystemPrompt, UserPrompt, TextFormat, Facts, CallerModuleInfo);
Suggestion := GenerateAndReviewCompletion(SystemPrompt, UserPrompt, TextFormat, Facts, CallerModuleInfo, Tone, TextEmphasis);

exit(Suggestion);
end;
Expand Down Expand Up @@ -272,15 +272,26 @@ codeunit 2012 "Entity Text Impl."
end;

[NonDebuggable]
local procedure GenerateAndReviewCompletion(SystemPrompt: Text; UserPrompt: Text; TextFormat: Enum "Entity Text Format"; Facts: Dictionary of [Text, Text]; CallerModuleInfo: ModuleInfo): Text
local procedure GenerateAndReviewCompletion(SystemPrompt: Text; UserPrompt: Text; TextFormat: Enum "Entity Text Format"; Facts: Dictionary of [Text, Text]; CallerModuleInfo: ModuleInfo; Tone: Enum "Entity Text Tone"; TextEmphasis: Enum "Entity Text Emphasis"): Text
var
Completion: Text;
CompletionTag: Text;
CompletionPar: Text;
MaxAttempts: Integer;
Attempt: Integer;
begin
MaxAttempts := 5;
for Attempt := 0 to MaxAttempts do begin
Completion := GenerateCompletion(SystemPrompt, UserPrompt, CallerModuleInfo);
if TextFormat = TextFormat::TaglineParagraph then begin
BuildPrompts(Facts, Tone, TextFormat::Tagline, TextEmphasis, SystemPrompt, UserPrompt);
CompletionTag := GenerateCompletion(SystemPrompt, UserPrompt, CallerModuleInfo);

BuildPrompts(Facts, Tone, TextFormat::Paragraph, TextEmphasis, SystemPrompt, UserPrompt);
CompletionPar := GenerateCompletion(SystemPrompt, UserPrompt, CallerModuleInfo);
Completion := CompletionTag + EncodedNewlineTok + EncodedNewlineTok + CompletionPar;
end
else
Completion := GenerateCompletion(SystemPrompt, UserPrompt, CallerModuleInfo);

if (not CompletionContainsPrompt(Completion, SystemPrompt)) and IsGoodCompletion(Completion, TextFormat, Facts) then
exit(Completion);
Expand Down

0 comments on commit 4fdfab0

Please sign in to comment.