文章目录
1.AI 大模型发展现状
端午假期几天,关注到国内的AI大模型厂商近乎疯狂地打起了价格战,这边阿里云刚宣布降价97%,那边百度就宣布两款模型全面免费,好不热闹!据不完全统计,国内已有7家大模型企业“参战”,包括字节跳动、阿里云、百度、腾讯云等互联网大厂,智谱AI、深度求索等AI创企,以及垂直赛道头部玩家科大讯飞,纷纷争夺“最便宜”“最高性价比”大模型这块蛋糕。
▲国内大模型厂商参与价格战情况(智东西制表,统计于2024年5月27日)
总的来看,各大厂商对降价原因的解释无外乎以下几点:技术突破了,推理成本降低了;为开发者兜底,降低大模型的使用门槛;提升产品竞争力,积累客户。但大模型价格战对产业的影响具有两面性,既能够促使产业格局变化和商业模式创新,也为开发者带来机遇,有利于爆款应用的开发和大模型私有化部署。
2.基于AI服务的智慧对话开发
由于工作关系,涉及到相关文字材料的编制,对于某些材料,选用baidu的文心一言或者Aliyun的通义千问对于简单的工作来说可以提升部分效率,但是基于网页端还是存在一些限制,于是计划假期间利用C#语言+VS2015的win界面开发优势,配合大模型API实现快速的文本改写、文字降重以及智慧对话的功能
2.1 大模型API选择
选择讯飞星火大模型,其SparkLite免费为开发者开放,且不限tokens和有效期,提供各类开发的Demo源码,对于新手开发的话也比较友好。
2.2 基于C#的聊天界面开发
聊天界面开发计划基于Panel、RichTextBox、Button、PictureBox组成。其中Button主要负责模拟发送。
值得说明的是:Panel部分的聊天窗口由设计如下控件组成,且要支持右键菜单的复制和全选的功能,方便获取消息内容。
功能 | 控件 |
---|---|
头像 | PictureBox |
昵称 | Label |
发送时间 | Label |
信息详情 | RichTextBox |
右键菜单 | ContextMenuStrip |
实现的效果如下:
主窗体源码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//新建聊天控件全局变量
ChatBubble tsps_chat;
private void button1_Click(object sender, EventArgs e)
{
Image touxiang = (WindowsFormsApplication1.Properties.Resources._001);
Image touxiang2 = (WindowsFormsApplication1.Properties.Resources._002);
//发送
tsps_chat.AddMsg(touxiang2,
richTextBox1.Text, ChatBubble.MsgPlace.Right, "测试");
//模拟接收
tsps_chat.AddMsg(touxiang,
"你好,我有一个帽衫...",ChatBubble.MsgPlace.Left,"TSPS");
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.VerticalScroll.Visible = true;
panel1.AutoScroll = true;
Font ft = new Font("黑体", 12, Font.Style & ~FontStyle.Italic);
//创建新的聊天窗口(传入panel和font)
tsps_chat = new ChatBubble(panel1, ft);
}
}
}
Panel相关代码如下:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
/// <summary>
/// 聊天窗口展示类
/// </summary>
class Class1
{
}
class ChatBubble
{
/// <summary>
/// 生成菜单项
/// </summary>
/// <param name="txt"></param>
/// <param name="img"></param>
/// <returns></returns>
private ToolStripMenuItem GetMenuItem(string txt, Image img)
{
ToolStripMenuItem menuItem = new ToolStripMenuItem();
menuItem.Text = txt;
menuItem.Image = img;
return menuItem;
}
/// <summary>
/// 菜单项事件响应
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripMenuItem_Click(object sender, ToolStripItemClickedEventArgs e)
{
//ToolStripMenuItem menuSend = sender as ToolStripMenuItem;
//string selectText = ((RichTextBox)menuSend.).SelectedText;
//MessageBox.Show(menu.Text);
//获取对应控件的值
ContextMenuStrip menu_now = (ContextMenuStrip)sender;
RichTextBox tb = ((RichTextBox)(menu_now).SourceControl);
if (((ContextMenuStrip)sender).Items[0] == e.ClickedItem)//全选
{
tb.Focus();//设置先焦点定位到当前活动的RichTextBox,
tb.SelectAll();
}
else if (((ContextMenuStrip)sender).Items[1] == e.ClickedItem)//复制
{
Clipboard.SetDataObject(tb.SelectedText);
}
}
public ChatBubble(Panel panel, Font font)
{
if (panel.Controls.Count != 0) throw new Exception("指定Panel控件不为空!");
ChatPlace = panel;