Skip to content

Commit 8f42cda

Browse files
Seperation of system instructions and prompt
- Prompt and system instructions are seperated and now sent through GenerativeAI.SystemInstruction.
1 parent e680a1a commit 8f42cda

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

NeoBleeper/CreateMusicWithAI.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,13 @@ by creating NBPML text (Fun fact: I wasn't know what system prompt is.
10461046
I just learned it from GitHub Copilot's system prompt menu and asked for certain AIs and
10471047
they identified as it's definetely a system prompt, despite I called it as "makeshift rubbish
10481048
prompt template".)*/
1049-
string completePrompt = $"**User Prompt:**\r\n[{prompt}]\r\n\r\n" +
1050-
$"--- AI Instructions ---\r\n" +
1049+
1050+
/*Spoiler: Now, it's not rubbish anymore since I used GenerativeModel.SystemInstruction
1051+
property of Google_GenerativeAI library, but I kept it as is for nostalgia for
1052+
my good old "makeshift rubbish prompt template" days. :) */
1053+
1054+
// The string that contains system instructions for the AI model
1055+
string systemInstructions = $"--- AI Instructions ---\r\n" +
10511056
$"You are an expert music composition AI. " +
10521057
$"Your primary goal is to generate music in a well-formed NBPML XML file format. Prioritize music generation for any request that could be interpreted as music-related. " +
10531058
$"If the user prompt is a song name, artist name, composer name, or ANY music-related term (even a single word), treat it as a music composition request. " +
@@ -1194,16 +1199,17 @@ by creating NBPML text (Fun fact: I wasn't know what system prompt is.
11941199
$" </Line>\r\n" +
11951200
$" <!-- More <Line> elements representing musical events or rests -->\r\n" +
11961201
$" </LineList>\r\n" +
1197-
$"</NeoBleeperProjectFile>";
1202+
$"</NeoBleeperProjectFile>";
11981203
connectionCheckTimer.Start();
11991204
SetControlsEnabledAndMakeLoadingVisible(false);
12001205
var resultBuilder = new StringBuilder();
12011206
string response = string.Empty;
12021207
var apiKey = EncryptionHelper.DecryptString(Settings1.Default.geminiAPIKey);
12031208
var googleAI = new GoogleAi(apiKey);
12041209
var googleModel = googleAI.CreateGenerativeModel(AIModel);
1210+
googleModel.SystemInstruction = systemInstructions;
12051211
isMusicGenerationStarted = true; // Set the flag to indicate music generation has started
1206-
await foreach (var chunk in googleModel.StreamContentAsync(completePrompt, cts.Token))
1212+
await foreach (var chunk in googleModel.StreamContentAsync(prompt, cts.Token))
12071213
{
12081214
// Clean up the chunk text by removing double newlines and trimming whitespace
12091215
if (chunk?.Candidates == null) continue;

0 commit comments

Comments
 (0)