Skip to content

Commit

Permalink
Merge pull request #21 from sdcb/feature/chat-span
Browse files Browse the repository at this point in the history
Feature/chat span
  • Loading branch information
sdcb authored Jan 1, 2025
2 parents df75c64 + 8d6cbe0 commit b83b76c
Show file tree
Hide file tree
Showing 115 changed files with 7,941 additions and 5,696 deletions.
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ Chats提供了以下几个镜像:

对于不便使用 Docker 部署的环境,Chats 提供了 8 种操作系统或架构的直接部署选项。可从以下链接获取相应的编译包:

| 平台 | Github下载链接 | 替代下载链接 |
| 平台 | Github下载链接 | 国内下载链接 |
| ---------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| Windows 64位 | [chats-win-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-win-x64.zip) | [chats-win-x64.zip](https://io.starworks.cc:88/chats/latest/chats-win-x64.zip) |
| Linux 64位 | [chats-linux-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-x64.zip) | [chats-linux-x64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-x64.zip) |
| Linux ARM64 | [chats-linux-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-arm64.zip) | [chats-linux-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-arm64.zip) |
| Linux musl x64 | [chats-linux-musl-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-x64.zip) | [chats-linux-musl-x64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-musl-x64.zip) |
| Linux musl ARM64 | [chats-linux-musl-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-arm64.zip) | [chats-linux-musl-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-musl-arm64.zip) |
| macOS ARM64 | [chats-osx-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-arm64.zip) | [chats-osx-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-osx-arm64.zip) |
| macOS x64 | [chats-osx-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-x64.zip) | [chats-osx-x64.zip](https://io.starworks.cc:88/chats/latest/chats-osx-x64.zip) |
| 依赖.NET的通用包 | [chats.zip](https://github.com/sdcb/chats/releases/latest/download/chats.zip) | [chats.zip](https://io.starworks.cc:88/chats/latest/chats.zip) |
| 纯前端文件 | [chats-fe.zip](https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip) | [chats-fe.zip](https://io.starworks.cc:88/chats/latest/chats-fe.zip) |
| Windows 64位 | [chats-win-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-win-x64.zip) | [chats-win-x64.7z](https://io.starworks.cc:88/chats/latest/chats-win-x64.7z) |
| Linux 64位 | [chats-linux-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-x64.zip) | [chats-linux-x64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-x64.7z) |
| Linux ARM64 | [chats-linux-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-arm64.zip) | [chats-linux-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-arm64.7z) |
| Linux musl x64 | [chats-linux-musl-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-x64.zip) | [chats-linux-musl-x64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-musl-x64.7z) |
| Linux musl ARM64 | [chats-linux-musl-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-arm64.zip) | [chats-linux-musl-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-musl-arm64.7z) |
| macOS ARM64 | [chats-osx-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-arm64.zip) | [chats-osx-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-osx-arm64.7z) |
| macOS x64 | [chats-osx-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-x64.zip) | [chats-osx-x64.7z](https://io.starworks.cc:88/chats/latest/chats-osx-x64.7z) |
| 依赖.NET的通用包 | [chats.zip](https://github.com/sdcb/chats/releases/latest/download/chats.zip) | [chats.7z](https://io.starworks.cc:88/chats/latest/chats.7z) |
| 纯前端文件 | [chats-fe.zip](https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip) | [chats-fe.7z](https://io.starworks.cc:88/chats/latest/chats-fe.7z) |

### 版本和下载说明

Expand All @@ -107,7 +107,7 @@ Chats提供了以下几个镜像:
```
- 例如,通过替代下载直接获取最新的 Windows 64-bit 版:
```
https://io.starworks.cc:88/chats/latest/chats-win-x64.zip
https://io.starworks.cc:88/chats/latest/chats-win-x64.7z
```

### 执行文件目录结构和运行说明
Expand Down Expand Up @@ -141,12 +141,16 @@ C:\Users\ZhouJie\Downloads\chats-win-x64>dir

- 对于下载的 `chats.zip`,将需要.NET SDK支持。安装.NET运行时后,使用 `dotnet Chats.BE.dll` 启动程序。

### 支持的大模型
### 支持的大模型服务

- OpenAI OpenAI
- Azure(或兼容OpenAI协议的API,如ollama)
- 通义千问(Dashscope)
- Azure OpenAI
- 腾讯混元(HunYuan)
- 零一万物(01.ai)
- 月之暗面(Moonshot)
- 文心一言(Wenxin Qianfan)
- 智谱清言(Zhipu AI)
- ...
- OpenAI(或兼容OpenAI协议的API,如ollama)
- 文心千帆(Wenxin Qianfan)
- 阿里灵积大模型平台(Aliyun DashScope)
- 讯飞星火(Xunfei Sparkdesk)
- DeepSeek
- x.AI
- Github Models
38 changes: 21 additions & 17 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ For environments where using Docker is inconvenient, Chats provides direct deplo
| Platform | GitHub Download Link | Alternative Download Link |
| --------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| Windows 64-bit | [chats-win-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-win-x64.zip) | [chats-win-x64.zip](https://io.starworks.cc:88/chats/latest/chats-win-x64.zip) |
| Linux 64-bit | [chats-linux-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-x64.zip) | [chats-linux-x64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-x64.zip) |
| Linux ARM64 | [chats-linux-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-arm64.zip) | [chats-linux-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-arm64.zip) |
| Linux musl x64 | [chats-linux-musl-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-x64.zip) | [chats-linux-musl-x64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-musl-x64.zip) |
| Linux musl ARM64 | [chats-linux-musl-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-arm64.zip) | [chats-linux-musl-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-linux-musl-arm64.zip) |
| macOS ARM64 | [chats-osx-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-arm64.zip) | [chats-osx-arm64.zip](https://io.starworks.cc:88/chats/latest/chats-osx-arm64.zip) |
| macOS x64 | [chats-osx-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-x64.zip) | [chats-osx-x64.zip](https://io.starworks.cc:88/chats/latest/chats-osx-x64.zip) |
| Generic package dependent on .NET | [chats.zip](https://github.com/sdcb/chats/releases/latest/download/chats.zip) | [chats.zip](https://io.starworks.cc:88/chats/latest/chats.zip) |
| Pure front-end files | [chats-fe.zip](https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip) | [chats-fe.zip](https://io.starworks.cc:88/chats/latest/chats-fe.zip) |
| Windows 64-bit | [chats-win-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-win-x64.zip) | [chats-win-x64.7z](https://io.starworks.cc:88/chats/latest/chats-win-x64.7z) |
| Linux 64-bit | [chats-linux-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-x64.zip) | [chats-linux-x64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-x64.7z) |
| Linux ARM64 | [chats-linux-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-arm64.zip) | [chats-linux-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-arm64.7z) |
| Linux musl x64 | [chats-linux-musl-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-x64.zip) | [chats-linux-musl-x64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-musl-x64.7z) |
| Linux musl ARM64 | [chats-linux-musl-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-linux-musl-arm64.zip) | [chats-linux-musl-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-linux-musl-arm64.7z) |
| macOS ARM64 | [chats-osx-arm64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-arm64.zip) | [chats-osx-arm64.7z](https://io.starworks.cc:88/chats/latest/chats-osx-arm64.7z) |
| macOS x64 | [chats-osx-x64.zip](https://github.com/sdcb/chats/releases/latest/download/chats-osx-x64.zip) | [chats-osx-x64.7z](https://io.starworks.cc:88/chats/latest/chats-osx-x64.7z) |
| Generic package dependent on .NET | [chats.zip](https://github.com/sdcb/chats/releases/latest/download/chats.zip) | [chats.7z](https://io.starworks.cc:88/chats/latest/chats.7z) |
| Pure front-end files | [chats-fe.zip](https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip) | [chats-fe.7z](https://io.starworks.cc:88/chats/latest/chats-fe.7z) |
### Version and Download Instructions
Expand All @@ -105,7 +105,7 @@ For environments where using Docker is inconvenient, Chats provides direct deplo
```
- For example, to directly download the latest Windows 64-bit version via the alternative download:
```
https://io.starworks.cc:88/chats/latest/chats-win-x64.zip
https://io.starworks.cc:88/chats/latest/chats-win-x64.7z
```
### Executable Directory Structure and Running Instructions
Expand Down Expand Up @@ -141,10 +141,14 @@ C:\Users\ZhouJie\Downloads\chats-win-x64>dir
### Supported LLMs
- OpenAI OpenAI
- Azure(or OpenAI API compatible APIs, like ollama)
- Aliyun Dashscope(通义千问)
- Moonshot(月之暗面)
- Wenxin Qianfan(文心千帆大模型平台)
- Zhipu AI(智谱清言)
- ...
- Azure OpenAI
- Tencent HunYuan
- 01.ai
- Moonshot
- OpenAI (or OpenAI API compatible APIs, like ollama)
- Wenxin Qianfan
- Aliyun DashScope
- Xunfei Sparkdesk
- DeepSeek
- x.AI
- GitHub Models
47 changes: 28 additions & 19 deletions src/BE/Controllers/Admin/AdminMessage/AdminMessageController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Chats.BE.Controllers.Admin.AdminMessage.Dtos;
using Chats.BE.Controllers.Admin.Common;
using Chats.BE.Controllers.Chats.Chats.Dtos;
using Chats.BE.Controllers.Chats.UserChats.Dtos;
using Chats.BE.Controllers.Common.Dtos;
using Chats.BE.DB;
using Chats.BE.DB.Enums;
Expand All @@ -24,27 +25,29 @@ public async Task<ActionResult<PagedResult<AdminChatsDto>>> GetMessages([FromQue
.Where(x => x.User.Role != "admin" || x.UserId == currentUser.Id);
if (!string.IsNullOrEmpty(req.Query))
{
chats = chats.Where(x => x.User.Username == req.Query);
chats = chats.Where(x => x.User.UserName == req.Query);
}

return await PagedResult.FromTempQuery(chats
return await PagedResult.FromQuery(chats
.OrderByDescending(x => x.CreatedAt)
.Select(x => new AdminChatsDtoTemp
.Select(x => new AdminChatsDto
{
Id = x.Id,
Id = idEncryption.EncryptChatId(x.Id),
CreatedAt = x.CreatedAt,
IsDeleted = x.IsDeleted,
IsShared = x.IsShared,
ModelName = x.Model.Name,
Title = x.Title,
UserName = x.User.Username,
//Cost = x.Messages.Select(x => x.Usage).Sum(x => x.InputCost + x.OutputCost)
JsonUserModelConfig = new JsonUserModelConfig()
UserName = x.User.UserName,
Spans = x.ChatSpans.Select(s => new ChatSpanDto
{
Temperature = x.Temperature,
EnableSearch = x.EnableSearch,
},
}), req, x => x.ToDto(), cancellationToken);
SpanId = s.SpanId,
ModelId = s.ModelId,
ModelName = s.Model.Name,
ModelProviderId = s.Model.ModelKey.ModelProviderId,
Temperature = s.Temperature,
EnableSearch = s.EnableSearch,
}).ToArray(),
}), req, cancellationToken);
}

[HttpGet("message-details")]
Expand All @@ -55,19 +58,25 @@ public async Task<ActionResult<AdminMessageRoot>> GetAdminMessage(int chatId,
return await GetAdminMessageInternal(db, chatId, idEncryption, fup, cancellationToken);
}

internal static async Task<ActionResult<AdminMessageRoot>> GetAdminMessageInternal(ChatsDB db, int conversationId,
internal static async Task<ActionResult<AdminMessageRoot>> GetAdminMessageInternal(ChatsDB db, int chatId,
IUrlEncryptionService urlEncryption,
FileUrlProvider fup,
CancellationToken cancellationToken)
{
AdminMessageDtoTemp? adminMessageTemp = await db.Chats
.Where(x => x.Id == conversationId)
.Where(x => x.Id == chatId)
.Select(x => new AdminMessageDtoTemp()
{
Name = x.Title,
ModelName = x.Model.Name,
Temperature = x.Temperature,
DeploymentName = x.Model.DeploymentName,
Spans = x.ChatSpans.Select(s => new ChatSpanDto
{
SpanId = s.SpanId,
ModelId = s.ModelId,
ModelName = s.Model.Name,
ModelProviderId = s.Model.ModelKey.ModelProviderId,
Temperature = s.Temperature,
EnableSearch = s.EnableSearch,
}).ToArray()
})
.SingleOrDefaultAsync(cancellationToken);
if (adminMessageTemp == null) return new NotFoundResult();
Expand All @@ -76,7 +85,7 @@ internal static async Task<ActionResult<AdminMessageRoot>> GetAdminMessageIntern
.Include(x => x.MessageContents).ThenInclude(x => x.MessageContentBlob)
.Include(x => x.MessageContents).ThenInclude(x => x.MessageContentFile).ThenInclude(x => x!.File).ThenInclude(x => x.FileService)
.Include(x => x.MessageContents).ThenInclude(x => x.MessageContentText)
.Where(x => x.ChatId == conversationId)
.Where(x => x.ChatId == chatId)
.Select(x => new AdminMessageItemTemp
{
Id = x.Id,
Expand All @@ -98,7 +107,7 @@ internal static async Task<ActionResult<AdminMessageRoot>> GetAdminMessageIntern
.ToArrayAsync(cancellationToken);

AdminMessageBasicItem[] items = AdminMessageItemTemp.ToDtos(messagesTemp, urlEncryption, fup);
AdminMessageRoot dto = adminMessageTemp.ToDto(items);
AdminMessageRoot dto = adminMessageTemp.Combine(items);

return new OkObjectResult(dto);
}
Expand Down
43 changes: 3 additions & 40 deletions src/BE/Controllers/Admin/AdminMessage/Dtos/AdminChatsDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Chats.BE.DB.Jsons;
using Chats.BE.Controllers.Chats.UserChats.Dtos;
using System.Text.Json.Serialization;

namespace Chats.BE.Controllers.Admin.AdminMessage.Dtos;
Expand All @@ -14,52 +14,15 @@ public record AdminChatsDto
[JsonPropertyName("title")]
public required string Title { get; init; }

[JsonPropertyName("modelName")]
public required string ModelName { get; init; }

[JsonPropertyName("isDeleted")]
public required bool IsDeleted { get; init; }

[JsonPropertyName("isShared")]
public required bool IsShared { get; init; }

[JsonPropertyName("userModelConfig")]
public required JsonUserModelConfig UserModelConfig { get; init; }
[JsonPropertyName("spans")]
public required ChatSpanDto[] Spans { get; init; }

[JsonPropertyName("createdAt")]
public required DateTime CreatedAt { get; init; }
}

public record AdminChatsDtoTemp
{
public required int Id { get; init; }

public required string UserName { get; init; }

public required string Title { get; init; }

public required string ModelName { get; init; }

public required bool IsDeleted { get; init; }

public required bool IsShared { get; init; }

public required JsonUserModelConfig JsonUserModelConfig { get; init; }

public required DateTime CreatedAt { get; init; }

public AdminChatsDto ToDto()
{
return new AdminChatsDto
{
Id = Id.ToString(),
UserName = UserName,
Title = Title,
ModelName = ModelName,
IsDeleted = IsDeleted,
IsShared = IsShared,
UserModelConfig = JsonUserModelConfig,
CreatedAt = CreatedAt
};
}
}
Loading

0 comments on commit b83b76c

Please sign in to comment.