Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marketing Text Empty Response Fix #690

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading