语义内核集成示例

一个使用Microsoft Semantic Kernel与OpenAI以及Model Context Protocol官方C# SDK的示例项目,展示了如何集成AI功能并发送电子邮件。

  • by mrazvanalex
  • C#
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 mrazvanalex/mpc-csharp-semantickernel

使用说明

$${\color{red}This\space存储库\space将\space不维护\space。\space这是\space只是\space一个\space快速\space示例。}$$

mpc-csharp语义核

Microsoft Semantic Kernel与OpenAI的示例使用以及模型上下文协议的官方C#SDK,可以在https://github.com/modelcontextprotocol/csharp-sdk

先决条件

SMTP电子邮件服务器(用于EmailTools) OpenAI ApiKey

如何运行示例

  1. 使用OpenAI开发者仪表板获取ApiKey。
  2. 填写每个单独项目的应用程序设置。
  3. 您可以向其发送电子邮件的电子邮件地址在Tools/EmailTool.cs中被硬编码为字典。用你的电子邮件列表更新字典。请随意设置此设置。
  4. 运行项目。默认启动设置设置为http://localhost:5109

应用程序设置

WebAppMCPoc项目

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "OpenAI": {
    "ApiKey": "<yourApiKey>",
    "ChatModelId" : "gpt-4o-mini"
  }
}

MCPServer项目

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "EmailSettings": {
    "SMTPServer": {
      "MailPort": "465",
      "MailServer": "<yourserver.com>",
      "Sender": "<sender@youremail.com>",
      "SenderName": "<AIEmailSender>",
      "Password": "<EmailPassword>",
      "Username": "<EmailUsername>"
    }
  }
}

发送请求:

您可以使用邮递员等工具发送请求。

请求示例: POST https://localhost:7113/chat 主体: { "text": "send and email toaFriend and tell him that you are an ai in 250 words. Tell him you're using C# to do this.."}

将{someone}替换为您在EmailTool电子邮件词典中添加的名称。

        private static readonly Dictionary<string, string> emails = new Dictionary<string, string>
        {
            { "example", "mail@example.com" },
            { "aFriend", "friendEmail@gmail.com" }
        };

许可证

该项目根据MIT许可证获得许可。