Skip to content

Commit fcf346e

Browse files
committed
Refactor prompt handling and enhance text processing logic
Moved prompt configuration to a dedicated method for clarity and updated the default prompt text. Adjusted text processing logic to handle individual lines separately, improving handling of models with limited capabilities. Removed unnecessary system message from request payload for streamlined communication.
1 parent 96acd44 commit fcf346e

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

source/Commas/Main.Designer.cs

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/Commas/Main.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public Main(Subtitle subtitle)
2121

2222
Closing += (sender, args) => { _ = CancelAndDisposeResources(); };
2323
buttonOkay.Click += ButtonOkayOnClick;
24+
25+
ConfigurePrompt();
26+
}
27+
28+
private void ConfigurePrompt()
29+
{
30+
textBoxPrompt.Text = "Fix commas only, " +
31+
"do not remove or add any words, " +
32+
"do not change the meaning of the sentence, " +
33+
"do do add or remove any other puntuation, " +
34+
"do not censor, " +
35+
"give only the output without comments or notes:";
2436
}
2537

2638
private void ButtonOkayOnClick(object sender, EventArgs e)
@@ -96,11 +108,26 @@ await Task.Run(async () =>
96108
}
97109

98110
var paragraph = _subtitle.Paragraphs[index];
99-
var output = await lmStudioClient.SendAsync(paragraph.Text).ConfigureAwait(false);
100111

101-
if (!output.Equals(paragraph.Text, StringComparison.Ordinal))
112+
var lines = paragraph.Text.SplitToLines();
113+
114+
// try sending each line individually to avoid messing up with the line that
115+
// doesn't require fixing which tends to happen when using less capable models
116+
for (var i = 0; i < lines.Count; i++)
117+
{
118+
string line = lines[i];
119+
120+
// remove formatting before sending as some models also remove formattings unintentionally
121+
var st = new StrippableText(line);
122+
st.StrippedText = await lmStudioClient.SendAsync(st.StrippedText).ConfigureAwait(false);
123+
lines[i] = st.MergedString;
124+
}
125+
126+
string result = string.Join(Environment.NewLine, lines);
127+
128+
if (!result.Equals(paragraph.Text, StringComparison.Ordinal))
102129
{
103-
progress.Report((new ListViewItem(new[] { paragraph.Text, output })
130+
progress.Report((new ListViewItem(new[] { paragraph.Text, result })
104131
{
105132
Tag = paragraph,
106133
}, index));

source/Commas/Services/LmStudioClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public async Task<string> SendAsync(string text)
3838

3939
var chatCompletionRequest = new ChatCompletionRequest(false, new[]
4040
{
41-
new Message("user", $"{_prompt}:\n\n{text}"),
42-
new Message("system", "You are a helpful assistant.")
41+
new Message("user", $"{_prompt}: \n\n{text}"),
42+
// new Message("system", "You are a helpful assistant.")
4343
}, 0.7);
4444

4545
var json = JsonConvert.SerializeObject(chatCompletionRequest);

0 commit comments

Comments
 (0)