Senparc
说明 | Nuget | |
---|---|---|
Senparc.AI | 为 |
|
Senparc.AI.Kernel | 为基于 Senparc.AI 标准, |
|
Senparc.AI.Agents | 为基于 Senparc.AI 标准, |
|
Senparc.AI.PromptRange ( |
为基于 Senparc.AI 标准,为“PromptRange( |
//Senparc.AI 设置
"SenparcAiSetting": {
"IsDebug": true,
"AiPlatform": "NeuCharAI", //注意 修 改 为自己 平台 对应的 枚 举值
"NeuCharAIKeys": {
"ApiKey": "<Your ApiKey>", //在 https://www.neuchar.com/Developer/AiApp 申 请
"NeuCharEndpoint": "https://www.neuchar.com/<DeveloperId>", //查看 ApiKey 时可看 到 DeveloperId
"ModelName": {
"Chat": "gpt-4o",
"Embedding": "text-embedding-ada-002",
"TextCompletion": "gpt-35-turbo-instruct"
}
},
"AzureOpenAIKeys": {
"ApiKey": "<Your AzureApiKey>",
"AzureEndpoint": "<Your AzureEndPoint>", //https://xxxx.openai.azure.com/
"AzureOpenAIApiVersion": "2022-12-01", //调用限 制 请参考 :https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits
"ModelName": {
"Chat": "gpt-35-turbo"
}
},
"OpenAIKeys": {
"ApiKey": "<Your OpenAIKey>",
"OrganizationId": "<Your OpenAIOrgId>",
"OpenAIEndpoint": null,
"ModelName": {
"Chat": "gpt-35-turbo"
}
},
"HuggingFaceKeys": {
"Endpoint": "<Your EndPoint>", //HuggingFace 的 Endpoint
"ModelName": {
"TextCompletion": "chatglm2"
}
},
"Items": {
// 更 多 自 定 义配置
}
}
其中:AiPlatform
OpenAI
、NeuCharAI
、AzureOpenAI
、HuggingFace
FastAPI
,
仅当 AiPlatform
设置为 OpenAI
时,OpenAIKeys
及以
仅当 AiPlatform
设置为 NeuCharAI
时,NeuCharAIKeys
及以
仅当 AiPlatform
设置为 AzureOpenAI
时,AzureOpenAIKeys
及以
其他
ModelName
节点,"Chat": "gpt-4"
。
提示 :AzureOpenAI 调用限 制 请参考 :https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits
OpenAI 调用限 制 请参考 OpenAI后 台 :https://platform.openai.com/docs/guides/rate-limits
Senparc.AI
//获取 AI 模型 配置 (从 appsettings.json 自 动读取)
var aiSetting = Senparc.AI.Config.SenparcAiSetting;
// 创建 AI Handler 处理器 (也可以通过工厂依赖注入 )
var handler = new SemanticAiHandler(aiSetting);
// 定 义 AI 接 口 调用参 数 和 Token 限 制 等
var promptParameter = new PromptConfigParameter()
{
MaxTokens = 2000,
Temperature = 0.7,
TopP = 0.5,
};
// 准 备运行
var userId = "JeffreySu";//区分 用 户
var iWantToRun =
handler.IWantTo()
.ConfigModel(aiSetting.ModelName.Chat, userId, modelName)
.BuildKernel()
.RegisterSemanticFunction("ChatBot", "Chat", promptParameter)
.iWantToRun;
// 输入/提 问,获取结果
var prompt = "请问中 国有 多少 人口 ?";
var aiRequest = iWantToRun.CreateRequest(prompt, true, true);
var aiResult = await iWantToRun.RunAsync(aiRequest);
//aiResult.Result 结果:中国 的 人口 约为13.8亿。
/Samples/
说明 | |
---|---|
Samples/Senparc.AI.Samples.Consoles | |
Samples/Senparc.AI.Samples.Agents | Agent( |
Senparc.AI.sln
,设置 appsettings.json Senparc.AI.Samples.Consoles
:
![image](https://private-user-images.githubusercontent.com/2281927/332745765-d38d15cd-6b88-488e-8b74-a26934dfb538.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMjc0NTc2NS1kMzhkMTVjZC02Yjg4LTQ4OGUtOGI3NC1hMjY5MzRkZmI1MzgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0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3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.EW4WphzUJaNdyT6FOcKT0phLnGBv7qzlxwhN0LdQSS0)
2
进入 TextCompletion
![image](https://private-user-images.githubusercontent.com/2281927/332746100-b28e67de-5334-4703-8b74-3da7f9c328fd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMjc0NjEwMC1iMjhlNjdkZS01MzM0LTQ3MDMtOGI3NC0zZGE3ZjljMzI4ZmQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjRUMTMwNDM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njg5MjU5N2NkODI3MzQ5ZDkyMTAyYjJhYmZhNTBiMTJmM2I3MjdhNDVmYWVjMjU2NjhkNzRjOTIyNWY1Njk1ZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.JWPl7eYQqO21WqzNh2Rrc9XSzNIyhrml13bE_TpZ4EE)
3
选择 1
,进入n
开始对话测试:
![image](https://private-user-images.githubusercontent.com/2281927/332746631-f22de4b1-1920-46fb-97fa-18265374d2ad.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMjc0NjYzMS1mMjJkZTRiMS0xOTIwLTQ2ZmItOTdmYS0xODI2NTM3NGQyYWQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjRUMTMwNDM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjViYTM3M2JlODliYzllZmVjMmFiODM0MDQ0MTM5NjM3NzU3YTAwMThhNGJkZmQ2NzhkZjMwZjdlZWU5ZTY4MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.mr4_iIsGbpRA5isZKOHYJAmRaiFdC6In0BV0AxuwjrE)
2.2.2 2
,进入n
开始对话测试:
![image](https://private-user-images.githubusercontent.com/2281927/332746447-effd6bab-ba23-40ec-a125-7270b4dbbd29.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMjc0NjQ0Ny1lZmZkNmJhYi1iYTIzLTQwZWMtYTEyNS03MjcwYjRkYmJkMjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNCUy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WQ9MCZyZXBvX2lkPTAifQ.i360HpbRh-0FHVQuZXwYnEGwmQu_vB8ZKFnynOtmcqU)
结果s
,
![image](https://private-user-images.githubusercontent.com/2281927/332751888-61daa2e3-a781-40ea-b47b-c360a3cc4464.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMjc1MTg4OC02MWRhYTJlMy1hNzgxLTQwZWEtYjQ3Yi1jMzYwYTNjYzQ0NjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjRUMTMwNDM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NmQwZTNhNTJlYzg2MzBkZTkyZTBkNzY1ZTcyMjY1MWI3OThiNmUzYzk3OWQ0N2IxOTM2NzEzZDhlMjBlNjc3ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.hkMjasxCO9UHkTWKetE28HKUwJx-bTTUk7ChzTOyCeo)
注意 :接 口 返 回 的 URL是 一 个暂存 地 址 ,不 可用 于持久 化 的 展示 ,需要 及时保存 ,
![image](https://private-user-images.githubusercontent.com/2281927/333240745-6ec61a15-e1c7-423b-9886-0e401c070e35.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MDQ5NzcsIm5iZiI6MTcyNDUwNDY3NywicGF0aCI6Ii8yMjgxOTI3LzMzMzI0MDc0NS02ZWM2MWExNS1lMWM3LTQyM2ItOTg4Ni0wZTQwMWMwNzBlMzUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjRUMTMwNDM3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDZlYjJmOTc4NDdmMzcxOGIxNDA0M2RlNTFkYWU2M2JiMzllZjIxN2RjNjJmZmE4NDBmYzdhNDg1NzU3NzIwNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Lgwpxo6CkzKiGNGzCe2EBkLVb8vByuPB0xz6tQATZ1U)
- 实现
更 多 模型 和 模 式 的 匹 配 。 - 实现
全 自 动的工 厂模块自动配置 。 -
集成 到 Senaprc.Weixin SDK,0 逻辑代 码实现 AI能力 接 入 (聊天场景为主)。 -
集成 到 NeuCharFramework,0 逻辑代 码实现 AI能力 接 入 (开发和 云 运营场景为主)。 -
完成 更 多 默 认模型 适配(目前 已 经提供 自 定 义扩展 能力 ) -
完 善 独立 文 档