Semantic Kernel:微软大模型开发框架——LangChain 替代

news/2024/7/8 2:31:54 标签: microsoft, langchain, 人工智能, python, llm, 大模型

大模型相关目录

大模型,包括部署微调prompt/Agent应用开发、知识库增强、数据库增强、知识图谱增强、自然语言处理、多模态等大模型应用开发内容
从0起步,扬帆起航。

  1. 基于Dify的QA数据集构建(附代码)
  2. Qwen-2-7B和GLM-4-9B:大模型届的比亚迪秦L
  3. 文擎毕昇和Dify:大模型开发平台模式对比
  4. Qwen-VL图文多模态大模型微调指南
  5. 从零开始的Ollama指南:部署私域大模型
  6. 基于Dify的智能分类方案:大模型结合KNN算法(附代码)
  7. OpenCompass:大模型测评工具
  8. 一文读懂多模态大模型基础架构
  9. 大模型管理平台:one-api使用指南
  10. 大模型RAG、ROG、RCG概念科普
  11. RAGOnMedicalKG:大模型结合知识图谱的RAG实现
  12. DSPy:变革式大模型应用开发
  13. 最简明的Few-shot Prompt指南
  14. Semantic Kernel:微软大模型开发框架——LangChain 替代

文章目录

  • 大模型相关目录
  • Semantic Kernel介绍
  • 与Langchain对比
  • 部署使用


Semantic Kernel介绍

Semantic Kernel:一个集成大型语言模型 (LLM) 的 SDK,如 OpenAI、Azure OpenAI、 以及使用 C#、Python 和 Java 等传统编程语言的 Hugging Face。语义内核实现了这一点 通过允许您定义可以链接在一起的插件 只需几行代码。

然而,语义内核的特别之处在于它能够自动编排 带有 AI 的插件。使用语义内核规划器,您可以 可以要求 LLM 生成实现用户唯一目标的计划。之后 语义内核将为用户执行计划。

Semantic Kernel 的主要特点:

• 灵活的插件架构: 允许开发者定义可以链接在一起的插件,仅需几行代码 即可实现复杂的功能。

• AI 驱动的插件编排: 可以使用 Semantic Kernel 规划器 让 LLM 生成一个计划来实现用户的独特目标,然后 Semantic Kernel 将为用户执行该计划。

• 多语言支持: 支持 C#、Python 和 Java 编程语言,方便不同技术背景的开发者使用。

在这里插入图片描述

与Langchain对比

LangChain 作为一款备受欢迎的 AI 应用开发框架,凭借其丰富的预制组件和易用性,吸引了众多开发者的目光。然而,微软开源的 Semantic Kernel 框架以其独特的优势和强大的功能,为开发者带来了全新的选择,或将成为 LangChain 的有力竞争者。
在这里插入图片描述

部署使用

项目开源地址:

python">https://github.com/microsoft/semantic-kernel

python教程:

python">https://github.com/microsoft/semantic-kernel/blob/main/python/samples/getting_started/03-prompt-function-inline.ipynb

在这里插入图片描述
安装最新软件包:

python">python -m pip install --upgrade semantic-kernel

如果要使用一些可选依赖项(默认安装 OpenAI),可以使用以下命令进行安装:

python">python -m pip install --upgrade semantic-kernel[hugging_face]

或全部:

python">python -m pip install --upgrade semantic-kernel[all]

使用示例:

python">import asyncio

from semantic_kernel importKernel
from semantic_kernel.functions import kernel_function
from semantic_kernel.connectors.ai.open_ai importAzureChatCompletion
from semantic_kernel.connectors.ai.function_call_behavior importFunctionCallBehavior
from semantic_kernel.connectors.ai.chat_completion_client_base importChatCompletionClientBase
from semantic_kernel.contents.chat_history importChatHistory
from semantic_kernel.functions.kernel_arguments importKernelArguments

from semantic_kernel.connectors.ai.open_ai.prompt_execution_settings.azure_chat_prompt_execution_settings import(
AzureChatPromptExecutionSettings,
)

asyncdefmain():
# Initialize the kernel
    kernel =Kernel()

# Add Azure OpenAI chat completion
    kernel.add_service(AzureChatCompletion(
        deployment_name="your_models_deployment_name",
        api_key="your_api_key",
        base_url="your_base_url",
))

# Set the logging level for  semantic_kernel.kernel to DEBUG.
    logging.basicConfig(
format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
)
    logging.getLogger("kernel").setLevel(logging.DEBUG)

# Add a plugin (the LightsPlugin class is defined below)
    kernel.add_plugin(
LightsPlugin(),
        plugin_name="Lights",
)

    chat_completion :AzureChatCompletion= kernel.get_service(type=ChatCompletionClientBase)

# Enable planning
    execution_settings =AzureChatPromptExecutionSettings(tool_choice="auto")
    execution_settings.function_call_behavior =FunctionCallBehavior.EnableFunctions(auto_invoke=True, filters={})

# Create a history of the conversation
    history =ChatHistory()

# Initiate a back-and-forth chat
    userInput =None
whileTrue:
# Collect user input
        userInput =input("User > ")

# Terminate the loop if the user says "exit"
if userInput =="exit":
break

# Add user input to the history
        history.add_user_message(userInput)

# Get the response from the AI
        result =(await chat_completion.get_chat_message_contents(
            chat_history=history,
            settings=execution_settings,
            kernel=kernel,
            arguments=KernelArguments(),
))[0]

# Print the results
print("Assistant > "+str(result))

# Add the message from the agent to the chat history
        history.add_message(result)

# Run the main function
if __name__ =="__main__":
    asyncio.run(main())

http://www.niftyadmin.cn/n/5536197.html

相关文章

【超级实用的一些adb命令】

实用的一些adb命令 #实用的一些adb命令 ##获取屏幕分辨率 adb shell wm size Physical size: 1920x1080##获取屏幕密度 adb shell wm density Physical density: 240##获取CPU信息 adb shell cat /proc/cpuinfo##获取内存信息 adb shell cat /proc/meminfo##给模拟器输入框输…

Avalonia应用在基于Linux的国产操作deepin上运行

deepin系统介绍 deepin(原名Linux Deepin)致力于为全球用户提供美观易用,安全可靠的 Linux发行版。deepin项目于2008年发起,并在2009年发布了以 linux deepin为名称的第一个版本。2014年4月更名为 deepin,在中国常被称为“深度操作系统”。 …

docker集群部署主从mysql

搭建一个mysql集群,1主2从,使用docker容器 一、创建docker的mysql镜像 下次补上,因为现在很多网络不能直接pull,操作下次补上。 二、创建mysql容器 创建容器1 docker run -it -d --name mysql_1 -p 7001:3306 --net mynet --…

FPGA问题

fpga 问题 ep2c5t144 开发板 第一道坎,安装软件;没有注册,无法产生sop文件,无法下载 没有相应的库的quartus ii版本,需要另下载 第二道坎,模拟器的下载,安装; 第三道,v…

Java中深度理解线程和进程

在Java中理解和区分线程和进程是至关重要的,因为它们是实现并发和多任务的基础。 进程(Process) 定义: 进程是程序在计算机上的一次执行活动,是系统进行资源分配和调度的基本单位。每个进程都有自己的独立地址空间、堆栈和数据段&#xff0…

基于轨迹信息的图像近距离可行驶区域方案验证

一 图像可行驶区域方案 1.1 标定场景 1.2 标定步骤 设计一定间距标定场,在标定场固定位置设置摄像头标定标识点。主车开到标定场固定位置录制主车在该位置各个摄像头数据,通过摄像头捕获图像获取图像上关键点坐标pts-2d基于标定场设计,计算…

服务器工具集合推荐

推荐一个朋友开源的服务器运维整合工具,目前的功能包括: ddns,rdp、ssh终端、ftp、http代理,支持在线文件编辑,文件管理,docker,进程,系统监控、wol唤醒,电脑远程开机,点对点&#…

Winform和WPF中关于是否处于设计模式的判断方式

在界面开发中,若在构造函数中增加了加载数据的代码,在设计界面时会出现界面打不开或者出现报错的情况。此时,可以检查一下是否为该情况。 Winform中的DesignMode判断 在WinForm开发中,一般会在窗体或者UserControl中判断当前是否为设计状态,…