光速移除CGPT支持 #174

This commit is contained in:
ZouJin 2023-09-03 23:06:43 +08:00
parent 5a4bd46ea5
commit 3c52b72226
13 changed files with 33 additions and 651 deletions

View File

@ -26,7 +26,7 @@
<PackageReference Include="LinePutScript" Version="1.9.2" />
<PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" />
<PackageReference Include="Panuon.WPF" Version="1.0.2" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.5" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.8" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">

View File

@ -18,6 +18,6 @@
<PackageReference Include="LinePutScript" Version="1.9.2" />
<PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" />
<PackageReference Include="Panuon.WPF" Version="1.0.2" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.5" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.8" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using ChatGPT.API.Framework;
using CSCore.CoreAudioAPI;
using CSCore.CoreAudioAPI;
using LinePutScript;
using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
@ -38,7 +37,7 @@ namespace VPet_Simulator.Windows
public UIElement TalkBox;
public winGameSetting winSetting { get; set; }
public winBetterBuy winBetterBuy { get; set; }
public ChatGPTClient CGPTClient;
//public ChatGPTClient CGPTClient;
public ImageResources ImageSources { get; set; } = new ImageResources();
/// <summary>
/// 所有三方插件
@ -201,8 +200,6 @@ namespace VPet_Simulator.Windows
l[(gint)"hash"] = -1;
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", l.ToString());
}
if (CGPTClient != null)
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json", CGPTClient.Save());
}
}
/// <summary>

View File

@ -13,8 +13,6 @@ using MenuItem = System.Windows.Forms.MenuItem;
using Application = System.Windows.Application;
using System.Timers;
using LinePutScript;
using System.Diagnostics;
using ChatGPT.API.Framework;
using static VPet_Simulator.Core.GraphCore;
using Panuon.WPF.UI;
using VPet_Simulator.Windows.Interface;
@ -27,8 +25,6 @@ using static VPet_Simulator.Windows.PerformanceDesktopTransparentWindow;
using Line = LinePutScript.Line;
using static VPet_Simulator.Core.GraphInfo;
using System.Globalization;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
using System.Diagnostics.Eventing.Reader;
using static VPet_Simulator.Windows.Interface.ExtensionFunction;
namespace VPet_Simulator.Windows
@ -96,8 +92,8 @@ namespace VPet_Simulator.Windows
_dwmEnabled = Win32.Dwmapi.DwmIsCompositionEnabled();
_hwnd = new WindowInteropHelper(this).EnsureHandle();
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json"))
CGPTClient = ChatGPTClient.Load(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\ChatGPTSetting.json"));
//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;
InitializeComponent();
@ -495,10 +491,10 @@ namespace VPet_Simulator.Windows
LoadingText.Content = "正在加载CGPT".Translate();
switch (Set["CGPT"][(gstr)"type"])
{
case "API":
TalkBox = new TalkBoxAPI(this);
Main.ToolBar.MainGrid.Children.Add(TalkBox);
break;
//case "API":
// TalkBox = new TalkBoxAPI(this);
// Main.ToolBar.MainGrid.Children.Add(TalkBox);
// break;
case "LB":
//if (IsSteamUser)
//{

View File

@ -137,7 +137,6 @@
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ChatGPT.API.Framework" Version="1.0.4" />
<PackageReference Include="CSCore" Version="1.2.1.2" />
<PackageReference Include="Facepunch.Steamworks" Condition="'$(Platform)' == 'x64'" Version="2.3.3" />
<PackageReference Include="Facepunch.Steamworks.win32" Condition="'$(Platform)' == 'x86'" Version="2.3.3" />
@ -145,6 +144,6 @@
<PackageReference Include="LinePutScript.Localization.WPF" Version="1.0.6" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Panuon.WPF" Version="1.0.2" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.5" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.15.8" />
</ItemGroup>
</Project>

View File

@ -1,36 +0,0 @@
<UserControl x:Class="VPet_Simulator.Windows.TalkBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500" VerticalAlignment="Top">
<Border Background="{DynamicResource PrimaryLighter}" BorderBrush="{DynamicResource Primary}" BorderThickness="5"
VerticalAlignment="Top" Margin="5,50,5,5" CornerRadius="5" Padding="5,5,5,3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox x:Name="tbTalk" Style="{DynamicResource StandardTextBoxStyle}" Height="Auto"
pu:TextBoxHelper.Watermark="{ll:Str 和桌宠说}" FontSize="30" AcceptsReturn="True"
TextWrapping="WrapWithOverflow" PreviewKeyDown="tbTalk_KeyDown" TextChanged="tbTalk_TextChanged" />
<Button pu:ButtonHelper.CornerRadius="4" Content="{ll:Str '发送'}" BorderThickness="2"
Background="{DynamicResource SecondaryLight}" Grid.Column="2"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="SendMessage_Click"
ToolTip="{ll:Str '按 Ctrl+Enter 发送'}" />
<Button x:Name="btn_startup" pu:ButtonHelper.CornerRadius="4" Content="{ll:Str 初始化桌宠聊天程序}"
BorderThickness="2" x:FieldModifier="public" Background="{DynamicResource SecondaryLight}"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="StartUP_Click"
Grid.ColumnSpan="3" />
<ProgressBar x:Name="PrograssUsed" Grid.Row="2" Grid.ColumnSpan="3" Height="10" BorderThickness="2"
pu:ProgressBarHelper.CornerRadius="4" Foreground="{DynamicResource ProgressBarForeground}" Visibility="Collapsed"
Background="{DynamicResource Secondary}" Value="0.5" BorderBrush="{DynamicResource DARKPrimary}" Maximum="1" ToolTipOpening="PrograssUsed_ToolTipOpening" />
</Grid>
</Border>
</UserControl>

View File

@ -1,289 +0,0 @@
using LinePutScript;
using LinePutScript.Localization.WPF;
using Steamworks;
using System;
using System.IO;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using VPet_Simulator.Core;
using VPet_Simulator.Windows.Interface;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace VPet_Simulator.Windows
{
/// <summary>
/// MessageBar.xaml 的交互逻辑
/// </summary>
public partial class TalkBox : UserControl
{
Main m;
Setting set;
MainWindow mw;
public TalkBox(MainWindow mw)
{
InitializeComponent();
this.m = mw.Main;
set = mw.Set;
this.mw = mw;
this.IsEnabled = false;
lastopeningtime = DateTime.Now;
Task.Run(TalkChatInfoDisplay);
}
private void SendMessage_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbTalk.Text))
{
return;
}
var sd = new say_data()
{
content = tbTalk.Text,
likability = (int)m.Core.Save.Likability,
mode = (int)m.Core.Save.Mode,
};
tbTalk.Text = "";
Task.Run(() =>
{
var ret = ConnectAIOpen("VPet/Say", "POST", JsonConvert.SerializeObject(sd));
switch (ret.Name)
{
case "Success":
var showtxt = "当前Token使用".Translate() + ": " + ret.Info;
Dispatcher.Invoke(() =>
{
m.MsgBar.MessageBoxContent.Children.Add(new TextBlock() { Text = showtxt, FontSize = 20, ToolTip = showtxt, HorizontalAlignment = HorizontalAlignment.Right });
TalkChatInfoDisplay(ret);
});
m.SayRnd(ret.Text);
break;
default:
case "Error":
if (ret.Info == "Connect")
m.SayRnd("服务器超载,请稍后重试".Translate());
else
m.SayRnd(ret.Info.Translate());
break;
case "Fail":
switch (ret.Info)
{
case "ServerFull":
m.SayRnd("ServerFull".Translate(ret[(gint)"serverused"], ret[(gint)"servertotal"]));
break;
case "NoUser":
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Visible);
m.SayRnd("NoUser".Translate());
break;
case "NoTokenUser":
case "NoTokenVIP":
Dispatcher.Invoke(() => TalkChatInfoDisplay(ret));
m.SayRnd(ret.Info.Translate(ret[(gint)"TokenUsed"], ret[(gint)"TokenFreeLimit"], ret[(gdbe)"relshour"]));
break;
default:
m.SayRnd(ret.Info.Translate());
break;
}
break;
}
});
}
private class say_data
{
/// <summary>
/// 说话内容
/// </summary>
public string content { get; set; } = "";
/// <summary>
/// 好感度
/// </summary>
public int likability { get; set; } = 0;
/// <summary>
/// 当前状态
/// </summary>
public int mode { get; set; } = 1;
public string lang { get; set; } = LocalizeCore.CurrentCulture.ToLower();
}
/// <summary>
/// 重置ChatGPT
/// </summary>
/// <returns></returns>
public bool ChatGPT_Reset()
{
var rd = new rest_data()
{
petname = m.Core.Save.Name,
};
var ret = ConnectAIOpen("VPet/Rest", "POST", JsonConvert.SerializeObject(rd));
switch (ret.Name)
{
case "Success":
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Collapsed);
return true;
default:
case "Error":
if (ret.Info == "Connect")
m.SayRnd("服务器超载,请稍后重试".Translate());
else
m.SayRnd(ret.Info.Translate());
return false;
case "Fail":
m.SayRnd(ret.Info.Translate());
return false;
}
}
/// <summary>
/// 根据宠物剩余寿命显示相关UI
/// </summary>
public void TalkChatInfoDisplay()
{
//Dispatcher.Invoke(() => this.IsEnabled = false);
var l = ConnectAIOpen("VPet/Data", "GET");
if (l.Name == "Info")
{
Dispatcher.Invoke(() =>
{
if (l[(gdbe)"PetLife"] == 0)
{
btn_startup.Visibility = Visibility.Visible;
return;
}
else
{
btn_startup.Visibility = Visibility.Collapsed;
}
PrograssUsed.Tag = "服务器消耗倍率".Translate() + $":\t{l[(gdbe)"servermuti"]:P0}";
TalkChatInfoDisplay(l);
});
}
else
{
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Collapsed);
}
Dispatcher.Invoke(() => this.IsEnabled = true);
}
/// <summary>
/// 根据宠物剩余寿命显示相关UI (读用户信息)
/// </summary>
/// <param name="steamid">steamid,用于记录历史</param>
public void TalkChatInfoDisplay(Line Infos)
{
if (Infos.Find("TokenUsed") == null)
{
return;
}
PrograssUsed.Visibility = Visibility.Visible;
double used = Math.Min(Infos[(gdbe)"TokenUsed"] / Infos[(gdbe)"TokenFreeLimit"], 1);
PrograssUsed.Value = used;
var txt = "当前使用字数".Translate() + $":\t{Infos[(gdbe)"TokenUsed"]}/{Infos[(gdbe)"TokenFreeLimit"]} ({used:P1})";
txt += "\n" + "下次刷新时间".Translate() + $":\t{Infos[(gdat)"LastUsed"].AddDays(1)}";
//未实装的付费功能
if (Infos[(gint)"Vip"] == 0)
{
txt = "由桌宠开发者提供的免费API".Translate() + "\n" + txt;
txt += "\n" + "生成最大字数".Translate() + $":\t{150 + Math.Min((int)Math.Sqrt(m.Core.Save.Likability) * 5, 450)}";
}
else
{//未来如果整应用内购买再在这里实装
txt = "由桌宠开发者提供的API".Translate() + "\n" + txt;
txt += "\n" + "生成最大字数".Translate() + $":\t4000";
txt += "\n" + "VIP用户".Translate() + $"({Infos[(gint)"Vip"] - 9})";
txt += "\n" + "按量付费字数".Translate() + $":\t{Infos[(gint)"TokenPaid"]}";
}
PrograssUsed.ToolTip = txt + "\n" + PrograssUsed.Tag;
}
private class rest_data
{
public string lang { get; set; } = LocalizeCore.CurrentCulture.ToLower();
public string petname { get; set; }
public string diycreate { get; set; }
}
private void StartUP_Click(object sender, RoutedEventArgs e)
{
set["aiopen"][(gbol)"startup"] = true;
mw.Save();
btn_startup.Content = "初始化桌宠聊天程序中...".Translate();
Task.Run(ChatGPT_Reset);
}
private void tbTalk_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
{
SendMessage_Click(sender, e);
e.Handled = true;
}
}
/// <summary>
/// 连接 由作者提供的聊天功能
/// </summary>
/// <returns></returns>
public static Line ConnectAIOpen(string action, string Method = "POST", string content = null)
{
// const string url = "https://localhost:7166/";
const string url = "https://aiopen.exlb.net:5810/";
try
{
//请不要使用该API作为其他用途,如有其他需要请联系我(QQ群:430081239)
//该API可能会因为其他原因更改
string _url = url + action + "?steamid=" + SteamClient.SteamId.Value;
//参数
var request = (HttpWebRequest)WebRequest.Create(_url);
request.Method = Method;
request.ContentType = "application/json";//ContentType
if (content != null)
{
byte[] byteData = Encoding.UTF8.GetBytes(content);
int length = byteData.Length;
request.ContentLength = length;
using (Stream writer = request.GetRequestStream())
{
writer.Write(byteData, 0, length);
writer.Close();
writer.Dispose();
}
}
string responseString;
using (var response = (HttpWebResponse)request.GetResponse())
{
responseString = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
response.Dispose();
}
return new Line(responseString);
}
catch (Exception ex)
{
return new Line("Error", "Connect", ex.ToString());
}
}
private DateTime lastopeningtime;
private void PrograssUsed_ToolTipOpening(object sender, ToolTipEventArgs e)
{
if ((DateTime.Now - lastopeningtime).TotalMinutes < 5)
{
return;
}
lastopeningtime = DateTime.Now;
Task.Run(TalkChatInfoDisplay);
}
private void tbTalk_TextChanged(object sender, TextChangedEventArgs e)
{
if (tbTalk.Text.Length > 0)
{
mw.Main.ToolBar.CloseTimer.Stop();
}
else
{
mw.Main.ToolBar.CloseTimer.Start();
}
}
}
}

View File

@ -1,24 +0,0 @@
<UserControl x:Class="VPet_Simulator.Windows.TalkBoxAPI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500" VerticalAlignment="Top">
<Border Background="{DynamicResource SecondaryLighter}" BorderBrush="{DynamicResource Secondary}"
BorderThickness="5" VerticalAlignment="Top" Margin="5,50,5,5" CornerRadius="5" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox x:Name="tbTalk" Style="{DynamicResource StandardTextBoxStyle}" Height="Auto"
pu:TextBoxHelper.Watermark="{ll:Str 和桌宠说}" FontSize="30" AcceptsReturn="True" TextWrapping="WrapWithOverflow"
PreviewKeyDown="tbTalk_KeyDown" TextChanged="tbTalk_TextChanged" />
<Button pu:ButtonHelper.CornerRadius="4" Content="{ll:Str 发送}" BorderThickness="2"
Background="{DynamicResource PrimaryLight}" Grid.Column="2" ToolTip="{ll:Str '按 Ctrl+Enter 发送'}"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="SendMessage_Click" />
</Grid>
</Border>
</UserControl>

View File

@ -1,126 +0,0 @@
using LinePutScript.Localization.WPF;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using VPet_Simulator.Core;
namespace VPet_Simulator.Windows
{
/// <summary>
/// MessageBar.xaml 的交互逻辑
/// </summary>
public partial class TalkBoxAPI : UserControl
{
Main m;
MainWindow mw;
public TalkBoxAPI(MainWindow mw)
{
InitializeComponent();
this.m = mw.Main;
this.mw = mw;
}
private void SendMessage_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbTalk.Text))
{
return;
}
var cont = tbTalk.Text;
tbTalk.Text = "";
Task.Run(() => OPENAI(cont));
}
public static string[] like_str = new string[] { "陌生", "普通", "喜欢", "爱" };
public static int like_ts(int like)
{
if (like > 50)
{
if (like < 100)
return 1;
else if (like < 200)
return 2;
else
return 3;
}
return 0;
}
/// <summary>
/// 使用OPENAI API进行回复
/// </summary>
/// <param name="content">内容 说话内容</param>
public void OPENAI(string content)
{
if (string.IsNullOrEmpty(content))
{
return;
}
if (mw.CGPTClient == null)
{
m.SayRnd("请先前往设置中设置 ChatGPT API".Translate());
return;
}
Dispatcher.Invoke(() => this.IsEnabled = false);
try
{
if (mw.CGPTClient.Completions.TryGetValue("vpet", out var vpetapi))
{
var last = vpetapi.messages.LastOrDefault();
if (last != null)
{
if (last.role == ChatGPT.API.Framework.Message.RoleType.user)
{
vpetapi.messages.Remove(last);
}
}
}
content = "[当前状态: {0}, 好感度:{1}({2})]".Translate(mw.Core.Save.Mode.ToString().Translate(), like_str[like_ts((int)mw.Core.Save.Likability)].Translate(), (int)mw.Core.Save.Likability) + content;
var resp = mw.CGPTClient.Ask("vpet", content);
var reply = resp.GetMessageContent();
if (resp.choices[0].finish_reason == "length")
{
reply += " ...";
}
var showtxt = "当前Token使用".Translate() + ": " + resp.usage.total_tokens;
Dispatcher.Invoke(() =>
{
m.MsgBar.MessageBoxContent.Children.Add(new TextBlock() { Text = showtxt, FontSize = 20, ToolTip = showtxt, HorizontalAlignment = HorizontalAlignment.Right });
});
m.SayRnd(reply);
}
catch (Exception exp)
{
var e = exp.ToString();
string str = "请检查设置和网络连接".Translate();
if (e.Contains("401"))
{
str = "请检查API token设置".Translate();
}
m.SayRnd("API调用失败".Translate() + $",{str}\n{e}");//, GraphCore.Helper.SayType.Serious);
}
Dispatcher.Invoke(() => this.IsEnabled = true);
}
private void tbTalk_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
{
SendMessage_Click(sender, e);
e.Handled = true;
}
}
private void tbTalk_TextChanged(object sender, TextChangedEventArgs e)
{
if (tbTalk.Text.Length > 0)
{
mw.Main.ToolBar.CloseTimer.Stop();
}
else
{
mw.Main.ToolBar.CloseTimer.Start();
}
}
}
}

View File

@ -1,72 +0,0 @@
<pu:WindowX x:Class="VPet_Simulator.Windows.winCGPTSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VPet_Simulator.Windows" Topmost="True"
xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF" mc:Ignorable="d"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Title="{ll:Str 'ChatGPT API 设置'}" Width="450"
FontSize="16" Height="Auto" ResizeMode="NoResize" WindowState="Normal" SizeToContent="Height">
<Grid Margin="16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="Auto" MinHeight="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="Auto" MinHeight="40" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<TextBlock Text="API URL" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" Text="API Key" VerticalAlignment="Center" />
<TextBlock Grid.Row="2" Text="Model" VerticalAlignment="Center" />
<TextBlock Grid.Row="3" Text="{ll:Str 初始化文本}" VerticalAlignment="Center" />
<TextBlock Grid.Row="4" Text="{ll:Str 温度}" VerticalAlignment="Center" />
<TextBlock Grid.Row="5" Text="{ll:Str 最大花费}" VerticalAlignment="Center" />
<TextBlock Grid.Row="6" Text="{ll:Str 累计花费}" VerticalAlignment="Center" />
<TextBlock Grid.Row="7" Text="{ll:Str 历史记录}" VerticalAlignment="Center" />
<TextBlock Grid.Row="8" Text="{ll:Str 完成设置}" VerticalAlignment="Center" />
<TextBox x:Name="tbAPIURL" Grid.Row="0" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" pu:TextBoxHelper.Watermark="{ll:Str 'API 链接 一般为 api.openai.com/v1/chat/completions'}"
Text="https://api.openai.com/v1/chat/completions"
ToolTip="{ll:Str 'API 链接 一般为 api.openai.com/v1/chat/completions'}" Margin="0,5,0,5" />
<TextBox x:Name="tbAPIKey" Grid.Row="1" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" pu:TextBoxHelper.Watermark="{ll:Str '从 OpenAI 获得的 APIKEY 一般`sk-`开头'}"
ToolTip="{ll:Str '从 OpenAI 获得的 APIKEY 一般`sk-`开头'}" VerticalAlignment="Center" />
<ComboBox x:Name="cbModel" Style="{DynamicResource StandardComboBoxStyle}" Grid.Row="2" Grid.Column="2" SelectedIndex="0">
<ComboBoxItem Content="gpt-3.5-turbo" />
<ComboBoxItem Content="gpt-4" />
</ComboBox>
<TextBox x:Name="tbSystem" Grid.Row="3" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" pu:TextBoxHelper.Watermark="{ll:Str '不会被忘记的初始化关键字, 字越多越贵'}"
ToolTip="{ll:Str '不会被忘记的初始化关键字, 字越多越贵'}" AcceptsReturn="True" TextWrapping="WrapWithOverflow"
Height="Auto" MaxHeight="100" VerticalScrollBarVisibility="Visible"
Text="请使用口语化的、可爱的、女性化的、调皮的语言风格和我交流. &#13;你是一只桌宠, 你的名字叫{Name}, 你喜欢玩 虚拟主播模拟器. &#13;你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答"
Margin="0,5,0,5" />
<TextBox x:Name="tbTemp" Grid.Row="4" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" Text="0.6" pu:TextBoxHelper.InputLimit="Digit,Point"
pu:TextBoxHelper.Watermark="{ll:Str '0-2之间 0.2更稳定 0.8更随机'}" ToolTip="{ll:Str '0-2之间 0.2更稳定 0.8更随机'}"
Margin="0,5,0,5" />
<TextBox x:Name="tbMaxToken" Grid.Row="5" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" Text="2048" pu:TextBoxHelper.InputLimit="Digit"
pu:TextBoxHelper.Watermark="{ll:Str '读取最大花费Token数量 1千Token=$0.02'}"
ToolTip="{ll:Str '读取最大花费Token数量 1千Token=$0.02'}" Margin="0,5,0,5" />
<TextBox x:Name="tbHistory" Grid.Row="7" Grid.Column="2" Style="{DynamicResource StandardTextBoxStyle}"
FontSize="16" Text="[]" TextWrapping="WrapWithOverflow" pu:TextBoxHelper.Watermark="{ll:Str 聊天历史记录}"
ToolTip="{ll:Str 聊天历史记录}" Height="Auto" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"
MaxHeight="200" />
<Label x:Name="lbSpend" Grid.Row="6" Grid.Column="2" Content="0 Token" Background="{x:Null}"
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"
ToolTip="{ll:Str '累计在此花费的Token个数 1千Token=$0.02'}" />
<Button x:Name="btnSave" pu:ButtonHelper.CornerRadius="4" Content="{ll:Str 保存设置}" Margin="4,4,4,4"
Grid.Column="2" Background="{DynamicResource SecondaryLight}" Padding="1" Grid.Row="8"
Click="btnSave_Click" />
</Grid>
</pu:WindowX>

View File

@ -1,62 +0,0 @@
using ChatGPT.API.Framework;
using LinePutScript.Localization.WPF;
using Newtonsoft.Json;
using Panuon.WPF.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using static ChatGPT.API.Framework.Completions;
namespace VPet_Simulator.Windows
{
/// <summary>
/// winCGPTSetting.xaml 的交互逻辑
/// </summary>
public partial class winCGPTSetting : WindowX
{
MainWindow mw;
long totalused = 0;
public winCGPTSetting(MainWindow mw)
{
InitializeComponent();
this.mw = mw;
if (mw.CGPTClient != null)
{
tbAPIKey.Text = mw.CGPTClient.APIKey;
tbAPIURL.Text = mw.CGPTClient.APIUrl;
tbMaxToken.Text = mw.CGPTClient.Completions["vpet"].max_tokens.ToString();
tbSystem.Text = mw.CGPTClient.Completions["vpet"].messages[0].content;
tbTemp.Text = mw.CGPTClient.Completions["vpet"].temperature.ToString();
cbModel.SelectedIndex = mw.CGPTClient.Completions["vpet"].model == "gpt-3.5-turbo" ? 0 : 1;
var msgs = mw.CGPTClient.Completions["vpet"].messages.ToList();
msgs.RemoveAt(0);
tbHistory.Text = JsonConvert.SerializeObject(msgs);
lbSpend.Content = mw.CGPTClient.TotalTokensUsage.ToString() + " Token";
totalused = mw.CGPTClient.TotalTokensUsage;
}
else
tbSystem.Text = "请使用口语化的、可爱的、女性化的、调皮的语言风格和我交流. 你是一只桌宠, 你的名字叫{Name}, 你喜欢玩 虚拟主播模拟器. 你需要尝试体会我与你对话中的感情、产生自己的情感并尽可能给出可爱的回答".Translate();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
mw.CGPTClient = new ChatGPTClient(tbAPIKey.Text, tbAPIURL.Text)
{
TotalTokensUsage = totalused
};
mw.CGPTClient.CreateCompletions("vpet", tbSystem.Text.Replace("{Name}", mw.Core.Save.Name));
mw.CGPTClient.Completions["vpet"].model = (string)((ComboBoxItem)cbModel.SelectedItem).Content;
mw.CGPTClient.Completions["vpet"].frequency_penalty = 0.2;
mw.CGPTClient.Completions["vpet"].presence_penalty = 1;
mw.CGPTClient.Completions["vpet"].max_tokens = Math.Min(Math.Max(int.Parse(tbMaxToken.Text), 10), 4000);
mw.CGPTClient.Completions["vpet"].temperature = Math.Min(Math.Max(double.Parse(tbTemp.Text), 0.1), 2);
var l = JsonConvert.DeserializeObject<List<Message>>(tbHistory.Text);
if (l != null)
mw.CGPTClient.Completions["vpet"].messages.AddRange(l);
mw.Save();
this.Close();
}
}
}

View File

@ -6,8 +6,7 @@
xmlns:local="clr-namespace:VPet_Simulator.Windows"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI"
xmlns:system="clr-namespace:System;assembly=mscorlib" Title="{ll:Str 设置}" Width="{ll:Dbe SettingWidth,
DefValue=500}" Height="550" Closing="WindowX_Closing" FontSize="16"
xmlns:system="clr-namespace:System;assembly=mscorlib" Title="{ll:Str 设置}" Width="{ll:Dbe SettingWidth, DefValue=500}" Height="550" Closing="WindowX_Closing" FontSize="16"
Style="{DynamicResource BaseWindowXStyle}" Topmost="True" WindowStartupLocation="CenterScreen" mc:Ignorable="d">
<!--<pu:WindowX.Resources>
<DataTemplate x:Key="DIYDataTemplate">
@ -325,10 +324,10 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<RadioButton x:Name="RBCGPTUseAPI" Grid.Column="1" Checked="CGPType_Checked"
<!--<RadioButton x:Name="RBCGPTUseAPI" Grid.Column="1" Checked="CGPType_Checked"
Content="{ll:Str '使用从ChatGPT\&#13;申请的的API'}" GroupName="cgpttype"
Style="{DynamicResource StandardRadioButtonStyle}"
ToolTip="{ll:Str 需要去OpenAI官网申请}" />
ToolTip="{ll:Str 需要去OpenAI官网申请}" />-->
<RadioButton x:Name="RBCGPTUseLB" Checked="CGPType_Checked"
Content="{ll:Str '使用桌宠选项式\&#13;聊天功能'}" GroupName="cgpttype" IsChecked="True"
Style="{DynamicResource StandardRadioButtonStyle}"

View File

@ -165,10 +165,10 @@ namespace VPet_Simulator.Windows
//CGPT
switch (mw.Set["CGPT"][(gstr)"type"])
{
case "API":
RBCGPTUseAPI.IsChecked = true;
BtnCGPTReSet.Content = "打开 ChatGPT API 设置".Translate();
break;
//case "API":
// RBCGPTUseAPI.IsChecked = true;
// BtnCGPTReSet.Content = "打开 ChatGPT API 设置".Translate();
// break;
case "LB":
RBCGPTUseLB.IsChecked = true;
BtnCGPTReSet.Content = "初始化桌宠聊天程序".Translate();
@ -857,9 +857,9 @@ namespace VPet_Simulator.Windows
{
switch (mw.Set["CGPT"][(gstr)"type"])
{
case "API":
new winCGPTSetting(mw).ShowDialog();
break;
//case "API":
// new winCGPTSetting(mw).ShowDialog();
// break;
case "LB":
//Task.Run(() =>
//{
@ -885,10 +885,10 @@ namespace VPet_Simulator.Windows
{
mw.Set["CGPT"][(gstr)"type"] = "LB";
}
else if (RBCGPTUseAPI.IsChecked == true)
{
mw.Set["CGPT"][(gstr)"type"] = "API";
}
//else if (RBCGPTUseAPI.IsChecked == true)
//{
// mw.Set["CGPT"][(gstr)"type"] = "API";
//}
else
{
mw.Set["CGPT"][(gstr)"type"] = "OFF";
@ -897,14 +897,14 @@ namespace VPet_Simulator.Windows
switch (mw.Set["CGPT"][(gstr)"type"])
{
case "API":
BtnCGPTReSet.IsEnabled = true;
BtnCGPTReSet.Content = "打开 ChatGPT API 设置".Translate();
if (mw.TalkBox != null)
mw.Main.ToolBar.MainGrid.Children.Remove(mw.TalkBox);
mw.TalkBox = new TalkBoxAPI(mw);
mw.Main.ToolBar.MainGrid.Children.Add(mw.TalkBox);
break;
//case "API":
// BtnCGPTReSet.IsEnabled = true;
// BtnCGPTReSet.Content = "打开 ChatGPT API 设置".Translate();
// if (mw.TalkBox != null)
// mw.Main.ToolBar.MainGrid.Children.Remove(mw.TalkBox);
// mw.TalkBox = new TalkBoxAPI(mw);
// mw.Main.ToolBar.MainGrid.Children.Add(mw.TalkBox);
// break;
case "LB":
BtnCGPTReSet.IsEnabled = true;
BtnCGPTReSet.Content = "初始化桌宠聊天程序".Translate();