首页 > 编程语言 >Semantic Kernel 知多少 | 开启面向AI编程新篇章

Semantic Kernel 知多少 | 开启面向AI编程新篇章

时间:2023-04-07 09:03:51浏览次数:54  
标签:Kernel Semantic AI Shengjie English Linda ChatGPT correct

引言

在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

标签:Kernel,Semantic,AI,Shengjie,English,Linda,ChatGPT,correct
From: https://www.cnblogs.com/sheng-jie/p/17294842.html

相关文章

  • Hi-C pairs 文件格式
    Hi-Cpairs文件格式##pairsformatv1.0#sorted:chr1-chr2-pos1-pos2#shape:uppertriangle#chromsize:chr1248956422#chromsize:chr2242193529#chromsize:chr3198295559#chromsize:chr4190214555#chromsize:chr5181538259#chromsize:chr6170805979#ch......
  • org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationExcept
    错误信息:com.xubo.rabbitmq.springbootrabbitmq.SpringbootRabbitmqApplication._________/\\/___'_____(_)______\\\\(()\___|'_|'_||'_\/_`|\\\\\\/___)||_)||||......
  • C 牛哥与AI (双hash,map处理 )2023年“华为”杯广东工业大学第十七届程序设计竞赛
     思路:从时间复杂度入手,就可以考虑暴力枚举每一种情况,然后利用数据结构去保存这些信息如何保存捏?自己想的是利用map<bitset>去做,真sb直接利用双hash,转化为数值然后map存就彳于了, 记住hash并不是只有字符串才用,01序列甚至图上,或者其他很多抽象的东西要去转......
  • 如何获得OpenAI API Key及OpenAI绑卡充值教程
    原帖地址:如何获得OpenAIAPIKey及OpenAI绑卡充值教程参考:使用虚拟信用卡升级ChatGPTPlus及OpenAI付款设置教程如果您想使用OpeanAIAPI开发一个聊天机器人或者使用OpenAIAPI进行自动化办公,您首先要创建一个OpenAIAPIKey,方法如下:打开platform.openai.com,输入你的OpenAI帐号......
  • 迁移学习《Asymmetric Tri-training for Unsupervised Domain Adaptation》
    论文信息论文标题:AsymmetricTri-trainingforUnsupervisedDomainAdaptation论文作者:KuniakiSaito, Y.Ushiku, T.Harada论文来源:27February2017——ICML论文地址:download 论文代码:download视屏讲解:click1介绍简单的域分布对齐可能无法提供有效的判别表示,为学......
  • AIArena Frontend 初步练习
    尝试对starter项目的页面进行改变修改侧边栏,只留下最上面的「仪表盘」和「列表页」两个大模块inSideNav.vuethecodeforthesidebarmenuis:<menu-content:navData="menu"/>fromtherewecangettoMenuContent.vueIthinkitisreferencingtheitemsinalis......
  • 07-网络安全-kail linux 网络配置(基础篇)
    一、网络配置1.查看网络IP地址,我的kail:192.168.15.128使用ifconfig查看kail网络连接情况,ip地址情况又复制了一台kail计算机的IP地址。   再看一下windows本机:使用ipconfig进行查看:再看一下虚拟机上的win7IP地址: 还可以使用ping命令检测网络是否连通:在同一个网段......
  • static关键字,main方法,代码块,final关键字
    static关键字,main()方法,代码块,final关键字static关键字的使用:static:静态的static可以修饰:属性、方法、代码块、内部类使用static修饰的变量:静态变量(类变量)3.1属性:实例变量:我们创建了多个类的对象,每个对象都拥有一套独立的类的非静态属性,当修改其中一个对象的非静......
  • AIRIOT赋能水务行业深度转型,打造智慧水务“四化建设”
     水利水务与民生息息相关,随着我国智慧城市建设的推进及科学技术的不断发展,对城市供水管理产生了尤为重要的影响。面对水务行业信息化建设周期长,无统一的技术标准和数据标准,信息孤岛严重,协同工作能力受制约,运营分析缺乏数据支撑和科学依据等一系列问题。因此,结合城市供......
  • 【Linux】raid管理工具-mdadm-raid0管理
    文章目录mdadm介绍mdadm命令的参数实战raid0新增两块硬盘创建raid0把配置信息保存起来对raid0创建分区格式化分区并挂载设置开机自动挂载mdadm介绍管理软raid工具:mdadmmdadm是linux下用于创建和管理软件RAID的命令,是一个模式化命令mdadm命令的参数-C建立一个新阵列-A激活磁......