From 7c051e66d05c872c18e47cdf8faf8c80b1c4c702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Tue, 21 Mar 2023 21:28:48 +0100 Subject: [PATCH] Add more settings --- ChatGPT.CLI/Program.cs | 1 + ChatGPT.Core/Defaults.cs | 6 +++++ .../ViewModels/Chat/ChatSettingsViewModel.cs | 27 +++++++++++++++++++ .../ViewModels/MainViewModel.Chats.cs | 3 +++ ChatGPT.UI/Views/Chat/ChatSettingsView.axaml | 3 +++ ChatGPT/Model/Services/ChatServiceSettings.cs | 2 ++ ChatGPT/Services/ChatService.cs | 4 +-- 7 files changed, 44 insertions(+), 2 deletions(-) diff --git a/ChatGPT.CLI/Program.cs b/ChatGPT.CLI/Program.cs index 6a3bed69..745f1028 100644 --- a/ChatGPT.CLI/Program.cs +++ b/ChatGPT.CLI/Program.cs @@ -25,6 +25,7 @@ You are a helpful assistant named Clippy. Settings = new ChatSettingsViewModel { Temperature = 0.7m, + TopP = 1m, MaxTokens = 2000, Model = "gpt-3.5-turbo", Directions = directions diff --git a/ChatGPT.Core/Defaults.cs b/ChatGPT.Core/Defaults.cs index 55825c11..af69c3f8 100644 --- a/ChatGPT.Core/Defaults.cs +++ b/ChatGPT.Core/Defaults.cs @@ -6,6 +6,12 @@ public static class Defaults public const decimal DefaultTemperature = 0.7m; + public const decimal DefaultTopP = 1m; + + public const decimal DefaultPresencePenalty = 0m; + + public const decimal DefaultFrequencyPenalty = 0m; + public const int DefaultMaxTokens = 256; public const string DefaultModel = "gpt-3.5-turbo"; diff --git a/ChatGPT.Core/ViewModels/Chat/ChatSettingsViewModel.cs b/ChatGPT.Core/ViewModels/Chat/ChatSettingsViewModel.cs index 0d59a667..2bbe1325 100644 --- a/ChatGPT.Core/ViewModels/Chat/ChatSettingsViewModel.cs +++ b/ChatGPT.Core/ViewModels/Chat/ChatSettingsViewModel.cs @@ -6,6 +6,9 @@ namespace ChatGPT.ViewModels.Chat; public partial class ChatSettingsViewModel : ObservableObject { private decimal _temperature; + private decimal _topP; + private decimal _presencePenalty; + private decimal _frequencyPenalty; private int _maxTokens; private string? _apiKey; private string? _model; @@ -19,6 +22,27 @@ public decimal Temperature set => SetProperty(ref _temperature, value); } + [JsonPropertyName("top_p")] + public decimal TopP + { + get => _topP; + set => SetProperty(ref _topP, value); + } + + [JsonPropertyName("presence_penalty")] + public decimal PresencePenalty + { + get => _presencePenalty; + set => SetProperty(ref _presencePenalty, value); + } + + [JsonPropertyName("frequency_penalty")] + public decimal FrequencyPenalty + { + get => _frequencyPenalty; + set => SetProperty(ref _frequencyPenalty, value); + } + [JsonPropertyName("maxTokens")] public int MaxTokens { @@ -59,6 +83,9 @@ public ChatSettingsViewModel Copy() return new ChatSettingsViewModel { Temperature = _temperature, + TopP = _topP, + PresencePenalty = _presencePenalty, + FrequencyPenalty = _frequencyPenalty, MaxTokens = _maxTokens, ApiKey = _apiKey, Model = _model, diff --git a/ChatGPT.Core/ViewModels/MainViewModel.Chats.cs b/ChatGPT.Core/ViewModels/MainViewModel.Chats.cs index d69821ac..be1dc195 100644 --- a/ChatGPT.Core/ViewModels/MainViewModel.Chats.cs +++ b/ChatGPT.Core/ViewModels/MainViewModel.Chats.cs @@ -58,6 +58,9 @@ private ChatSettingsViewModel CreateDefaultChatSettings() return new ChatSettingsViewModel { Temperature = Defaults.DefaultTemperature, + TopP = Defaults.DefaultTopP, + PresencePenalty = Defaults.DefaultPresencePenalty, + FrequencyPenalty = Defaults.DefaultFrequencyPenalty, MaxTokens = Defaults.DefaultMaxTokens, Model = Defaults.DefaultModel, ApiKey = null, diff --git a/ChatGPT.UI/Views/Chat/ChatSettingsView.axaml b/ChatGPT.UI/Views/Chat/ChatSettingsView.axaml index 737d71c3..fdc8357c 100644 --- a/ChatGPT.UI/Views/Chat/ChatSettingsView.axaml +++ b/ChatGPT.UI/Views/Chat/ChatSettingsView.axaml @@ -10,6 +10,9 @@ 0.6 + 1 + 0 + 0 100 diff --git a/ChatGPT/Model/Services/ChatServiceSettings.cs b/ChatGPT/Model/Services/ChatServiceSettings.cs index 59767da0..449e82f3 100644 --- a/ChatGPT/Model/Services/ChatServiceSettings.cs +++ b/ChatGPT/Model/Services/ChatServiceSettings.cs @@ -10,5 +10,7 @@ public class ChatServiceSettings public decimal Temperature { get; set; } public int MaxTokens { get; set; } public decimal TopP { get; set; } + public decimal PresencePenalty { get; set; } + public decimal FrequencyPenalty { get; set; } public string? Stop { get; set; } } diff --git a/ChatGPT/Services/ChatService.cs b/ChatGPT/Services/ChatService.cs index 509a21a4..3a3904f5 100644 --- a/ChatGPT/Services/ChatService.cs +++ b/ChatGPT/Services/ChatService.cs @@ -35,8 +35,8 @@ private static string GetRequestBodyJson(ChatServiceSettings settings) N = 1, Stream = false, Stop = settings.Stop, - FrequencyPenalty = 0.0m, - PresencePenalty = 0.0m, + FrequencyPenalty = settings.FrequencyPenalty, + PresencePenalty = settings.PresencePenalty, User = null };