Skip to content

Commit 7f7c670

Browse files
committed
feat(translate): support LLM parameters - temperature, top_p
1 parent f7242c4 commit 7f7c670

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

FlyleafLib/MediaPlayer/Translation/Services/ITranslateSettings.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,36 @@ public virtual string ChatPath
179179
public int TimeoutMs { get; set => Set(ref field, value); } = 15000;
180180
public int TimeoutHealthMs { get; set => Set(ref field, value); } = 2000;
181181

182+
#region LLM Parameters
183+
public double Temperature
184+
{
185+
get;
186+
set
187+
{
188+
if (value is >= 0.0 and <= 2.0)
189+
{
190+
Set(ref field, Math.Round(value, 2));
191+
}
192+
}
193+
} = 0.0;
194+
195+
public bool TemperatureManual { get; set => Set(ref field, value); } = true;
196+
197+
public double TopP
198+
{
199+
get;
200+
set
201+
{
202+
if (value is >= 0.0 and <= 1.0)
203+
{
204+
Set(ref field, Math.Round(value, 2));
205+
}
206+
}
207+
} = 1;
208+
209+
public bool TopPManual { get; set => Set(ref field, value); }
210+
#endregion
211+
182212
/// <summary>
183213
/// GetHttpClient
184214
/// </summary>

FlyleafLib/MediaPlayer/Translation/Services/OpenAIBaseTranslateService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ private static async Task<string> SendChatRequest(
165165
model = settings.Model,
166166
stream = false,
167167
messages = messages,
168+
169+
temperature = settings.TemperatureManual ? settings.Temperature : null,
170+
top_p = settings.TopPManual ? settings.TopP : null
168171
};
169172

170173
if (!settings.ModelRequired && string.IsNullOrWhiteSpace(settings.Model))
@@ -260,6 +263,8 @@ public class OpenAIRequest
260263
public string? model { get; set; }
261264
public OpenAIMessage[] messages { get; set; }
262265
public bool stream { get; set; }
266+
public double? temperature { get; set; }
267+
public double? top_p { get; set; }
263268
}
264269

265270
public class OpenAIResponse

LLPlayer/Controls/Settings/Trans/OpenAIBaseTranslateControl.xaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,55 @@
9797
IsReadOnly="True"
9898
Text="{Binding Status, Mode=OneWay}" />
9999
</DockPanel>
100+
101+
<Expander Header="LLM Parameters">
102+
<StackPanel Margin="10">
103+
<StackPanel Orientation="Horizontal" Margin="0 0 0 12"
104+
VerticalAlignment="Center">
105+
<TextBlock
106+
Width="180"
107+
Text="temperature" />
108+
<CheckBox
109+
Content="Manual"
110+
IsChecked="{Binding TemperatureManual}" />
111+
<Slider
112+
Minimum="0" Maximum="1" TickFrequency="0.01" IsSnapToTickEnabled="True"
113+
Margin="8 0 0 0"
114+
Value="{Binding Temperature, Mode=TwoWay}"
115+
Width="200"
116+
Style="{StaticResource MaterialDesignDiscreteSlider}"
117+
materialDesign:SliderAssist.OnlyShowFocusVisualWhileDragging="True"
118+
IsEnabled="{Binding TemperatureManual}" />
119+
<TextBox
120+
Width="40"
121+
Text="{Binding Temperature}"
122+
IsEnabled="{Binding TemperatureManual}"
123+
helpers:TextBoxHelper.OnlyNumeric="Double" />
124+
</StackPanel>
125+
126+
<StackPanel Orientation="Horizontal" Margin="0 0 0 12"
127+
VerticalAlignment="Center">
128+
<TextBlock
129+
Width="180"
130+
Text="top_p" />
131+
<CheckBox
132+
Content="Manual"
133+
IsChecked="{Binding TopPManual}" />
134+
<Slider
135+
Minimum="0" Maximum="1" TickFrequency="0.01" IsSnapToTickEnabled="True"
136+
Margin="8 0 0 0"
137+
Value="{Binding TopP, Mode=TwoWay}"
138+
Width="200"
139+
Style="{StaticResource MaterialDesignDiscreteSlider}"
140+
materialDesign:SliderAssist.OnlyShowFocusVisualWhileDragging="True"
141+
IsEnabled="{Binding TopPManual}" />
142+
<TextBox
143+
Width="40"
144+
Text="{Binding TopP}"
145+
IsEnabled="{Binding TopPManual}"
146+
helpers:TextBoxHelper.OnlyNumeric="Double" />
147+
</StackPanel>
148+
</StackPanel>
149+
</Expander>
100150
</StackPanel>
101151
</UserControl>

0 commit comments

Comments
 (0)