C# 使用 Microsoft Semantic Kernel 示例
展示如何使用 Microsoft Semantic Kernel 与 OpenAI 和 MCP 服务器的示例项目。
快速入门指南
前置条件
- 需要一个 SMTP 邮件服务器(用于 EmailTools)。
- 获取 OpenAI 的 ApiKey。
运行步骤
- 在 OpenAI 开发者面板 获取 ApiKey。
- 根据每个项目的
appsettings
文件填写配置。- WebAppMCPPoc 项目需要填入 OpenAI 的
ApiKey
。 - MCPServer 项目需要设置邮件服务器信息,如 SMTP 地址、端口、用户名和密码。
- WebAppMCPPoc 项目需要填入 OpenAI 的
- 更新
Tools/EmailTool.cs
中的邮件地址字典,替换为你自己的邮箱列表。 - 启动项目,默认访问地址为 http://localhost:5109。
发送请求
使用工具(如 Postman)发送以下 POST 请求:
- URL: https://localhost:7113/chat
- 请求体:
{ "text": "send an email to aFriend and tell him that you are an ai in 250 words. Tell him you're using C# to do this."}
将 aFriend
替换为你在 EmailTool
字典中定义的名字。