China.AiChat.Sdk
1.0.1
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.6.2
This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
dotnet add package China.AiChat.Sdk --version 1.0.1
NuGet\Install-Package China.AiChat.Sdk -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="China.AiChat.Sdk" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add China.AiChat.Sdk --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: China.AiChat.Sdk, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install China.AiChat.Sdk as a Cake Addin #addin nuget:?package=China.AiChat.Sdk&version=1.0.1 // Install China.AiChat.Sdk as a Cake Tool #tool nuget:?package=China.AiChat.Sdk&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
China.AiChat.Sdk
China.AiChat.Sdk 集成DeepSeek,Kimi,Volcengine等ai引擎,适用于VB.NET,C#.NET,.NET CORE等应用程序使用,支持普通对话,流式对话,查询余额,列出模型等接口。并支持.Net FarmeWork流式输出,WinForm,Office Vsto插件,CAD插件,Solid Work插件,CDR插件等应用接入场景。更多内容,请关注,微信公众号:办公魔盒
.NET .NET Framework版本支持
.NET 实现 | 版本支持 |
---|---|
.NET 和.NET Core | 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0 |
.NET Framework | 4.6.1、4.6.2、4.7、4.7.1、4.7.2、4.8、4.8.1 |
Mono | 5.4、6.4 |
Xamarin.iOS | 10.14、12.16 |
Xamarin.Mac | 3.8、5.16 |
Xamarin.Android | 8.0、10.0 |
通用 Windows 平台 | 10.0.16299,待定 |
Unity | 2018 年 1 月 |
示例代码
VB.NET
Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
<TestClass()>
Public Class UnitTest1
''' <summary>
''' 多轮对话
''' </summary>
''' <returns></returns>
Private Property resultMsg As New System.Text.StringBuilder
''' <summary>
''' 深度求索DeepSeek测试
''' </summary>
<TestMethod()>
Public Async Function DeepSeekTest() As Task
' api密钥
Dim apikey As String = "sk-6666666666666666666666"
' 创建ds对象
Dim ds As IChinaAiChat = China.AiChat.Sdk.CreateService(AiType.DeepSeek, apikey)
'' 模型查询
'Dim modelList As Model = Await ds.GetModelList()
'Trace.WriteLine(modelList)
'' 余额查询
'Dim ResBalance As Balance = Await ds.GetBalance
'Trace.WriteLine(ResBalance)
''-----------------
'Dim chatReq As New ChatRequest With {
' .Messages = New List(Of ChatRequest.MessagesType) From {
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.System,
' .Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
' },
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.User,
' .Content = "你是谁?"
' }
' },
' .Model = China.AiChat.Sdk.ModelEnum.DeepseekChat,
' .ResponseFormat = New ChatRequest.ResponseFormatType(),
' .StreamOptions = New ChatRequest.StreamOptionsType(),
' .Stream = False,
' .FrequencyPenalty = 0,
' .MaxTokens = 4096,
' .PresencePenalty = 0,
' .Temperature = 1,
' .TopP = 1,
' .Logprobs = False
'}
'Dim chatRes As ChatResponse = Await ds.Chat(chatReq)
'Trace.WriteLine(chatRes.Choices.First.Message.Content)
'-----------------
Dim chatReq As New ChatRequest With {
.Messages = New List(Of ChatRequest.MessagesType) From {
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.System,
.Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
},
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.User,
.Content = "你是谁?"
}
},
.Model = China.AiChat.Sdk.ModelEnum.DeepseekChat,
.ResponseFormat = New ChatRequest.ResponseFormatType(),
.StreamOptions = New ChatRequest.StreamOptionsType(),
.Stream = True,
.FrequencyPenalty = 0,
.MaxTokens = 4096,
.PresencePenalty = 0,
.Temperature = 1,
.TopP = 1,
.Logprobs = False
}
'' 多轮对话
If Not String.IsNullOrWhiteSpace(resultMsg.ToString) Then
chatReq.Messages.Add(New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.Assistant,
.Content = resultMsg.ToString
})
End If
Await ds.ChatStream(chatReq, openedCallBack:=Sub(state As String) ''打开状态
Trace.WriteLine(state)
End Sub,
closedCallBack:=Sub(state) ''关闭状态
Trace.WriteLine(state)
resultMsg.Clear() ''拼接完成则清空,进行下一轮拼接
End Sub,
msgCallback:=Sub(res As ChatResponse) ''接收信息
Dim msg As String = res.Choices.First?.Delta?.Content
resultMsg.Append(msg)
Trace.WriteLine(msg)
End Sub,
errorCallback:=Sub(ex As String) ''异常处理
Trace.WriteLine(ex)
End Sub)
Await Task.CompletedTask
End Function
''' <summary>
''' 抖音火山引擎DeepSeek测试
''' </summary>
<TestMethod()>
Public Async Function VolcengineTest() As Task
' api密钥
Dim apikey As String = "bae6666666666666666666666666666"
' 创建doubao对象
Dim doubao As IChinaAiChat = China.AiChat.Sdk.CreateService(AiType.Volcengine, apikey)
''-----------------
'Dim chatReq As New ChatRequest With {
' .Messages = New List(Of ChatRequest.MessagesType) From {
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.System,
' .Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
' },
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.User,
' .Content = "你是谁?"
' }
' },
' .Model = China.AiChat.Sdk.ModelEnum.DouBao1_5Pro32k,
' .StreamOptions = New ChatRequest.StreamOptionsType(),
' .Stream = False,
' .FrequencyPenalty = 0,
' .MaxTokens = 4096,
' .PresencePenalty = 0,
' .Temperature = 1,
' .TopP = 0.7,
' .Logprobs = False
'}
'Dim chatRes As ChatResponse = Await doubao.Chat(chatReq)
'Trace.WriteLine(chatRes.Choices.First.Message.Content)
'-----------------
Dim chatReq As New ChatRequest With {
.Messages = New List(Of ChatRequest.MessagesType) From {
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.System,
.Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
},
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.User,
.Content = "你是谁?"
}
},
.Model = China.AiChat.Sdk.ModelEnum.DouBao1_5Pro32k,
.StreamOptions = New ChatRequest.StreamOptionsType(),
.Stream = False,
.FrequencyPenalty = 0,
.MaxTokens = 4096,
.PresencePenalty = 0,
.Temperature = 1,
.TopP = 0.7,
.Logprobs = False
}
'' 多轮对话
If Not String.IsNullOrWhiteSpace(resultMsg.ToString) Then
chatReq.Messages.Add(New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.Assistant,
.Content = resultMsg.ToString
})
End If
Await doubao.ChatStream(chatReq, openedCallBack:=Sub(state As String) ''打开状态
Trace.WriteLine(state)
End Sub,
closedCallBack:=Sub(state) ''关闭状态
Trace.WriteLine(state)
resultMsg.Clear() ''拼接完成则清空,进行下一轮拼接
End Sub,
msgCallback:=Sub(res As ChatResponse) ''接收信息
Dim msg As String = res.Choices.First?.Delta?.Content
resultMsg.Append(msg)
Trace.WriteLine(msg)
End Sub,
errorCallback:=Sub(ex As String) ''异常处理
Trace.WriteLine(ex)
End Sub)
Await Task.CompletedTask
End Function
''' <summary>
''' 月之暗面kimi测试
''' </summary>
<TestMethod()>
Public Async Function MoonshotKimiAiTest() As Task
' api密钥
Dim apikey As String = "sk-6666666666666666666666666666"
' 创建Kimi对象
Dim Kimi As IChinaAiChat = China.AiChat.Sdk.CreateService(AiType.Kimi, apikey)
'' 模型查询
'Dim modelList As Model = Await Kimi.GetModelList()
'Trace.WriteLine(modelList)
'' 余额查询
'Dim ResBalance As Balance = Await Kimi.GetBalance
'Trace.WriteLine(ResBalance)
'' 计算token
'Dim tkreq As New CalculateTokenRequest With {
' .Messages = New List(Of ChatRequest.MessagesType) From {
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.System,
' .Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
' },
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.User,
' .Content = "你是谁?"
' }
' },
' .Model = ModelEnum.MoonShotV1Auto
'}
'Dim calctoekn As CalculateTokenResponse = Await Kimi.CalculateTokenSize(tkreq)
'Trace.WriteLine(calctoekn)
''-----------------
'Dim chatReq As New ChatRequest With {
' .Messages = New List(Of ChatRequest.MessagesType) From {
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.System,
' .Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
' },
' New ChatRequest.MessagesType With {
' .Role = China.AiChat.Sdk.RoleEnum.User,
' .Content = "你是谁?"
' }
' },
' .Model = China.AiChat.Sdk.ModelEnum.MoonShotV1Auto,
' .ResponseFormat = New ChatRequest.ResponseFormatType(),
' .Stream = False,
' .FrequencyPenalty = 0,
' .MaxTokens = 4096,
' .PresencePenalty = 0,
' .Temperature = 0.3,
' .N = 1,
' .TopP = 1,
' .Logprobs = False
'}
'Dim chatRes As ChatResponse = Await Kimi.Chat(chatReq)
'Trace.WriteLine(chatRes.Choices.First.Message.Content)
''-----------------
Dim chatReq As New ChatRequest With {
.Messages = New List(Of ChatRequest.MessagesType) From {
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.System,
.Content = "你是一个Excel办公助手,仅回答办公相关的内容,其他无关内容忽略。"
},
New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.User,
.Content = "你是谁?"
}
},
.Model = China.AiChat.Sdk.ModelEnum.MoonShotV1Auto,
.ResponseFormat = New ChatRequest.ResponseFormatType(),
.Stream = False,
.FrequencyPenalty = 0,
.MaxTokens = 4096,
.PresencePenalty = 0,
.Temperature = 0.3,
.N = 1,
.TopP = 1,
.Logprobs = False
}
'' 多轮对话
If Not String.IsNullOrWhiteSpace(resultMsg.ToString) Then
chatReq.Messages.Add(New ChatRequest.MessagesType With {
.Role = China.AiChat.Sdk.RoleEnum.Assistant,
.Content = resultMsg.ToString
})
End If
Await Kimi.ChatStream(chatReq, openedCallBack:=Sub(state As String) ''打开状态
Trace.WriteLine(state)
End Sub,
closedCallBack:=Sub(state) ''关闭状态
Trace.WriteLine(state)
resultMsg.Clear() ''拼接完成则清空,进行下一轮拼接
End Sub,
msgCallback:=Sub(res As ChatResponse) ''接收信息
Dim msg As String = res.Choices.First?.Delta?.Content
resultMsg.Append(msg)
Trace.WriteLine(msg)
End Sub,
errorCallback:=Sub(ex As String) ''异常处理
Trace.WriteLine(ex)
End Sub)
Await Task.CompletedTask
End Function
End Class
C#.NET
自行根据vb.net代码改一下即可
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.2
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.7.2
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
-
.NETFramework 4.8
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
-
.NETStandard 2.0
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
-
net6.0
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- LaunchDarkly.EventSource (>= 5.2.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
首发