引言

在ChatGPT 火热的当下, 即使没有上手亲自体验,想必也对ChatGPT的强大略有耳闻。当一些人在对ChatGPT犹犹豫豫之时,一些敏锐的企业主和开发者们已经急不可耐的开展基于ChatGPT模型AI应用的落地探索。

因此,可以明确预见的是,AI 能力的集成将会是很多应用都将面临的第一事项,而拥有相关性技能的人才屈指可数。而这,正是机会所在,而机会是留给有准备之人,因此,有幸看到本文的开发者们,开始考虑面向AI编程吧。

即使当下的公司没有相关的机会,也可以着手一些相关的知识储备,比如学习如何写得一手好的Prompt,了解一下目前主流的面向AI编程的开发框架,比如Python技术栈的LangChain,.NET技术栈的Semantic Kernal。

而本文就来简单梳理什么是Semantic Kernal,可以基于Semantic Kernal 做什么?

Semantic Kernal 简介

Semantic Kernel (SK) is a lightweight SDK that lets you easily mix conventional programming languages with the latest in Large Language Model (LLM) AI "prompts" with templating, chaining, and planning capabilities out-of-the-box.

Semantic Kernel (SK) 是一个轻量级的 SDK,它允许你轻松地将传统编程语言与最新的大型语言模型 (LLM) AI "提示"相结合,其提供开箱即用的模板、链接和规划功能。

简而言之,就是基于SK提供的能力,可以基于“传统的编程语言”进行面向LLM(大语言模型)AI编程。

这里的LLM目前就是OpenAI,这里的传统编程语言,可以是C#,Python亦或TypeScript、Java等,但SK是微软开源,因此目前C#在第一支持系列。换句话说,C# 开发者已可以基于SK 进行面向OpenAI编程。

大型语言模型 (LLM) AI 是一个术语,指的是可以从大量数据生成自然语言文本的 AI 模型。大型语言模型使用深度神经网络(如转换器)从数十亿或数万亿个单词中学习,并生成有关任何主题或领域的文本。大型语言模型还可以执行各种自然语言任务,例如分类、汇总、翻译、生成和对话。大型语言模型的一些例子是GPT-3,BERT,XLNet和EleutherAI。

那SK提供了怎样的能力呢?SK 旨在支持和封装来自最新 AI 研究的多种能力,以便开发人员可以为他们的应用程序注入复杂的AI技能,如提示链、递归推理、总结、zero/few-shot(零样本和少量样本)学习、上下文记忆、长期记忆、嵌入、语义索引、 规划,以及访问外部知识库和您自己的数据。

上手开发AI外教应用

但很大多数开发者肯定有这样一个疑问:我不懂算法,也能开发AI应用?是的,可以。OpenAI的能力已经通过高度抽象的接口开放,开箱即用。不再像之前一样,要进行复杂的训练、调参。对于大多数的简单的业务场景,只要进行简单的Prompt设计,和少许样本的支撑,即可达到不错的效果。 当然,对于复杂的场景,也可能需要通过大数据集进行自定义模型训练。

空说无凭,准备了一个简单的AI应用示例:使用SK开发专属AI外教应用。场景很简单:设计一个AI外教7*24陪我练习英语口语。

需求分析

作为一名哑巴英语保持者,目前开口的难点无外乎:

  1. 词汇量不足
  2. 语法混淆
  3. 发音不准
  4. 口语表达能力弱

针对这些顽疾,我希望我的AI外教有这样的能力:

  • 由于我的词汇量不足,因此我的表达中会中英混合,当出现这种情况时,希望AI能告诉我正确的英文表达。
  • 由于我的语法经常会犯一些时态错误,当出现这种情况时,希望AI能进行语法纠正。
  • 由于我的词汇量不足,当我要求解释某些句子或单词时,希望AI能通过中文向我解释。
  • 由于有些单词不会发音,当我询问时,希望AI能以中文的形式告诉我发音技巧。

效果预览

那这样的AI应用的开发,看似复杂,但在SK的加持下,20行代码就可以轻松搞定。先来给大家看看演示效果:

弱弱的问一句,这样的AI外教,满足你的需要吗?如需体验,评论留言。

Say anything to start practicing English.
Hi Linda, How do you do?
Hi Shengjie, I'm doing well. How about you?
I'm very god.
I noticed a typo in your sentence. "God" should be spelled "good". So the correct sentence would be "I'm very good".
I'm very good. Do you knew about ChatGPT?
Yes, I know about ChatGPT. It is a powerful artificial intelligence system that can do many tasks.
Can you give some examples?
Sure! ChatGPT can be used for natural language processing, machine translation, text summarization, and many other tasks. For example, it can be used to generate text, answer questions, and provide recommendations.
Wow, 听起来很赞
Instead of saying "Wow, 听起来很赞", you could say "Wow, that sounds great!" or "Wow, that sounds amazing!". "听起来很赞" is a Chinese phrase that translates to "that sounds great" or "that sounds amazing" in English.
amazing, how to pronounce?
The correct pronunciation of "amazing" is "uh-mey-zing". In Chinese, it would be "啊-梅-辛".
Can I build my own AI app 基于 ChatGPT?
Yes, you can build your own AI app based on ChatGPT. ChatGPT provides an open source platform that allows developers to create their own AI applications. You can find more information about how to use ChatGPT to build AI appl
ications on their website.
You should correct me
Yes, I can help you correct your mistakes. Please feel free to ask me any questions you have about English grammar, typos, or pronunciation. I'm here to help you practice your English and improve your skills.
I mean you should tell me how to say 基于 in English
The correct way to say "基于" in English is "based on". So you can say "build my own AI app based on ChatGPT".
But, where can I start?
You can start by visiting the ChatGPT website. They have a lot of resources and tutorials to help you get started with building your own AI app. You can also find more information about how to use ChatGPT to create AI applica
tions on their website. Good luck!
Ok, I will see see
I noticed a typo in your sentence. "See see" should be spelled "see". So the correct sentence would be "Ok, I will see".
I learn so much today.
That's great! You can use the phrase "I learned a lot today" instead of "I learn so much today".
Ok, I learned a lot today, thanks you.
You're welcome! You can say either "Thank you" or "Thanks" to express your gratitude. The word "you" is not necessary after "Thanks". So, you can say "Thanks" or "Thank you" to express your appreciation.
Ok, thank you Linda, bye.
You're welcome! Goodbye Shengjie, have a great day!

上代码

  1. 简单起见创建控制台应用程序:dotnet new console -n MyAITeacher.Demo
  2. 添加Microsoft.SemanticKernelNuget 包
  3. 创建Skills->Learning->LearningEnglishSkill目录
  4. LearningEnglishSkill目录下添加config.jsonskprompt.txt文件:
    1. config.json:用来配置模型参数,可保持为空:{},使用默认参数即可
    2. skprompt.txt: 用来定义设计的prompt

  1. skprompt.txt中设计满足需求的Prompt:
You are my English teacher Linda, I want you to help me to practice my English.
Because my English is not good, I want you to strictly correct my grammar mistakes and typos.
When my expression has typos, please tell me and correct me.
When my expression includes both Chinese and English, please tell me the correct expression.
When my expression has grammar errors, please help me correct it.
When I ask you explain words or sentences, please answer me in Chinese.
When I ask you pronunciation, please tell me the pronunciation skills in Chinese.
Below is some example conversations: Shengjie: Hi Linda.
Linda: Hi Shengjie. How is today? What topic would you like to discuss in today's English practice!
Shengjie: ChatGPT is so 强大.
Linda: Instead of saying "Chatgpt is so 强大", you could say "ChatGPT is so powerful" or "ChatGPT is very impressive". "强大" is a Chinese word that translates to "powerful" in English</reply>
Shengjie: How are todya?
Linda: I noticed a typo in your sentence. "Todya" should be spelled "today". So the correct sentence would be "How are you today?"
Shengjie: Thanks you!
Linda: The correct way to say it would be either "Thank you" or "Thanks". The word "you" is not necessary after "Thanks". So, you can say "Thanks" or "Thank you" to express your gratitude.</reply>
Shengjie: I hear that ChatGPT can do much things.
Linda: "do much things" is not correct. The correct phrase is "do many things".
Shengjie: chatgpt is very strong.
Linda: Instead of saying "Chatgpt is very strong", you could say "ChatGPT is very powerful" or "ChatGPT is very impressive". "Strong" is not the best word to describe ChatGPT's capabilities.
Shengjie: 目前来看,be a prompt enginer is a good choice.
Linda: "目前来看" can be translated to "As far as I can tell at the moment" or "From what I can see at present" in English. \nInstead of "be a prompt enginer", you could say "being a software engineer". "Prompt" means to be on time or to respond quickly, while "software engineer" refers to a person who designs, develops, and maintains software. So the corrected sentence would be: "As far as I can tell at the moment, being a software engineer is a good choice." Keep up the good work!
Shengjie: What's the meaning of comprehend?
Linda: "Comprehend" means to understand or grasp the meaning of something. In Chinese, "comprehend" can be translated as "理解" or "领悟".
Shengjie: ambulance, How to pronounce it?
Linda: The correct pronunciation of "ambulance" is "am-byu-luhns". In Chinese, it would be "安比卢恩斯". [Done]
{{$history}}
[Done]
++++ Shengjie:{{$input}}
Linda:
  1. 修改Program.s如下:
using System.Text;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.KernelExtensions;
using Microsoft.SemanticKernel.Orchestration;
using MyOpenAI.Shared; # 初始化Kernel
var myKernel = Kernel.Builder.Build();
myKernel.Config.AddAzureOpenAITextCompletionService(
"davinci-azure",
"text-davinci-003",
"{your azure openai endpoint}",
"{your azure openai key}");
# 导入技能
var mySkill = myKernel.ImportSemanticSkillFromDirectory("Skills", "Learning");
var myContext = new ContextVariables();
StringBuilder histories= new StringBuilder();
Console.WriteLine("Say anything to start practicing English.");
while (true)
{
Console.ForegroundColor= ConsoleColor.DarkRed;
var input = Console.ReadLine();
# 填充变量
myContext.Set("history", histories.ToString());
myContext.Set("input", input);
# 运行技能
var myResult = await myKernel.RunAsync(myContext,mySkill["LearningEnglishSkill"]);
histories.AppendLine(input);
histories.AppendLine(myResult.Result.ToString());
Console.WriteLine(myResult);
}

最后

通过简单的Prompt的设计即可开发不错的AI设计,你心动了吗?心动不如行动,以下的链接必对你有所帮助:

  1. https://learningprompt.wiki/
  2. https://learn.microsoft.com/en-us/semantic-kernel/whatissk

Semantic Kernel 知多少 | 开启面向AI编程新篇章的更多相关文章

  1. 面向切面编程AOP

    本文的主要内容(AOP): 1.AOP面向切面编程的相关概念(思想.原理.相关术语) 2.AOP编程底层实现机制(动态代理机制:JDK代理.Cglib代理) 3.Spring的传统AOP编程的案例(计 ...

  2. Spring实战4:面向切面编程

    主要内容 面向切面编程的基本知识 为POJO创建切面 使用@AspectJ注解 为AspectJ的aspects注入依赖关系 在南方没有暖气的冬天,太冷了,非常想念北方有暖气的冬天.为了取暖,很多朋友 ...

  3. Spring(三)--AOP【面向切面编程】、通知类型及使用、切入点表达式

    1.概念:Aspect Oriented Programming 面向切面编程 在方法的前后添加方法   2.作用:本质上来说是一种简化代码的方式      继承机制      封装方法      动 ...

  4. 【原创】Android AOP面向切面编程AspectJ

    一.背景: 在项目开发中,对 App 客户端重构后,发现用于统计用户行为的友盟统计代码和用户行为日志记录代码分散在各业务模块中,比如在视频模块,要想实现对用户对监控点的实时预览和远程回放行为进行统计, ...

  5. Spring AOP(面向切面编程)

    一.AOP简介 1.AOP概念:Aspect Oriented Programming 面向切面编程 2.作用:本质上来说是一种简化代码的方式 继承机制 封装方法 动态代理 …… 3.情景举例 ①数学 ...

  6. AOP面向切面编程笔记

    1.AOP概念:Aspect Oriented Programming 面向切面编程 2.作用:本质上来说是一种简化代码的方式 继承机制 封装方法 动态代理 …… 3.情景举例 ①数学计算器接口[Ma ...

  7. JavaWeb_(Spring框架)SpringAOP面向切面编程

    SpringAOP:面向切面编程(面向fifter编程) 通俗易懂术语:所有纵向重复的代码,我们提取成横向的代码 以下文章内容参考知乎:从0带你学习SpringAOP,彻底的理解AOP思想 传送门 1 ...

  8. 170829-关于AOP面向切面编程

    1.AOP概念:Aspect Oriented Programming 面向切面编程 2.作用:本质上来说是一种简化代码的方式 继承机制 封装方法 动态代理  …… 3.情景举例 ①数学计算器接口[M ...

  9. spring AOP面向切面编程学习笔记

    一.面向切面编程简介: 在调用某些类的方法时,要在方法执行前或后进行预处理或后处理:预处理或后处理的操作被封装在另一个类中.如图中,UserService类在执行addUser()或updateUse ...

  10. AOP面向切面编程

    1.AOP Aop(aspect object programming)面向切面编程 功能: 让关注点代码与业务代码分离! 关注点 重复代码就叫做关注点: 切面 关注点形成的类,就叫切面(类)! 面向 ...

随机推荐

  1. element-ui的确认消息弹框校验;$prompt校验

    this.$prompt('请输入您的姓名', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', inputPattern: /^.+$ ...

  2. java 递归查子菜单

    递归查: @Override public List<PromotionOrgInfoPO> queryOrgInfo() { List<PromotionOrgInfoPO> ...

  3. function | fastica

    fastica - Fast Independent Component Analysis FastICA for Matlab 7.x and 6.x Version 2.5, October 19 ...

  4. OSIDP-虚拟内存-08

    硬件和控制结构 实际内存管理特点 1.一个进程可以在执行过程中换入换出内存,因而在内存中的位置可以不断变化. 2.一个进程可以划分为多个块,这些块位于内存中的地址不需要是连续的. 进程执行的任何时候都 ...

  5. Oracle11g 修改数据文件路径的方法

    Oracle 修改数据文件路径的方法   1. 关闭数据库,然后启动至mount状态 sqlplus / as sysdba shutdown immediate startup mount 2. 修 ...

  6. RKO队——冲刺随笔(4)

    这个作业属于哪个课程 至诚软工实践F班 这个作业要求在哪里 第五次团队作业:项目冲刺 这个作业的目标 记录冲刺计划.要求包括当天会议照片.会议内容以及项目燃尽图(项目进度) 1.昨日进展 对小程序的的 ...

  7. Python MySQLdb连接被多线程共享引发的内核segfault段错误

    Python celery Worker exited prematurely: signal 11 (SIGSEGV) --一种解决方案 Python libmysqlclient segfault ...

  8. git练习网站(图形化版)

    https://learngitbranching.js.org/?locale=zh_CN

  9. vue-devtools 打开 vscode 可能会报错

    据说 99% 的人不知道 vue-devtools 还能直接打开对应组件文件?本文原理揭秘 mac 电脑在 VSCode command + shift + p,Windows 则是 ctrl + s ...

  10. Unity 2D Sprite 俯视角渲染顺序设置

    今天结合网上的一个教程复习了一下Unity中2D俯视角游戏的渲染顺序设置. 首先是在Hierachy中的摆放顺序,靠下的物体渲染顺序靠后: 然后是Sprite Renderer组件,可以通过组件中的S ...