Skip to content

Commit 9fd8ead

Browse files
committed
Refactor project dependencies and update LmStudioClient.
Added asset control to package references and included Newtonsoft.Json for better dependency management. Refactored `LmStudioClient` to use a public constructor, removing the static `Create` method, and improved the naming of the assistant's system message. Minor code cleanup and formatting adjustments for better readability.
1 parent 7d13665 commit 9fd8ead

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

source/Commas/Commas.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="libse" IncludeAssets="compile"/>
18+
19+
<!-- https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets-->
1820
<PackageReference Include="Newtonsoft.Json" IncludeAssets="compile"/>
1921
</ItemGroup>
2022

source/Commas/LmStudioClient.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class LmStudioClient : IDisposable
1010
private readonly string _prompt;
1111
private readonly HttpClient _httpClient;
1212

13-
private LmStudioClient(string url, string prompt)
13+
public LmStudioClient(string url, string prompt)
1414
{
1515
_prompt = prompt;
1616
_httpClient = new HttpClient()
@@ -40,7 +40,7 @@ public async Task<string> SendAsync(string text)
4040
var chatCompletionRequest = new ChatCompletionRequest(false, new[]
4141
{
4242
new Message("user", $"{_prompt}:\n\"{text}\""),
43-
new Message("system", "You are very good at fixing commas.")
43+
new Message("system", "You are a helpful assistant.")
4444
}, 0.7);
4545

4646
var json = JsonConvert.SerializeObject(chatCompletionRequest);
@@ -57,11 +57,6 @@ public async Task<string> SendAsync(string text)
5757

5858
public void Dispose() => _httpClient.Dispose();
5959

60-
public static LmStudioClient Create(string endpoint, string prompt)
61-
{
62-
return new LmStudioClient(endpoint, prompt);
63-
}
64-
6560
public class ChatCompletionRequest(bool stream, Message[] messages, double temperature)
6661
{
6762
[JsonProperty("stream")]

source/Commas/Main.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public Main(Subtitle subtitle)
2020

2121
private async void buttonFixComma_Click(object sender, EventArgs e)
2222
{
23-
using var lmStudioClient = LmStudioClient.Create(textBoxEndPoint.Text, textBoxPrompt.Text);
23+
24+
using var lmStudioClient = new LmStudioClient(textBoxEndPoint.Text, textBoxPrompt.Text);
2425

2526
// listView1.BeginUpdate();
2627
_cancellationTokenSource = new CancellationTokenSource();

source/LibSeBasedPlugin/LibSeBasedPlugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="libse" />
10+
<PackageReference Include="libse" IncludeAssets="compile" />
1111
</ItemGroup>
1212
</Project>

source/LibSeBasedPlugin/LibSePlugin.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public class LibSePlugin : IPlugin
1717
public string Shortcut { get; } = "";
1818

1919
public string DoAction(Form parentForm, string srtText, double frameRate, string uiLineBreak, string file,
20-
string videoFile,
21-
string rawText)
20+
string videoFile, string rawText)
2221
{
2322
#if DEBUG
2423
if (!Debugger.IsAttached)
@@ -29,13 +28,11 @@ public string DoAction(Form parentForm, string srtText, double frameRate, string
2928
var subrip = new SubRip();
3029
var subtitle = new Subtitle();
3130
subrip.LoadSubtitle(subtitle, srtText.SplitToLines(), file);
32-
33-
31+
3432
// var subtitle = new Subtitle();
3533
// var format = subtitle.LoadSubtitle(rawText, out _, Encoding.UTF8);
3634
// if (format == null) return string.Empty;
3735

38-
3936
return subrip.ToText(subtitle, "");
4037
}
4138
}

0 commit comments

Comments
 (0)