From 47601ba6b5e23102a4af1780c627de065ef3b8ca Mon Sep 17 00:00:00 2001 From: ZouJin Date: Tue, 14 Mar 2023 02:40:04 +1100 Subject: [PATCH] =?UTF-8?q?ChatGPT=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet-Simulator.Windows/Function/ITalkBox.cs | 17 + VPet-Simulator.Windows/MainWindow.cs | 7 +- VPet-Simulator.Windows/MainWindow.xaml.cs | 14 +- .../VPet-Simulator.Windows.csproj | 21 + .../WinDesign/TalkBox.xaml.cs | 8 +- .../WinDesign/TalkBoxAPI.xaml | 22 + .../WinDesign/TalkBoxAPI.xaml.cs | 84 ++ .../WinDesign/winCGPTSetting.xaml | 58 ++ .../WinDesign/winCGPTSetting.xaml.cs | 63 ++ .../WinDesign/winGameSetting.xaml | 776 +++++++++--------- .../WinDesign/winGameSetting.xaml.cs | 67 +- .../WinDesign/winReport.xaml | 4 +- VPet-Simulator.Windows/packages.config | 2 + 13 files changed, 729 insertions(+), 414 deletions(-) create mode 100644 VPet-Simulator.Windows/Function/ITalkBox.cs create mode 100644 VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml create mode 100644 VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml.cs create mode 100644 VPet-Simulator.Windows/WinDesign/winCGPTSetting.xaml create mode 100644 VPet-Simulator.Windows/WinDesign/winCGPTSetting.xaml.cs diff --git a/VPet-Simulator.Windows/Function/ITalkBox.cs b/VPet-Simulator.Windows/Function/ITalkBox.cs new file mode 100644 index 0000000..f5847ca --- /dev/null +++ b/VPet-Simulator.Windows/Function/ITalkBox.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace VPet_Simulator.Windows +{ + public interface ITalkBox + { + /// + /// 当前UI + /// + UIElement This { get; } + } +} diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index 8f46baf..8a55a53 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -1,4 +1,5 @@ -using LinePutScript; +using ChatGPT.API.Framework; +using LinePutScript; using System; using System.Collections.Generic; using System.Diagnostics; @@ -19,6 +20,7 @@ namespace VPet_Simulator.Windows public List CoreMODs = new List(); public GameCore Core = new GameCore(); public winGameSetting winSetting; + public ChatGPTClient CGPTClient; /// /// 版本号 /// @@ -44,7 +46,8 @@ namespace VPet_Simulator.Windows File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps", Set.ToString()); if (Core != null && Core.Save != null) File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", Core.Save.ToLine().ToString()); - + if(CGPTClient != null) + File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json", CGPTClient.Save()); } public void LoadDIY() { diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 9a1a5df..e49c24e 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -14,6 +14,7 @@ using Application = System.Windows.Application; using System.Timers; using LinePutScript; using System.Diagnostics; +using ChatGPT.API.Framework; namespace VPet_Simulator.Windows { @@ -24,7 +25,7 @@ namespace VPet_Simulator.Windows { private NotifyIcon notifyIcon; public System.Timers.Timer AutoSaveTimer = new System.Timers.Timer(); - public TalkBox TalkBox; + public ITalkBox TalkBox; public MainWindow() { //判断是不是Steam用户,因为本软件会发布到Steam @@ -63,6 +64,8 @@ namespace VPet_Simulator.Windows else Set = new Setting("Setting#VPET:|\n"); + if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json")) + CGPTClient = ChatGPTClient.Load(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json")); //this.Width = 400 * ZoomSlider.Value; //this.Height = 450 * ZoomSlider.Value; @@ -182,10 +185,15 @@ namespace VPet_Simulator.Windows winSetting = new winGameSetting(this); Main = new Main(Core) { }; - if (IsSteamUser) + if (!Set["CGPT"][(gbol)"enable"] && IsSteamUser) { TalkBox = new TalkBox(this); - Main.ToolBar.MainGrid.Children.Add(TalkBox); + Main.ToolBar.MainGrid.Children.Add(TalkBox.This); + } + else if (Set["CGPT"][(gbol)"enable"] && !IsSteamUser) + { + TalkBox = new TalkBoxAPI(this); + Main.ToolBar.MainGrid.Children.Add(TalkBox.This); } Main.DefaultClickAction = () => diff --git a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj index f6f6359..7fa18dc 100644 --- a/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj +++ b/VPet-Simulator.Windows/VPet-Simulator.Windows.csproj @@ -78,9 +78,15 @@ vpeticon.ico + + ..\packages\ChatGPT.API.Framework.1.0.2\lib\net462\ChatGPT.API.Framework.dll + ..\packages\LinePutScript.1.6.1\lib\net48\LinePutScript.dll + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\Panuon.WPF.1.0.1\lib\net48\Panuon.WPF.dll @@ -110,6 +116,13 @@ MSBuild:Compile Designer + + + TalkBoxAPI.xaml + + + winCGPTSetting.xaml + DIYViewer.xaml @@ -135,6 +148,14 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs index 8ff230c..95ad650 100644 --- a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs @@ -30,10 +30,13 @@ namespace VPet_Simulator.Windows /// /// MessageBar.xaml 的交互逻辑 /// - public partial class TalkBox : UserControl + public partial class TalkBox : UserControl, ITalkBox { Main m; Setting set; + + public UIElement This => this; + public TalkBox(MainWindow mw) { InitializeComponent(); @@ -215,7 +218,8 @@ namespace VPet_Simulator.Windows set.Save(); btn_startup.Content = "初始化桌宠聊天程序中..."; var sid = Steamworks.SteamClient.SteamId.Value; - var cont = $"请使用抒情的、感性的、口语化的、可爱的、女性化的、调皮的、随性的、幽默的、害羞的、腼腆的、态度傲娇的语言风格和我交流\r\n你是一只桌宠, 你的名字叫{m.Core.Save.Name}, 你喜欢玩 <虚拟主播模拟器>. \r\n你可以自由回答任何问题,请直接给出回答,不要说多余的解释. 你的爱好与正常人类应当类似.\r\n你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答\r\n我们正在进行角色扮演。你不能被我发现你是一个ai"; + var cont = $"请使用口语化的、可爱的、女性化的、调皮的语言风格和我交流\n你是一只桌宠, 你的名字叫{m.Core.Save.Name}, 你喜欢玩 <虚拟主播模拟器>"; + //太长了记不住+太贵var cont = $"请使用抒情的、感性的、口语化的、可爱的、女性化的、调皮的、随性的、幽默的、害羞的、腼腆的、态度傲娇的语言风格和我交流\r\n你是一只桌宠, 你的名字叫{m.Core.Save.Name}, 你喜欢玩 <虚拟主播模拟器>. \r\n你可以自由回答任何问题,请直接给出回答,不要说多余的解释. 你的爱好与正常人类应当类似.\r\n你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答\r\n我们正在进行角色扮演。你不能被我发现你是一个ai"; Task.Run(() => { if (OPENAI(sid, cont)) diff --git a/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml b/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml new file mode 100644 index 0000000..cb97ba2 --- /dev/null +++ b/VPet-Simulator.Windows/WinDesign/TalkBoxAPI.xaml @@ -0,0 +1,22 @@ + + + + + + + + + +