fix: 修复Embedding输入处理逻辑和字段可空性
- 优化Embedding输入类型判断逻辑,支持string和JsonElement数组类型 - 将EncodingFormat字段设置为可空类型,提高兼容性 - 注释知识库场景下的消息统计功能,避免不必要的数据记录
This commit is contained in:
@@ -11,7 +11,7 @@ public sealed class ThorEmbeddingInput
|
|||||||
public object Input { get; set; }
|
public object Input { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("encoding_format")]
|
[JsonPropertyName("encoding_format")]
|
||||||
public string EncodingFormat { get; set; }
|
public string? EncodingFormat { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("dimensions")]
|
[JsonPropertyName("dimensions")]
|
||||||
public int? Dimensions { get; set; }
|
public int? Dimensions { get; set; }
|
||||||
|
|||||||
@@ -360,11 +360,7 @@ public class AiGateWayManager : DomainService
|
|||||||
//dto进行转换,支持多种格式
|
//dto进行转换,支持多种格式
|
||||||
if (input.Input is JsonElement str)
|
if (input.Input is JsonElement str)
|
||||||
{
|
{
|
||||||
if (str.ValueKind == JsonValueKind.String)
|
if (str.ValueKind == JsonValueKind.Array)
|
||||||
{
|
|
||||||
embeddingCreateRequest.Input = str.ToString();
|
|
||||||
}
|
|
||||||
else if (str.ValueKind == JsonValueKind.Array)
|
|
||||||
{
|
{
|
||||||
var inputString = str.EnumerateArray().Select(x => x.ToString()).ToArray();
|
var inputString = str.EnumerateArray().Select(x => x.ToString()).ToArray();
|
||||||
embeddingCreateRequest.InputAsList = inputString.ToList();
|
embeddingCreateRequest.InputAsList = inputString.ToList();
|
||||||
@@ -374,6 +370,10 @@ public class AiGateWayManager : DomainService
|
|||||||
throw new Exception("Input,输入格式错误,非string或Array类型");
|
throw new Exception("Input,输入格式错误,非string或Array类型");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (input.Input is string strInput)
|
||||||
|
{
|
||||||
|
embeddingCreateRequest.Input = strInput;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception("Input,输入格式错误,未找到类型");
|
throw new Exception("Input,输入格式错误,未找到类型");
|
||||||
@@ -398,21 +398,22 @@ public class AiGateWayManager : DomainService
|
|||||||
Usage = usage
|
Usage = usage
|
||||||
});
|
});
|
||||||
|
|
||||||
await _aiMessageManager.CreateUserMessageAsync(userId, sessionId,
|
//知识库暂不使用message统计
|
||||||
new MessageInputDto
|
// await _aiMessageManager.CreateUserMessageAsync(userId, sessionId,
|
||||||
{
|
// new MessageInputDto
|
||||||
Content = string.Empty,
|
// {
|
||||||
ModelId = input.Model,
|
// Content = string.Empty,
|
||||||
TokenUsage = usage,
|
// ModelId = input.Model,
|
||||||
});
|
// TokenUsage = usage,
|
||||||
|
// });
|
||||||
await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId,
|
//
|
||||||
new MessageInputDto
|
// await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId,
|
||||||
{
|
// new MessageInputDto
|
||||||
Content = string.Empty,
|
// {
|
||||||
ModelId = input.Model,
|
// Content = string.Empty,
|
||||||
TokenUsage = usage
|
// ModelId = input.Model,
|
||||||
});
|
// TokenUsage = usage
|
||||||
|
// });
|
||||||
|
|
||||||
await _usageStatisticsManager.SetUsageAsync(userId, input.Model, usage);
|
await _usageStatisticsManager.SetUsageAsync(userId, input.Model, usage);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user