fix: 修复Embedding输入处理逻辑和字段可空性

- 优化Embedding输入类型判断逻辑,支持string和JsonElement数组类型
- 将EncodingFormat字段设置为可空类型,提高兼容性
- 注释知识库场景下的消息统计功能,避免不必要的数据记录
This commit is contained in:
chenchun
2025-08-11 18:05:33 +08:00
parent cfde73d13a
commit 7b0e4fcc73
2 changed files with 22 additions and 21 deletions

View File

@@ -11,7 +11,7 @@ public sealed class ThorEmbeddingInput
public object Input { get; set; }
[JsonPropertyName("encoding_format")]
public string EncodingFormat { get; set; }
public string? EncodingFormat { get; set; }
[JsonPropertyName("dimensions")]
public int? Dimensions { get; set; }

View File

@@ -360,11 +360,7 @@ public class AiGateWayManager : DomainService
//dto进行转换支持多种格式
if (input.Input is JsonElement str)
{
if (str.ValueKind == JsonValueKind.String)
{
embeddingCreateRequest.Input = str.ToString();
}
else if (str.ValueKind == JsonValueKind.Array)
if (str.ValueKind == JsonValueKind.Array)
{
var inputString = str.EnumerateArray().Select(x => x.ToString()).ToArray();
embeddingCreateRequest.InputAsList = inputString.ToList();
@@ -374,6 +370,10 @@ public class AiGateWayManager : DomainService
throw new Exception("Input输入格式错误非string或Array类型");
}
}
else if (input.Input is string strInput)
{
embeddingCreateRequest.Input = strInput;
}
else
{
throw new Exception("Input输入格式错误未找到类型");
@@ -398,21 +398,22 @@ public class AiGateWayManager : DomainService
Usage = usage
});
await _aiMessageManager.CreateUserMessageAsync(userId, sessionId,
new MessageInputDto
{
Content = string.Empty,
ModelId = input.Model,
TokenUsage = usage,
});
await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId,
new MessageInputDto
{
Content = string.Empty,
ModelId = input.Model,
TokenUsage = usage
});
//知识库暂不使用message统计
// await _aiMessageManager.CreateUserMessageAsync(userId, sessionId,
// new MessageInputDto
// {
// Content = string.Empty,
// ModelId = input.Model,
// TokenUsage = usage,
// });
//
// await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId,
// new MessageInputDto
// {
// Content = string.Empty,
// ModelId = input.Model,
// TokenUsage = usage
// });
await _usageStatisticsManager.SetUsageAsync(userId, input.Model, usage);
}