Zongsoft.Intelligences
0.4.0
dotnet add package Zongsoft.Intelligences --version 0.4.0
NuGet\Install-Package Zongsoft.Intelligences -Version 0.4.0
<PackageReference Include="Zongsoft.Intelligences" Version="0.4.0" />
<PackageVersion Include="Zongsoft.Intelligences" Version="0.4.0" />
<PackageReference Include="Zongsoft.Intelligences" />
paket add Zongsoft.Intelligences --version 0.4.0
#r "nuget: Zongsoft.Intelligences, 0.4.0"
#:package Zongsoft.Intelligences@0.4.0
#addin nuget:?package=Zongsoft.Intelligences&version=0.4.0
#tool nuget:?package=Zongsoft.Intelligences&version=0.4.0
人工智能扩展库
安装 Ollama
在 Windows 11 中确保 WSL 2 和 Podman 安装成功。
确保 Podman 虚拟机已经启动,可通过下列命令进行查验:
podman machine list #查看虚拟机列表 podman machine info #查看虚拟机信息 podman machine start #启动默认虚拟机
💡 提示: Docker 与 Podman 的操作方式基本一致,只需将
podman命令改成docker即可。
在 Podman 中安装 Ollama
根据 Ollama 官方文档 《Ollama is now available as an official Docker image》 的指引,在 PowerShell 中执行下列命令安装 Ollama 镜像。
podman run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
等待下载安装完成后,通过下面命令进行查验 (此时镜像列表为空):
podman exec -it ollama ollama list
安装模型
在 Ollama 官方模型库 (https://ollama.com/search) 中查找需要的大语言模型。
💡 如果只是本地开发测试,推荐使用 阿里千问 (
qwen3:0.6b) 模型,它只有523MB大小,可在无显卡的低配电脑上流畅运行。
podman exec -it ollama ollama pull qwen3:0.6b
等待下载安装完成后,通过下面命令进行查验:
# 查看本地模型库列表 podman exec -it ollama ollama list # 运行 qwen3:0.6b 模型 # 运行成功后自动进入交互模式,可通过 `/bye` 命令退出 podman exec -it ollama ollama run qwen3:0.6b # 查看正在运行的模型列表 podman exec -it ollama ollama ps
运行调试
如果宿主程序中本库(Zongsoft.Intelligences.dll)所在目录中包含一个名为 preludes 的子目录,则当开启一个新的聊天会话时默认会在该目录中查找该助手名字打头的文本文件作为新会话的开场白。具体请参考 ChatSessionPreludeLoader.cs 类的源码。
本扩展库提供了 命令行 和 RESTful API 接口两种方式。
命令行
- 执行 terminal 项目的
deploy.cmd部署命令; - 启动编译后的 terminal 本地宿主程序;
如果 Ollama 没有安装在本机,则需要修改该插件的
Zongsoft.Intelligences.option配置文件中的连接地址。
命令说明
查看AI助手列表
ai.assistant激活指定的AI助手
注意:后续命令皆基于该命令设置的AI助手。
# 设置AI助手配置(注:该命令参数即为配置文件中的连接名) ai.assistant ollama模型命令
# 查看本地模型库列表 ai.assistant.model.list # 查看正在运行的模型列表 ai.assistant.model.list --running # 查看指定的模型信息 ai.assistant.model.info "qwen3:0.6b" # 下载并安装指定的大语言模型 ai.assistant.model.install "qwen3:0.6b" # 删除并卸载指定的大语言模型 ai.assistant.model.uninstall "qwen3:0.6b"会话命令
# 创建一个新的会话 ai.assistant.chat.open # 进入指定的会话 ai.assistant.chat.open 'session|chatroom' # 关闭当前会话 ai.assistant.chat.close # 关闭指定会话 ai.assistant.chat.close 'session|chatroom' # 清空当前会话的历史记录 ai.assistant.chat.clear # 清空指定会话的历史记录 ai.assistant.chat.clear 'session|chatroom' # 查看当前会话的历史纪录 ai.assistant.chat.history # 查看指定会话的历史记录 ai.assistant.chat.history 'session|chatroom'聊天命令
# 对话 ai.assistant.chat "内容" # 对话:结果为纯文本 ai.assistant.chat --format:text "内容" # 对话:结果为异步流 ai.assistant.chat --streaming "内容" # 对话:结果为纯文本的异步流 ai.assistant.chat --streaming --format:text "内容" # 进入交互对话模式 ai.assistant.chat --interactive
RESTful API 接口
获取AI助手列表
GET /ai/assistants获取指定AI助手信息
GET /ai/assistants/{name}获取模型列表
GET /ai/assistants/{name}/models获取模型详情
GET /ai/assistants/{name}/models/{id}获取会话列表
GET /ai/assistants/{name}/chats获取会话详情
GET /ai/assistants/{name}/chats/{id}创建新的会话
POST /ai/assistants/{name}/chats关闭一个会话
DELETE /ai/assistants/{name}/chats/{id}获取指定会话的聊天历史记录
GET /ai/assistants/{name}/chats/{id}/history清空指定会话的聊天历史记录
DELETE /ai/assistants/{name}/chats/{id}/history聊天对话 (无会话历史)
POST /ai/assistants/{name}/chats/chat聊天对话 (有会话历史)
POST /ai/assistants/{name}/chats/{id}/chat
提示:api 项目中的
chat.html文件为调用聊天 API 的范例,它采用 Server-Sent Events 技术实现。
完整 API 请参考 api 项目中的
Zongsoft.Intelligences.Web.http文档。
{name}表示助手名字,譬如:ollama;{id}表示会话编号。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.AI (>= 9.9.1)
- Microsoft.Extensions.AI.Abstractions (>= 9.9.1)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Microsoft.SemanticKernel (>= 1.66.0)
- Microsoft.SemanticKernel.Abstractions (>= 1.66.0)
- Microsoft.SemanticKernel.Core (>= 1.66.0)
- OllamaSharp (>= 5.4.7)
- Zongsoft.Core (>= 7.25.0)
-
net8.0
- Microsoft.Extensions.AI (>= 9.9.1)
- Microsoft.Extensions.AI.Abstractions (>= 9.9.1)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Microsoft.SemanticKernel (>= 1.66.0)
- Microsoft.SemanticKernel.Abstractions (>= 1.66.0)
- Microsoft.SemanticKernel.Core (>= 1.66.0)
- OllamaSharp (>= 5.4.7)
- Zongsoft.Core (>= 7.25.0)
-
net9.0
- Microsoft.Extensions.AI (>= 9.9.1)
- Microsoft.Extensions.AI.Abstractions (>= 9.9.1)
- Microsoft.Extensions.Configuration (>= 9.0.2)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Microsoft.SemanticKernel (>= 1.66.0)
- Microsoft.SemanticKernel.Abstractions (>= 1.66.0)
- Microsoft.SemanticKernel.Core (>= 1.66.0)
- OllamaSharp (>= 5.4.7)
- Zongsoft.Core (>= 7.25.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Zongsoft.Intelligences:
| Package | Downloads |
|---|---|
|
Zongsoft.Intelligences.Web
This is a web class library about artificial intelligence development. |
GitHub repositories
This package is not used by any popular GitHub repositories.