【deepseek实战】绿色好用,不断网

server/2025/2/2 13:40:25/
aidu_pl">

前言

        最佳deepseek火热网络,我也开发一款windows的电脑端,接入了deepseek,基本是复刻了网页端,还加入一些特色功能。

        助力国内AI,发出自己的热量

        说一下开发过程和内容的使用吧。


ain-toc" name="tableOfContents">目录

一、介绍

二、具体工作

        1.1、引用

        1.2、主界面

        1.3、主界面布局

        1.4 、消息类

        1.5 、设置

三、运行图示 

四、总结

五、下载


 

一、介绍

  •    目标:个人桌面AI助手,避免与专属API冲突,因为官网一些原因断网,自己接入API,确保能上deepseek。
    先上图,确定是否需要使用:
  • 软件是免费的,自己用自己的key或者别人的key,没有key可以联系我

 

二、具体工作

        1.1、引用

        dotnet8.0

  <TargetFramework>net8.0-windows</TargetFramework>

        PackageReference 

    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /><PackageReference Include="System.Drawing.Common" Version="8.0.0" /><PackageReference Include="System.Speech" Version="8.0.0" /><PackageReference Include="Spire.Doc" Version="12.8.0" />

            Newtonsoft.Json 编译和反编译API信息
            System.Drawing 绘制库,画界面主要
            System.Speech 语音接入
            Spire.Doc 文档使用

        这几个引用根据自己需要添加

        1.2、主界面

        信息处理,分为及时信息和二次信息处理,这样能对文本信息进行个人需要处理

private async Task<ChatMessage> StreamResponseAsync(string apiKey, List<ChatMessage> chatHistory, string language, CancellationToken cancellationToken)
{var deepseekService = new DeepseekService(currentUser, _printService);var messages = chatHistory.Select(m => new ChatMessage{Role = m.Role,MessageType = m.MessageType,Content = m.Content}).ToList();try{var typingDelay = TimeSpan.FromMilliseconds(50);var buffer = new StringBuilder();var responseMessage = new ChatMessage{Role = "assistant",MessageType = MessageType.Answer,Content = string.Empty,WrappedContent = string.Empty};// 创建响应消息但不立即添加到历史记录var responseIndex = _displayHistory .Count;// 实时处理流式响应 - deepseek输出开始var charCount = 0;var tempBuffer = new StringBuilder();await foreach (var chunk in deepseekService.StreamChatResponseAsync(apiKey, messages, language).WithCancellation(cancellationToken)){if (string.IsNullOrEmpty(chunk) || _isStopping || cancellationToken.IsCancellationRequested) {// Immediately return if stoppingreturn new ChatMessage{Role = "assistant",MessageType = MessageType.Answer,Content = "对话已终止",WrappedContent = "对话已终止"};}tempBuffer.Append(chunk);charCount += chunk.Length;// 每20个字符更新一次显示if (charCount >= 20){buffer.Append(tempBuffer.ToString());tempBuffer.Clear();charCount = 0;await Dispatcher.InvokeAsync(() => {responseMessage.Content = buffer.ToString();responseMessage.WrappedContent = WrapText(responseMessage.Content+"\n回答完成1",ChatHistoryRichTextBox?.ActualWidth - 20 ?? ChatMessage.DefaultBorderWidth);// 更新_curchat_curchatMesg = responseMessage;// 只在第一次更新时添加消息if (_displayHistory .Count == responseIndex) {_displayHistory .Add(responseMessage);} else {_displayHistory [responseIndex] = responseMessage;}UpdateChatHistoryDisplayList(_displayHistory);});          await Task.Delay(typingDelay);}}// 处理剩余不足20字符的内容if (tempBuffer.Length > 0){buffer.Append(tempBuffer.ToString());await Dispatcher.InvokeAsync(() => {responseMessage.Content = buffer.ToString() ;responseMessage.WrappedContent = WrapText(responseMessage.Content+"\n回答完成2",ChatHistoryRichTextBox?.ActualWidth - 20 ?? ChatMessage.DefaultBorderWidth);          // 更新_curchat_curchatMesg = responseMessage;_displayHistory [responseIndex] = responseMessage;UpdateChatHistoryDisplayList(_displayHistory);});}// deepseek输出完成 - 流式响应结束// 进行最后的换行检查await Dispatcher.InvokeAsync(() => {responseMessage.WrappedContent = WrapText(responseMessage.Content+"\n回答完成3", ChatHistoryRichTextBox?.ActualWidth - 20 ?? ChatMessage.DefaultBorderWidth);// 更新_curchat_curchatMesg = responseMessage;_displayHistory [responseIndex] = responseMessage;UpdateChatHistoryDisplayList(_displayHistory);});return responseMessage;}catch (Exception ex){return new ChatMessage{Role = "assistant",MessageType = MessageType.Answer,Content = $"Error: {ex.Message}",WrappedContent = $"Error: {ex.Message}"};}finally{// 清空输入框InputTextBox.Text = string.Empty;}
}

        1.3、主界面布局
<Window x:Class="AIzhushou.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:AIzhushou.Converters"Title="智能聊天助手" Height="820" Width="420" MinHeight="800" MinWidth="400"WindowStartupLocation="Manual"Background="#333333" ResizeMode="CanResizeWithGrip"><Window.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="/Styles.xaml"/></ResourceDictionary.MergedDictionaries><local:EndMarkVisibilityConverter x:Key="EndMarkVisibilityConverter"/><local:MathConverter x:Key="MathConverter"/></ResourceDictionary></Window.Resources><Viewbox Stretch="Uniform"><Grid Width="420" Height="760" Background="#333333"><Grid.ColumnDefinitions><ColumnDefinition Width="63*"/><ColumnDefinition Width="337*"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="*"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions><!-- Top Buttons --><DockPanel Grid.Row="0" Grid.Column="1" Margin="265,0,20,5" Width="88"><Button  x:Name="setting" Style="{StaticResource MainButtonStyle}"Click="setting_Click" Height="40" Width="40" RenderTransformOrigin="0.5,0.5"DockPanel.Dock="Right"><Image Source="pack://application:,,,/AIzhushou;component/Img/icons8-home-page-50.png" Width="30" Height="30"/></Button></DockPanel><!-- Chat History Label --><Label Style="{StaticResource SectionLabelStyle}" Content="聊天记录" Margin="22,0,0,0" Grid.ColumnSpan="2" VerticalAlignment="Center"/><!-- Chat History RichTextBox --><Border Grid.Row="1" Style="{StaticResource ChatBorderStyle}" HorizontalAlignment="Left"Grid.ColumnSpan="2" Margin="15,0,0,10"><Border.Resources><Style TargetType="ScrollViewer" BasedOn="{StaticResource CustomScrollViewerStyle}" /></Border.Resources><RichTextBox x:Name="ChatHistoryRichTextBox" Style="{StaticResource ChatHistoryRichTextBoxStyle}"Loaded="ChatHistoryRichTextBox_Loaded" Width="380" Margin="-10,0,0,0"><RichTextBox.Resources><!-- 设置 Paragraph 的 Margin --><Style TargetType="Paragraph"><Setter Property="Margin" Value="0"/></Style></RichTextBox.Resources></RichTextBox></Border><!-- New Conversation Button --><StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,10,0,10" Grid.Column="1"><!--<Button x:Name="FreshButton" Style="{StaticResource FreshButtonStyle}" Click="freshButton_Click" Height="36" Width="120"><Button.Content><StackPanel Orientation="Horizontal"><Image Source="pack://application:,,,/AIzhushou;component/Img/icons8-refresh-96.png" Width="20" Height="20" Margin="0,0,5,0"/><TextBlock Text="刷新刚才回答" VerticalAlignment="Center" Foreground="#4d6bfe"/></StackPanel></Button.Content></Button>--><Button x:Name="NewConversationButton" Style="{StaticResource NewConversationButtonStyle}"Click="NewConversationButton_Click" Margin="90,0,5,0" Height="36" Width="120"><Button.Content><StackPanel Orientation="Horizontal"><Image Source="pack://application:,,,/AIzhushou;component/Img/icons8-talk-64.png" Width="20" Height="20" Margin="0,0,5,0"/><TextBlock Text="开启新对话" VerticalAlignment="Center" Foreground="#4d6bfe"/></StackPanel></Button.Content></Button></StackPanel><!-- Input Label --><Label Grid.Row="3" Style="{StaticResource SectionLabelStyle}" Content="输入消息" Margin="22,0,0,0" Grid.ColumnSpan="2" VerticalAlignment="Center"/><!-- Input Section --><Grid Grid.Row="4" HorizontalAlignment="Left" VerticalAlignment="Bottom"Margin="22,0,0,-10" Width="378" Grid.ColumnSpan="2"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions><!-- Input TextBox --><TextBox x:Name="InputTextBox" Grid.Column="0"Style="{StaticResource InputTextBoxStyle}"TextWrapping="Wrap" AcceptsReturn="True"KeyDown="InputTextBox_KeyDown"PreviewKeyDown="InputTextBox_KeyDown"/><!-- Send Button --><Border Grid.Column="1" Style="{StaticResource SendButtonBorderStyle}" Margin="10,0,0,0"><Button x:Name="SendButton" Style="{StaticResource SendButtonStyle}"Content="发送" Click="SendButton_Click" IsEnabled="True"/></Border></Grid></Grid></Viewbox>
</Window>

        1.4 、消息类

        设计这个是为了对消息类对API的信息进行存入和处理

 public enum MessageType{Question,Answer}public class ChatMessage{public static double DefaultBorderWidth { get; set; } = 300;public string Role { get; set; }public string Content { get; set; }public string WrappedContent { get; set; }public double BorderWidth { get; set; } = DefaultBorderWidth;public Brush BackgroundColor { get; set; }public Brush TextColor { get; set; }public DateTime Timestamp { get; set; }    public MessageType MessageType { get; set; }public ChatMessage(){Role = string.Empty;Content = string.Empty;WrappedContent = string.Empty;Timestamp = DateTime.Now;BackgroundColor = Brushes.White;TextColor = Brushes.Black;}public ChatMessage(string content, string wrappedContent, double borderWidth) : this(){Content = content;WrappedContent = wrappedContent;BorderWidth = borderWidth;}}

 


        1.5 、设置

        API KEY这里是必须填写的,不填写是无法进行问题的回答

这里是代码

private void SaveButton_Click(object sender, RoutedEventArgs e)
{// 更新用户信息currentUser.Username = UsernameTextBox.Text;currentUser.Password = PasswordBox.Password;currentUser.AiUrl = AiUrlTextBox.Text;currentUser.ModelUrl = ModelUrlTextBox.Text;currentUser.ApiKey = ApiKeyTextBox.Text == "请输入deepseek的API keys" ? string.Empty : ApiKeyTextBox.Text;// 保存语言设置var selectedLanguage = ((ComboBoxItem)LanguageComboBox.SelectedItem).Content.ToString();string languageCode = selectedLanguage == "中文" ? "zh-CN" : "en-US";AppSettings.Instance.DefaultLanguage = languageCode;AppSettings.Instance.SaveLanguageSettings(languageCode);// 保存复制选项设置//AppSettings.Instance.CopyCurrent = CopyCurrentRadio.IsChecked == true;AppSettings.Instance.Save();// 保存到配置文件string configPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"AIzhushou","config.json");// 确保目录存在var directoryPath = System.IO.Path.GetDirectoryName(configPath);if (string.IsNullOrEmpty(directoryPath)){throw new InvalidOperationException("无法确定配置文件的目录路径");}System.IO.Directory.CreateDirectory(directoryPath);// 序列化保存string json = Newtonsoft.Json.JsonConvert.SerializeObject(currentUser);System.IO.File.WriteAllText(configPath, json);MessageBox.Show("设置保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);this.Close();
}

 


三、运行图示 


四、总结

  •    实测了windows c#版本和python版本, c#版比python版本的性能更好,可能C#是微软亲儿子原因?
  •    一定用要异步处理,没有什么特别需要
  •    AI里面,deepseek是真的强
  •    如果需要提供协助,可以私信我

写着写着就这么多了,可能不是特别全,不介意费时就看看吧。有时间还会接着更新。


五、下载

        AI助手项目下载


http://www.ppmy.cn/server/164345.html

相关文章

数据挖掘常用算法

文章目录 基于机器学习~~线性/逻辑回归~~树模型~~贝叶斯~~~~聚类~~集成算法神经网络~~支持向量机~~~~降维算法~~ 基于机器学习 线性/逻辑回归 类似单层神经网络 yk*xb 树模型 优点 可以做可视化分析速度快结果稳定 依赖前期对业务和数据的理解 贝叶斯 贝叶斯依赖先验概…

STM32调试手段:重定向printf串口

引言 C语言中经常使用printf来输出调试信息&#xff0c;打印到屏幕。由于在单片机中没有屏幕&#xff0c;但是我们可以重定向printf&#xff0c;把数据打印到串口&#xff0c;从而在电脑端接收调试信息。这是除了debug外&#xff0c;另外一个非常有效的调试手段。 一、什么是pr…

C++ -vector的模拟实现

博客主页&#xff1a;【夜泉_ly】 本文专栏&#xff1a;【C】 欢迎点赞&#x1f44d;收藏⭐关注❤️ 自定义 vector 类的实现 我们将在 ly 命名空间下&#xff0c;简单实现一个模板化的 vector 类。 以下是完整的代码示例&#xff1a; namespace ly { template <class T&g…

智能汽车网络安全威胁报告

近年来随着智能汽车技术的快速发展&#xff0c;针对智能汽车的攻击也逐渐从传统的针对单一车辆控制器的攻击转变为针对整车智能化服务的攻击&#xff0c;包括但不限于对远程控制应用程序的操控、云服务的渗透、智能座舱系统的破解以及对第三方应用和智能服务的攻击。随着WP.29 …

spark运行流程

spark运行流程 任务提交后&#xff0c;先启动 Driver 程序随后 Driver 向集群管理器注册应用程序集群管理器根据此任务的配置文件分配 Executor 并启动Driver 开始执行 main 函数&#xff0c;Spark 查询为懒执行&#xff0c;当执行到 Action 算子时开始反向推 算&#xff0c;根…

编辑器Vim基本模式和指令 --【Linux基础开发工具】

文章目录 一、编辑器Vim 键盘布局二、Linux编辑器-vim使用三、vim的基本概念正常/普通/命令模式(Normal mode)插入模式(Insert mode)末行模式(last line mode) 四、vim的基本操作五、vim正常模式命令集插入模式从插入模式切换为命令模式移动光标删除文字复制替换撤销上一次操作…

如何使用 DeepSeek 和 Dexscreener 构建免费的 AI 加密交易机器人?

我使用DeepSeek AI和Dexscreener API构建的一个简单的 AI 加密交易机器人实现了这一目标。在本文中&#xff0c;我将逐步指导您如何构建像我一样的机器人。 DeepSeek 最近发布了R1&#xff0c;这是一种先进的 AI 模型。您可以将其视为 ChatGPT 的免费开源版本&#xff0c;但增加…

MYSQL5.7 全文检索中文无返回数据

在MySQL 5.7.6之前&#xff0c;全文索引只支持英文全文索引&#xff0c;不支持中文全文索引&#xff0c;需要利用分词器把中文段落预处理拆分成单词&#xff0c;然后存入数据库。 从MySQL 5.7.6开始&#xff0c;MySQL内置了ngram全文解析器&#xff0c;用来支持中文、日文、韩文…