Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 49 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img width="943" alt="image" src="https://github.com/Senparc/Senparc.AI/assets/2281927/1a3a5c32-98dc-473e-be00-ed4fd0319f4b"># Senaprc.AI
# Senaprc.AI
Senparc 全家桶的 AI 扩展包,目前主要集中于 LLM(大语言模型)的交互。


Expand All @@ -18,38 +18,58 @@ Senparc 全家桶的 AI 扩展包,目前主要集中于 LLM(大语言模型
在 appsettings.json 中配置 OpenAI 或 Azure OpenAI 的接口信息,如:

``` json
//Senparc.AI 设置
"SenparcAiSetting": {
"IsDebug": true,
"AiPlatform": "AzureOpenAI", //注意修改为自己平台对应的枚举值
"NeuCharOpenAIKeys": {
"ApiKey": "<Your ApiKey>", //在 https://www.neuchar.com/Developer/AiApp 申请
"NeuCharEndpoint": "https://www.neuchar.com/<DeveloperId>/" //查看 ApiKey 时可看到 DeveloperId
},
"AzureOpenAIKeys": {
"ApiKey": "<Your AzureApiKey>",
"AzureEndpoint": "<Your AzureEndPoint>",
"AzureOpenAIApiVersion": "2022-12-01"
},
"OpenAIKeys": {
"ApiKey": "<Your OpenAIKey>",
"OrganizationId": "<Your OpenAIOrgId>"
},
"HuggingFaceKeys": {
"Endpoint": "<Your EndPoint>"
//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`、`NeuCharOpenAI` 或 `AzureOpenAI`,分别对应 openai.com 官方接口(OpenAI),以及 https://www.neuchar.com 由 Senparc 提供的中转接口,及基于微软 Azure 的 Azure OpenAI 接口(AOAI,系统会根据配置自动实现切换,无需在逻辑代码中进行判断。
其中:`AiPlatform` 是平台类型,目前可选值为 `OpenAI`、`NeuCharOpenAI`、`AzureOpenAI`、`HuggingFace` 和 `FastAPI`,分别对应 openai.com 官方接口(OpenAI)https://www.neuchar.com 由 Senparc 提供的中转接口、基于微软 Azure 的 AzureOpenAI 接口(AOAI)、HuggingFace 接口和 FastAPI 接口,系统会根据配置自动实现切换,无需在逻辑代码中进行判断。

仅当 `AiPlatform` 设置为 `OpenAI` 时,才需要设置 `OpenAIKeys` 及以下参数。

仅当 `AiPlatform` 设置为 `NeuCharOpenAI` 时,才需要设置 `NeuCharOpenAIKeys` 及以下参数。

仅当 `AiPlatform` 设置为 `AzureOpenAI` 时,才需要设置 `AzureOpenAIKeys` 及以下参数。

其他平台以此类推。

每一个平台类型配置下,都有一个 `ModelName` 节点,用于设置该平台下需要被支持的模型类型,例如需要将 Chat 接口设置为 GPT-4 模型,则设置:`"Chat": "gpt-4"`。

> 提示:AzureOpenAI 调用限制请参考:https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quotas-limits<br>
> OpenAI 调用限制请参考 OpenAI 后台:https://platform.openai.com/docs/guides/rate-limits
Expand All @@ -63,8 +83,11 @@ Senparc 全家桶的 AI 扩展包,目前主要集中于 LLM(大语言模型
Senparc.AI 使用了创新的对话式编程体验,您无需了解过多不同平台、SDK 的详细用法,只需要按照自己的想法进行定义和编程,最后接收结果,以目前最火的聊天场景(Chat)为例:

```C#
//获取 AI 模型配置(从 appsettings.json 自动读取)
var aiSetting = Senparc.AI.Config.SenparcAiSetting;

// 创建 AI Handler 处理器(也可以通过工厂依赖注入)
var handler = new SemanticAiHandler();
var handler = new SemanticAiHandler(aiSetting);

// 定义 AI 接口调用参数和 Token 限制等
var promptParameter = new PromptConfigParameter()
Expand All @@ -76,10 +99,9 @@ var promptParameter = new PromptConfigParameter()

// 准备运行
var userId = "JeffreySu";//区分用户
var modelName = "text-davinci-003";//默认使用模型
var iWantToRun =
handler.IWantTo()
.ConfigModel(ConfigModel.TextCompletion, userId, modelName)
.ConfigModel(aiSetting.ModelName.Chat, userId, modelName)
.BuildKernel()
.RegisterSemanticFunction("ChatBot", "Chat", promptParameter)
.iWantToRun;
Expand All @@ -91,6 +113,7 @@ var aiResult = await iWantToRun.RunAsync(aiRequest);
//aiResult.Result 结果:中国的人口约为13.8亿。
```


<img width="623" alt="image" src="https://user-images.githubusercontent.com/2281927/230152103-3486fbfc-2426-407c-bcb6-74d4485eaf91.png">

## 示例
Expand Down Expand Up @@ -150,7 +173,7 @@ Samples/Senparc.AI.Samples.Agents | Agent(智能体)测试,已集成 AutoG

结果将以 URL 的形式返回,此时出入 `s` ,可保存图片到本地:

![Uploading image.png…]()
<img width="951" alt="image" src="https://github.com/Senparc/Senparc.AI/assets/2281927/61daa2e3-a781-40ea-b47b-c360a3cc4464">

> 注意:接口返回的 URL 是一个暂存地址,不可用于持久化的展示,需要及时保存,

Expand Down
2 changes: 1 addition & 1 deletion src/Senparc.AI.Agents/Senparc.AI.Agents.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>0.1-beta1</Version>
<Version>0.1.1-beta1</Version>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.AI.Agents</AssemblyName>
Expand Down