From 28a743ebc00c8c0927db7820da4da5edab1748b1 Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:29:52 +0100 Subject: [PATCH] add option to show debug messages for AI chat --- Dockerfile | 1 + SecondBotEvents/Config/ChatGptConfig.cs | 6 ++++++ SecondBotEvents/Services/ChatGptService.cs | 12 +++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd5286c..490503b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,6 +117,7 @@ ENV basic_Username='' \ chatgpt_ChatHistoryMessages='5' \ chatgpt_ChatPrompt='respond as if you are a horse that knows its going to the glue factory and you are upset about this fact' \ chatgpt_Provider='openai' \ + chatgtp_ShowDebug='false' \ onevent_Enabled='false' \ onevent_Count=0 \ chatgpt_ChatHistoryTimeout='15' \ diff --git a/SecondBotEvents/Config/ChatGptConfig.cs b/SecondBotEvents/Config/ChatGptConfig.cs index e95070a..2e83a80 100644 --- a/SecondBotEvents/Config/ChatGptConfig.cs +++ b/SecondBotEvents/Config/ChatGptConfig.cs @@ -25,9 +25,15 @@ namespace SecondBotEvents.Config settings.Add("ChatHistoryMessages"); settings.Add("ChatPrompt"); settings.Add("ChatHistoryTimeout"); + settings.Add("ShowDebug"); settings.Add("Provider"); } + public bool GetShowDebug() + { + return ReadSettingAsBool("ShowDebug", false); + } + public int GetChatHistoryTimeout() { return ReadSettingAsInt("ChatHistoryTimeout", 15); diff --git a/SecondBotEvents/Services/ChatGptService.cs b/SecondBotEvents/Services/ChatGptService.cs index 9a7c309..1a25c07 100644 --- a/SecondBotEvents/Services/ChatGptService.cs +++ b/SecondBotEvents/Services/ChatGptService.cs @@ -309,9 +309,12 @@ namespace SecondBotEvents.Services else if (role == "assistant") messages.Add(ChatMessage.FromAssistant(thismessage)); } } - catch + catch (Exception ex) { - //LogFormater.Warn("error building AI request:" + ex.Message); + if (myConfig.GetShowDebug() == true) + { + LogFormater.Warn("error building AI request:" + ex.Message); + } return; } } @@ -413,7 +416,10 @@ namespace SecondBotEvents.Services } catch (Exception ex) { - LogFormater.Warn("An error occurred: " + ex.Message); + if (myConfig.GetShowDebug() == true) + { + LogFormater.Warn("An error occurred:" + ex.Message); + } } }