-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLLMOptions.cs
More file actions
70 lines (56 loc) · 2.32 KB
/
LLMOptions.cs
File metadata and controls
70 lines (56 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.ComponentModel.DataAnnotations;
using PropertyTools.DataAnnotations;
using WindowTranslator.ComponentModel;
using WindowTranslator.Modules;
using WindowTranslator.Plugin.LLMPlugin.Properties;
namespace WindowTranslator.Plugin.LLMPlugin;
public class LLMOptions : IPluginParam
{
[SelectorStyle(SelectorStyle.ComboBox)]
public CorrectMode CorrectMode { get; set; }
public bool WaitCorrect { get; set; }
[EditableItemsSource(nameof(ModelCandidates))]
public string? Model { get; set; } = "gpt-4o-mini";
[System.ComponentModel.Browsable(false)]
public IReadOnlyList<string> ModelCandidates { get; set; } = [];
[DataType(DataType.Password)]
public string? ApiKey { get; set; }
[LocalizedDescription(typeof(Resources), $"{nameof(Endpoint)}_Desc")]
public string? Endpoint { get; set; }
[Height(120)]
[DataType(DataType.MultilineText)]
public string? CorrectSample { get; set; }
[Height(120)]
[DataType(DataType.MultilineText)]
public string? TranslateContext { get; set; }
[FileExtensions(Extensions = ".csv")]
[InputFilePath(".csv", "CSV (.csv)|*.csv")]
public string? GlossaryPath { get; set; }
}
public enum CorrectMode
{
[LocalizedDescription(typeof(Resources), $"{nameof(CorrectMode)}_{nameof(None)}")]
None,
[LocalizedDescription(typeof(Resources), $"{nameof(CorrectMode)}_{nameof(Text)}")]
Text,
[LocalizedDescription(typeof(Resources), $"{nameof(CorrectMode)}_{nameof(Image)}")]
Image,
}
public class LLMOptionsValidator : ITargetSettingsValidator
{
public ValueTask<ValidateResult> Validate(TargetSettings settings)
{
var op = settings.PluginParams.GetValueOrDefault(nameof(LLMOptions)) as LLMOptions;
// APIキーが設定されている場合は有効
if (!string.IsNullOrEmpty(op?.ApiKey))
{
return ValueTask.FromResult(ValidateResult.Valid);
}
// 翻訳モジュールでも補正も利用しない場合は無条件で有効
if (settings.SelectedPlugins[nameof(ITranslateModule)] != nameof(LLMTranslator) && (op?.CorrectMode ?? CorrectMode.None) == CorrectMode.None)
{
return ValueTask.FromResult(ValidateResult.Valid);
}
return ValueTask.FromResult(ValidateResult.Invalid("ChatGPT API", Resources.InvalidOptions));
}
}