Ohh.ChatAi.TotalApi
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Ohh.ChatAi.TotalApi --version 1.0.0
NuGet\Install-Package Ohh.ChatAi.TotalApi -Version 1.0.0
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="Ohh.ChatAi.TotalApi" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ohh.ChatAi.TotalApi --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ohh.ChatAi.TotalApi, 1.0.0"
#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 Ohh.ChatAi.TotalApi as a Cake Addin #addin nuget:?package=Ohh.ChatAi.TotalApi&version=1.0.0 // Install Ohh.ChatAi.TotalApi as a Cake Tool #tool nuget:?package=Ohh.ChatAi.TotalApi&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Ohh.ChatAi.TotalApi国内AI-API集大成者
公众号:办公魔盒
博客:https://bgmh.work
微信:vbee_club
简介
预计会集成国内大部分的chatAI聊天大模型,包括Moonshot-Kimi,文心一言,通义千问,DeepSeek,腾讯混元,智谱清言等
集成情况
目前已集成Moonshot-Kimi模型
框架支持
框架 | 版本 |
---|---|
.NET Framework | >=net461 |
.NET | >=net5.0 |
.NET Core | >=netcoreapp2.0 |
.NET Standard | >=netstandard2.0 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | >=tizen40 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
1.2024-07-01 已集成Kimi大模型
1.1.支持查询模型列表API
GetModelsListAsync
2.2.支持计算当前请求token数据
CalcTokenCountAsync
3.3.普通聊天和流式聊天示例
vb.net示例
Imports System.IO
Imports System.Reflection
Imports System.Runtime.Remoting.Messaging
Imports Ohh.ChatAi.TotalApi.MoonshotKimi
Imports Ohh.ChatAi.TotalApi.MoonshotKimi.Models
Imports Ohh.ChatAi.TotalApi.MoonshotKimi.Models.Consts
Public Class Form1
''' <summary>
''' kimi对象
''' </summary>
Private _kimi As MoonshotClient
Public Sub New()
InitializeComponent()
''------------------
_kimi = New MoonshotClient("sk-xxxxxxxxxxxxxx")
End Sub
Private Async Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Try
richTextBox1.Clear()
''------
Dim chatReq As New ChatRequest With
{
.model = ChatModels.MoonshotV1By8K,
.messages = New List(Of MessagesItem) From {
New MessagesItem With {.role = ChatRoles.System, .content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手..."},
New MessagesItem With {.role = ChatRoles.User, .content = textBox1.Text}
},
.stream = True
}
'' 订阅事件
RemoveHandler _kimi.MessageReceivedEventHandler, AddressOf OnMessageReceived
AddHandler _kimi.MessageReceivedEventHandler, AddressOf OnMessageReceived
'' 开始任务
Await _kimi.ChatStreamAsync(chatReq)
Catch ex As Exception
Console.WriteLine("流式聊天失败:" + ex.Message)
End Try
End Sub
''' <summary>
''' 订阅SSE事件
''' </summary>
''' <param name="s"></param>
''' <param name="m"></param>
Sub OnMessageReceived(s As Object, m As ChatResponse)
''Console.WriteLine("聊天内容:" + ee);
Invoke(Sub()
Dim msg As String = m.choices?.FirstOrDefault()?.delta.content
If Not String.IsNullOrWhiteSpace(msg) Then richTextBox1.AppendText(msg)
End Sub)
End Sub
Private Async Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
Try
Dim chatReq As New ChatRequest With
{
.model = ChatModels.MoonshotV1By8K,
.messages = New List(Of MessagesItem) From {
New MessagesItem With {.role = ChatRoles.System, .content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手..."},
New MessagesItem With {.role = ChatRoles.User, .content = textBox1.Text}
}
}
Dim chatRes As ChatResponse = Await _kimi.ChatAsync(chatReq)
Console.WriteLine("聊天内容:" & chatRes.choices?.FirstOrDefault()?.message.content)
richTextBox1.Text = chatRes.choices?.FirstOrDefault()?.message.content
Catch ex As Exception
Console.WriteLine("聊天失败:" & ex.Message)
End Try
End Sub
End Class
c# 示例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ohh.ChatAi.TotalApi.MoonshotKimi;
using Ohh.ChatAi.TotalApi.MoonshotKimi.Models;
using Ohh.ChatAi.TotalApi.MoonshotKimi.Models.Consts;
using System.Windows.Forms;
namespace Ohh.ChatAi.TotalApi.CSharp.Example
{
public partial class Form1 : Form
{
/// <summary>
/// kimi对象
/// </summary>
private MoonshotClient _kimi;
public Form1()
{
InitializeComponent();
//---------
_kimi = new MoonshotClient("sk-xxxxxxxxxxxxxxx");
}
private async void button1_Click(object sender, EventArgs e)
{
try
{
richTextBox1.Clear();
//------
var chatReq = new ChatRequest
{
model = ChatModels.MoonshotV1By8K,
messages = new List<MessagesItem> {
new MessagesItem { role = ChatRoles.System, content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手..." },
new MessagesItem { role = ChatRoles.User, content = textBox1.Text }
},
stream = true
};
// 订阅事件
_kimi.MessageReceivedEventHandler -= OnMessageReceived;
_kimi.MessageReceivedEventHandler += OnMessageReceived;
// 开始任务
await _kimi.ChatStreamAsync(chatReq);
// 局部函数,订阅SSE事件
void OnMessageReceived(object s, ChatResponse m)
{
//Console.WriteLine("聊天内容:" + ee);
Invoke(new Action(() =>
{
var msg = m.choices?.FirstOrDefault()?.delta.content;
if (msg != null) richTextBox1.AppendText(msg);
}));
}
}
catch (Exception ex)
{
Console.WriteLine("流式聊天失败:" + ex.Message);
}
}
private async void button2_Click(object sender, EventArgs e)
{
try
{
var chatReq = new ChatRequest
{
model = ChatModels.MoonshotV1By8K,
messages = new List<MessagesItem> {
new MessagesItem { role = ChatRoles.System, content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手..." },
new MessagesItem { role = ChatRoles.User, content = textBox1.Text }
}
};
var chatRes = await _kimi.ChatAsync(chatReq);
Console.WriteLine("聊天内容:" + chatRes.choices?.FirstOrDefault()?.message.content);
richTextBox1.Text = chatRes.choices?.FirstOrDefault()?.message.content;
}
catch (Exception ex)
{
Console.WriteLine("聊天失败:" + ex.Message);
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.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 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. 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.
-
.NETStandard 2.0
- LaunchDarkly.EventSource (>= 5.1.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.
V1.0.0 优先支持Kimi MoonshotAI