Skip to content

Commit

Permalink
Merge branch 'feature/chat-span' of private:sdcb/chats into feature/c…
Browse files Browse the repository at this point in the history
…hat-span
  • Loading branch information
greywen committed Dec 20, 2024
2 parents e3b5564 + 02e9ae8 commit 543e8b7
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 183 deletions.
72 changes: 38 additions & 34 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ jobs:
name: ${{ matrix.asset }}
path: ${{ matrix.asset }}

- name: Compress artifacts into ZIP
- name: Compress artifacts into 7z
run: |
zip -r ${{ matrix.asset }}.zip ${{ matrix.asset }}
7z a ${{ matrix.asset }}.7z ${{ matrix.asset }}
shell: bash

- name: Configure MINIO Credentials
Expand All @@ -79,7 +79,7 @@ jobs:
- name: Upload to Minio
run: |
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.asset }}.zip s3://chats/r${{ github.run_number }}/${{ matrix.asset }}.zip
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.asset }}.7z s3://chats/r${{ github.run_number }}/${{ matrix.asset }}.7z
build-primary-container:
needs: build-fe
Expand Down Expand Up @@ -203,19 +203,19 @@ jobs:
include:
- id: chats
- id: chats-win-x64
args: -r win-x64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r win-x64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-linux-x64
args: -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r linux-x64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-linux-arm64
args: -r linux-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r linux-arm64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-linux-musl-x64
args: -r linux-musl-x64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r linux-musl-x64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-linux-musl-arm64
args: -r linux-musl-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r linux-musl-arm64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-osx-arm64
args: -r osx-arm64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r osx-arm64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true
- id: chats-osx-x64
args: -r osx-x64 --self-contained true /p:PublishSingleFile=true /p:PublishReadyToRun=true /p:EnableCompressionInSingleFile=true
args: -r osx-x64 --self-contained true /p:PublishReadyToRun=true /p:PublishSingleFile=true

runs-on: ubuntu-latest
steps:
Expand All @@ -238,9 +238,9 @@ jobs:
name: ${{ matrix.id }}
path: ./Publish

- name: Compress artifacts into ZIP
- name: Compress artifacts into 7z
run: |
zip -r ${{ matrix.id }}.zip ./Publish
7z a ${{ matrix.id }}.7z ./Publish
- name: Configure MINIO Credentials
run: |
Expand All @@ -250,7 +250,7 @@ jobs:
- name: Upload to Minio
run: |
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.id }}.zip s3://chats/r${{ github.run_number }}/${{ matrix.id }}.zip
aws --endpoint-url ${{ vars.MINIO_URL }} s3 cp ${{ matrix.id }}.7z s3://chats/r${{ github.run_number }}/${{ matrix.id }}.7z
create-release:
if: github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -303,20 +303,20 @@ jobs:
| Latest | ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_NAMESPACE }}/chats:latest |

### Alternative binaries download links that may faster than GitHub(for China users)
| Artifact | Download Link |
| -------------------------- | -------------------------------------------------------------------------------- |
| chats-win-x64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-win-x64.zip |
| chats-linux-x64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-x64.zip |
| chats-linux-arm64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-arm64.zip |
| chats-linux-musl-x64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-musl-x64.zip |
| chats-linux-musl-arm64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-musl-arm64.zip |
| chats-osx-arm64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-osx-arm64.zip |
| chats-osx-x64.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-osx-x64.zip |
| chats-fe.zip | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-fe.zip |
| chats | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats |
| Artifact | Download Link |
| ------------------------- | ------------------------------------------------------------------------------- |
| chats-win-x64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-win-x64.7z |
| chats-linux-x64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-x64.7z |
| chats-linux-arm64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-arm64.7z |
| chats-linux-musl-x64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-musl-x64.7z |
| chats-linux-musl-arm64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-linux-musl-arm64.7z |
| chats-osx-arm64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-osx-arm64.7z |
| chats-osx-x64.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-osx-x64.7z |
| chats-fe.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats-fe.7z |
| chats.7z | ${{ vars.MINIO_URL }}/chats/r${{ github.run_number }}/chats.7z |

**NOTE**:
Replace \`r${{ github.run_number }}\` with \`latest\` in the download link to get the latest version, for example: \`${{ vars.MINIO_URL }}/chats/latest/chats-win-x64.zip\`
Replace \`r${{ github.run_number }}\` with \`latest\` in the download link to get the latest version, for example: \`${{ vars.MINIO_URL }}/chats/latest/chats-win-x64.7z\`
`,
draft: false,
prerelease: false,
Expand Down Expand Up @@ -348,8 +348,9 @@ jobs:
name: ${{ matrix.asset }}
path: ${{ matrix.asset }}
- name: Compress artifacts into ZIP
- name: Compress artifacts
run: |
7z a ${{ matrix.asset }}.7z ${{ matrix.asset }}
zip -r ${{ matrix.asset }}.zip ${{ matrix.asset }}
shell: bash
Expand All @@ -358,17 +359,20 @@ jobs:
with:
script: |
const fs = require('fs');
const assetPath = './${{ matrix.asset }}.zip';
const assetNames = [ '${{ matrix.asset }}.7z', '${{ matrix.asset }}.zip' ];
const releaseId = "${{ needs.create-release.outputs.release_id }}";
const asset = fs.readFileSync(assetPath);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: '${{ matrix.asset }}.zip',
data: asset,
const promises = assetNames.map(assetName => {
const asset = fs.readFileSync('./' + assetName);
return github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: assetName,
data: asset,
});
});
await Promise.all(promises);
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 0 additions & 2 deletions src/BE/Controllers/Chats/Chats/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Npgsql.Internal;
using OpenAI.Chat;
using Sdcb.DashScope;
using System;
using System.ClientModel;
using System.Diagnostics;
using System.Text.Json;
Expand Down
6 changes: 0 additions & 6 deletions src/BE/Controllers/Chats/Chats/Dtos/ChatRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ namespace Chats.BE.Controllers.Chats.Chats.Dtos;

public record ChatRequest
{
[JsonPropertyName("modelId")]
public required short ModelId { get; init; }

[JsonPropertyName("chatId")]
public required string EncryptedChatId { get; init; }

Expand All @@ -28,7 +25,6 @@ public DecryptedChatRequest Decrypt(IUrlEncryptionService idEncryption)
{
return new DecryptedChatRequest
{
ModelId = ModelId,
ChatId = idEncryption.DecryptChatId(EncryptedChatId),
Spans = Spans,
MessageId = EncryptedMessageId == null ? null : idEncryption.DecryptMessageId(EncryptedMessageId),
Expand All @@ -39,8 +35,6 @@ public DecryptedChatRequest Decrypt(IUrlEncryptionService idEncryption)

public record DecryptedChatRequest
{
public required short ModelId { get; init; }

public required int ChatId { get; init; }

public required ChatSpanRequest[] Spans { get; init; }
Expand Down
6 changes: 3 additions & 3 deletions src/BE/Controllers/Chats/Messages/Dtos/MessageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract record MessageDto
public required string? ParentId { get; init; }

[JsonPropertyName("role")]
public required string Role { get; init; }
public required DBChatRole Role { get; init; }

[JsonPropertyName("content")]
public required MessageContentResponse Content { get; init; }
Expand Down Expand Up @@ -155,7 +155,7 @@ public MessageDto ToDto(IUrlEncryptionService urlEncryption, FileUrlProvider fup
{
Id = urlEncryption.EncryptMessageId(Id),
ParentId = ParentId != null ? urlEncryption.EncryptMessageId(ParentId.Value) : null,
Role = Role.ToString().ToLowerInvariant(),
Role = Role,
Content = MessageContentResponse.FromSegments(Content, fup),
CreatedAt = CreatedAt,
SpanId = SpanId,
Expand All @@ -167,7 +167,7 @@ public MessageDto ToDto(IUrlEncryptionService urlEncryption, FileUrlProvider fup
{
Id = urlEncryption.EncryptMessageId(Id),
ParentId = ParentId != null ? urlEncryption.EncryptMessageId(ParentId.Value) : null,
Role = Role.ToString().ToLowerInvariant(),
Role = Role,
Content = MessageContentResponse.FromSegments(Content, fup),
CreatedAt = CreatedAt,
SpanId = SpanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Text.Json.Nodes;
using Chats.BE.Controllers.OpenAICompatible.Dtos;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;

namespace Chats.BE.Controllers.OpenAICompatible;

Expand All @@ -21,7 +22,7 @@ public partial class OpenAICompatibleController(ChatsDB db, CurrentApiKey curren
[HttpPost("chat/completions")]
public async Task<ActionResult> ChatCompletion([FromBody] JsonObject json, [FromServices] ClientInfoManager clientInfoManager, CancellationToken cancellationToken)
{
InChatContext icc = new();
InChatContext icc = new(Stopwatch.GetTimestamp());
CcoWrapper cco = new(json);
if (!cco.SeemsValid())
{
Expand Down
Loading

0 comments on commit 543e8b7

Please sign in to comment.