{"id":24653967,"url":"https://github.com/senparc/senparc.ai","last_synced_at":"2025-04-12T14:58:21.390Z","repository":{"id":156397181,"uuid":"622973819","full_name":"Senparc/Senparc.AI","owner":"Senparc","description":"Senparc 全家桶的 AI 扩展包","archived":false,"fork":false,"pushed_at":"2025-04-10T15:02:00.000Z","size":1409,"stargazers_count":81,"open_issues_count":3,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-12T14:58:15.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Senparc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-03T12:49:05.000Z","updated_at":"2025-03-16T18:37:33.000Z","dependencies_parsed_at":"2023-09-22T19:24:59.679Z","dependency_job_id":"d3d9abf7-137e-48d7-bdf3-f2080f7f3c8f","html_url":"https://github.com/Senparc/Senparc.AI","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senparc%2FSenparc.AI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senparc%2FSenparc.AI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senparc%2FSenparc.AI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senparc%2FSenparc.AI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Senparc","download_url":"https://codeload.github.com/Senparc/Senparc.AI/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586250,"owners_count":21128997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-25T21:14:35.650Z","updated_at":"2025-04-12T14:58:21.369Z","avatar_url":"https://github.com/Senparc.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Senaprc.AI\r\nSenparc 全家桶的 AI 扩展包，目前主要集中于 LLM（大语言模型）的交互。\r\n\r\n\r\n## 项目介绍\r\n\r\n| 名称 | 说明 | Nuget |\r\n|--------|--------|--------|\r\n| Senparc.AI | 为所有标准接口和基础功能的基础模块 | [![Senparc.AI](https://img.shields.io/nuget/v/Senparc.AI.svg)](https://www.nuget.org/packages/Senparc.AI/) |\r\n| Senparc.AI.Kernel | 为基于 Senparc.AI 标准，使用 [SemanticKernel](https://github.com/microsoft/semantic-kernel) 实现的接口调用，可以实现即插即用。|  [![Senparc.AI.Kernel](https://img.shields.io/nuget/v/Senparc.AI.Kernel.svg)](https://www.nuget.org/packages/Senparc.AI.Kernel/) |\r\n| Senparc.AI.Agents | 为基于 Senparc.AI 标准，使用 [AutoGen](https://github.com/microsoft/autogen) 实现的 Agent 集成扩展模块。|  [![Senparc.AI.Agents](https://img.shields.io/nuget/v/Senparc.AI.Agents.svg)](https://www.nuget.org/packages/Senparc.AI.Agents/) |\r\n`Senparc.AI.PromptRange`\u003cbr\u003e([独立项目](https://github.com/Senparc/Senparc.AI.PromptRange)) | 为基于 Senparc.AI 标准，为“PromptRange（提示词靶场）”生态提供底层标准支持的底层库。目前已经由 [Senparc.Xncf.PromptRange](https://github.com/NeuCharFramework/NcfPackageSources/tree/master/src/Extensions/Senparc.Xncf.PromptRange) 实现，可用于开发基于 PromptRange 的扩展应用，兼容 Web、桌面、手机等系统（支持 .NET 6.0 及以上框架）。[NeuCharFramework(NCF)](https://github.com/orgs/NeuCharFramework) 框架已经默认集成 [Senparc.Xncf.PromptRange](https://github.com/NeuCharFramework/NcfPackageSources/tree/master/src/Extensions/Senparc.Xncf.PromptRange)，可无需修改任何代码，直接使用。（[什么是 PromptRange？](https://github.com/Senparc/Senparc.AI.PromptRange/wiki/What's-PromptRange%3F)） |  |\r\n\r\n## 开发过程\r\n\r\n### 第一步：配置账号\r\n\r\n在 appsettings.json 中配置 OpenAI 或 Azure OpenAI 的接口信息，如：\r\n\r\n``` json\r\n//Senparc.AI 设置\r\n\"SenparcAiSetting\": {\r\n  \"IsDebug\": true,\r\n  \"AiPlatform\": \"NeuCharAI\", //注意修改为自己平台对应的枚举值\r\n  \"NeuCharAIKeys\": {\r\n    \"ApiKey\": \"\u003cYour ApiKey\u003e\", //在 https://www.neuchar.com/Developer/AiApp 申请\r\n    \"NeuCharEndpoint\": \"https://www.neuchar.com/\u003cDeveloperId\u003e\", //查看 ApiKey 时可看到 DeveloperId\r\n    \"ModelName\": {\r\n      \"Chat\": \"gpt-4o\",\r\n      \"Embedding\": \"text-embedding-ada-002\",\r\n      \"TextCompletion\": \"gpt-35-turbo-instruct\"\r\n    }\r\n  },\r\n  \"AzureOpenAIKeys\": {\r\n    \"ApiKey\": \"\u003cYour AzureApiKey\u003e\", \r\n    \"AzureEndpoint\": \"\u003cYour AzureEndPoint\u003e\", //https://xxxx.openai.azure.com/\r\n    \"AzureOpenAIApiVersion\": \"2022-12-01\", //调用限制请参考：https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits\r\n    \"ModelName\": {\r\n      \"Chat\": \"gpt-35-turbo\"\r\n    }\r\n  },\r\n  \"OpenAIKeys\": {\r\n    \"ApiKey\": \"\u003cYour OpenAIKey\u003e\",\r\n    \"OrganizationId\": \"\u003cYour OpenAIOrgId\u003e\",\r\n    \"OpenAIEndpoint\": null,\r\n    \"ModelName\": {\r\n      \"Chat\": \"gpt-35-turbo\"\r\n    }\r\n  },\r\n  \"HuggingFaceKeys\": {\r\n    \"Endpoint\": \"\u003cYour EndPoint\u003e\", //HuggingFace 的 Endpoint\r\n    \"ModelName\": {\r\n      \"TextCompletion\": \"chatglm2\"\r\n    }\r\n  },\r\n  \"Items\": {\r\n    // 更多自定义配置\r\n  }\r\n}\r\n```\r\n\r\n其中：`AiPlatform` 是平台类型，目前可选值为 `OpenAI`、`NeuCharAI`、`AzureOpenAI`、`HuggingFace` 和 `FastAPI`，分别对应 openai.com 官方接口（OpenAI）、https://www.neuchar.com 由 Senparc 提供的中转接口、基于微软 Azure 的 AzureOpenAI 接口（AOAI)、HuggingFace 接口和 FastAPI 接口，系统会根据配置自动实现切换，无需在逻辑代码中进行判断。\r\n\r\n仅当 `AiPlatform` 设置为 `OpenAI` 时，才需要设置 `OpenAIKeys` 及以下参数。\r\n\r\n仅当 `AiPlatform` 设置为 `NeuCharAI` 时，才需要设置 `NeuCharAIKeys` 及以下参数。\r\n\r\n仅当 `AiPlatform` 设置为 `AzureOpenAI` 时，才需要设置 `AzureOpenAIKeys` 及以下参数。\r\n\r\n其他平台以此类推。\r\n\r\n每一个平台类型配置下，都有一个 `ModelName` 节点，用于设置该平台下需要被支持的模型类型，例如需要将 Chat 接口设置为 GPT-4 模型，则设置：`\"Chat\": \"gpt-4\"`。\r\n\r\n\u003e 提示：AzureOpenAI 调用限制请参考：https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits\u003cbr\u003e\r\n\u003e OpenAI 调用限制请参考 OpenAI 后台：https://platform.openai.com/docs/guides/rate-limits\r\n\r\n#### 进阶（一）：配置多模型环境\r\n\r\n#### 进阶（二）：动态配置模型参数\r\n\r\n### 第二步：开发\r\n\r\nSenparc.AI 使用了创新的对话式编程体验，您无需了解过多不同平台、SDK 的详细用法，只需要按照自己的想法进行定义和编程，最后接收结果，以目前最火的聊天场景（Chat）为例：\r\n\r\n```C#\r\n//获取 AI 模型配置（从 appsettings.json 自动读取）\r\nvar aiSetting = Senparc.AI.Config.SenparcAiSetting;\r\n\r\n// 创建 AI Handler 处理器（也可以通过工厂依赖注入）\r\nvar handler = new SemanticAiHandler(aiSetting);\r\n\r\n// 定义 AI 接口调用参数和 Token 限制等\r\nvar promptParameter = new PromptConfigParameter()\r\n{\r\n    MaxTokens = 2000,\r\n    Temperature = 0.7,\r\n    TopP = 0.5,\r\n};\r\n\r\n// 准备运行\r\nvar userId = \"JeffreySu\";//区分用户\r\nvar iWantToRun = \r\n     handler.IWantTo()\r\n            .ConfigModel(aiSetting.ModelName.Chat, userId, modelName)\r\n            .BuildKernel()\r\n            .RegisterSemanticFunction(\"ChatBot\", \"Chat\", promptParameter)\r\n            .iWantToRun;\r\n\r\n// 输入/提问，获取结果\r\nvar prompt = \"请问中国有多少人口？\";\r\nvar aiRequest = iWantToRun.CreateRequest(prompt, true, true);\r\nvar aiResult = await iWantToRun.RunAsync(aiRequest);\r\n//aiResult.Result 结果：中国的人口约为13.8亿。\r\n```\r\n\r\n\r\n\u003cimg width=\"623\" alt=\"image\" src=\"https://user-images.githubusercontent.com/2281927/230152103-3486fbfc-2426-407c-bcb6-74d4485eaf91.png\"\u003e\r\n\r\n## 示例\r\n\r\n所有快速参考示例位于 `/Samples/` 文件夹内\r\n\r\n文件夹 |  说明\r\n------|--------\r\nSamples/Senparc.AI.Samples.Consoles | 命令行\r\nSamples/Senparc.AI.Samples.Agents | Agent（智能体）测试，已集成 AutoGen\r\n\r\n## 命令示例行使用说明\r\n\r\n### 1. 打开解决方案\r\n\r\n打开解决方案 `Senparc.AI.sln`，设置 appsettings.json 中 ApiKey 等平台参数，启动项目 `Senparc.AI.Samples.Consoles`：\r\n\r\n\u003cimg width=\"801\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/d38d15cd-6b88-488e-8b74-a26934dfb538\"\u003e\r\n\r\n### 2. 操作\r\n\r\n#### 2.1 对话\r\n\r\n输入 `1`，进入对话操作：\r\n\r\n\u003cimg width=\"738\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/32933f21-c8db-4090-ad5a-a955039ee407\"\u003e\r\n\r\n#### 2.2 TextCompletion\r\n\r\n在主界面输入 `2` 进入 TextCompletion 操作：\r\n\r\n\u003cimg width=\"717\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/b28e67de-5334-4703-8b74-3da7f9c328fd\"\u003e\r\n\r\n\r\n#### 2.3 Embedding\r\n\r\n在主界面输入 `3` 即可进入 Embedding 操作，Embedding 分为常规信息和引用信息两类，将在下一步中做选择：\r\n\r\n#### 2.3.1 常规 Embedding（Information）\r\n\r\n选择 `1`，进入到常规 Embedding 测试，输入信息由 3 个英文冒号分割，录入完成后输入 `n` 开始对话测试：\r\n\r\n\u003cimg width=\"708\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/f22de4b1-1920-46fb-97fa-18265374d2ad\"\u003e\r\n\r\n\r\n#### 2.3.2 引用 Embedding（Reference）\r\n2.2.2 上一步选择 `2`，进入到引用 Embedding 测试，输入信息由 3 个英文冒号分割，录入完成后输入 `n` 开始对话测试：\r\n\r\n\u003cimg width=\"957\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/effd6bab-ba23-40ec-a125-7270b4dbbd29\"\u003e\r\n\r\n\r\n#### 2.4 DallE 绘图操作\r\n\r\n初始界面中输入 `4`，进入 DallE 接口的绘图操作：\r\n\r\n\u003cimg width=\"941\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/e353b059-3399-425a-80f3-ec0eed767b90\"\u003e\r\n\r\n结果将以 URL 的形式返回，此时出入 `s` ，可保存图片到本地：\r\n\r\n\u003cimg width=\"951\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/61daa2e3-a781-40ea-b47b-c360a3cc4464\"\u003e\r\n\r\n\u003e 注意：接口返回的 URL 是一个暂存地址，不可用于持久化的展示，需要及时保存，\r\n\r\n## 单元测试\r\n\r\n\u003cimg width=\"498\" alt=\"image\" src=\"https://github.com/Senparc/Senparc.AI/assets/2281927/6ec61a15-e1c7-423b-9886-0e401c070e35\"\u003e\r\n\r\n## TODO:\r\n1. [x] 实现更多模型和模式的匹配。\r\n1. [x] 实现全自动的工厂模块自动配置。\r\n1. [x] 集成到 [Senaprc.Weixin SDK](https://github.com/JeffreySu/WeiXinMPSDK)，0 逻辑代码实现 AI 能力接入（聊天场景为主）。\r\n1. [x] 集成到 [NeuCharFramework](https://github.com/NeuCharFramework/NCF)，0 逻辑代码实现 AI 能力接入（开发和云运营场景为主）。\r\n1. [ ] 完成更多默认模型适配（目前已经提供自定义扩展能力）\r\n1. [ ] 完善独立文档\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenparc%2Fsenparc.ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsenparc%2Fsenparc.ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenparc%2Fsenparc.ai/lists"}