如何生成内核
使用语义内核 SDK 只需最少的设置。 若要开始创建自己的 AI 代理,只需使用 SDK 包和大型语言模型 (LLM) 服务的终结点。 SDK 使用此终结点连接到 LLM 并运行提示。 语义内核 SDK 支持 HuggingFace、OpenAI 和 Azure OpenAI LLM。 在本例中,我们使用 Azure OpenAI。
开始使用语义内核 SDK 的步骤如下:
安装语义内核 SDK。
在 Visual Studio Code 中,可以使用以下命令:
dotnet add package Microsoft.SemanticKernel --version 1.30.0导航到 Azure 门户。
创建新的 Azure OpenAI 资源(如果还没有)。
为要使用的模型创建部署。
检索密钥和终结点。
将密钥和终结点添加到内核生成器服务。
using Microsoft.SemanticKernel;
// Populate values from your OpenAI deployment
var modelId = "";
var endpoint = "";
var apiKey = "";
// Create a kernel with Azure OpenAI chat completion
var builder = Kernel.CreateBuilder().AddAzureOpenAIChatCompletion(modelId, endpoint, apiKey);
// Build the kernel
Kernel kernel = builder.Build();
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
# Populate values from your OpenAI deployment
model_id = ""
endpoint = ""
api_key = ""
# Create a kernel and add Azure OpenAI chat completion
kernel = Kernel()
kernel.add_service(
AzureChatCompletion(
deployment_name=model_id,
endpoint=endpoint,
api_key=api_key
)
)
kernel.add_service(chatcompletion)
在以下练习中,你可以练习设置自己的语义内核项目。