feat: 新增向量嵌入服务支持

新增SiliconFlow向量嵌入服务实现,支持文本向量化功能:
- 新增ITextEmbeddingService接口和SiliconFlowTextEmbeddingService实现
- 新增EmbeddingCreateRequest/Response等向量相关DTO
- 在AiGateWayManager中新增EmbeddingForStatisticsAsync方法
- 在OpenApiService中新增向量生成API接口
- 扩展ModelTypeEnum枚举支持Embedding类型
- 优化ThorChatMessage的Content属性处理逻辑
This commit is contained in:
chenchun
2025-08-11 15:29:24 +08:00
parent bbe5b01872
commit 25eebec8f7
11 changed files with 405 additions and 21 deletions

View File

@@ -0,0 +1,24 @@
using System.Net.Http.Json;
using Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi.Embeddings;
using Yi.Framework.AiHub.Domain.Shared.Dtos;
namespace Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorSiliconFlow.Embeddings;
public sealed class SiliconFlowTextEmbeddingService
: ITextEmbeddingService
{
public async Task<EmbeddingCreateResponse> EmbeddingAsync(
EmbeddingCreateRequest createEmbeddingModel,
AiModelDescribe? options = null,
CancellationToken cancellationToken = default)
{
var response = await HttpClientFactory.GetHttpClient(options.Endpoint).PostJsonAsync(
options?.Endpoint.TrimEnd('/') + "/v1/embeddings",
createEmbeddingModel, options!.ApiKey);
var result =
await response.Content.ReadFromJsonAsync<EmbeddingCreateResponse>(cancellationToken: cancellationToken);
return result;
}
}