feat: 完成图片模型单独扣费
This commit is contained in:
@@ -86,7 +86,8 @@ public class AiGateWayManager : DomainService
|
||||
AppExtraUrl = app.ExtraUrl,
|
||||
ModelExtraInfo = model.ExtraInfo,
|
||||
Multiplier = model.Multiplier,
|
||||
IsPremium = model.IsPremium
|
||||
IsPremium = model.IsPremium,
|
||||
ModelType = model.ModelType
|
||||
})
|
||||
.FirstAsync();
|
||||
if (aiModelDescribe is null)
|
||||
@@ -871,7 +872,20 @@ public class AiGateWayManager : DomainService
|
||||
var data = await chatService.GenerateContentAsync(modelDescribe, request, cancellationToken);
|
||||
|
||||
var tokenUsage = GeminiGenerateContentAcquirer.GetUsage(data);
|
||||
tokenUsage.SetSupplementalMultiplier(modelDescribe.Multiplier);
|
||||
//如果是图片模型,单独扣费
|
||||
if (modelDescribe.ModelType == ModelTypeEnum.Image)
|
||||
{
|
||||
tokenUsage = new ThorUsageResponse
|
||||
{
|
||||
InputTokens = (int)modelDescribe.Multiplier,
|
||||
OutputTokens = (int)modelDescribe.Multiplier,
|
||||
TotalTokens = (int)modelDescribe.Multiplier
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenUsage.SetSupplementalMultiplier(modelDescribe.Multiplier);
|
||||
}
|
||||
|
||||
if (userId is not null)
|
||||
{
|
||||
@@ -944,7 +958,20 @@ public class AiGateWayManager : DomainService
|
||||
if (responseResult!.Value.GetPath("candidates", 0, "finishReason").GetString() == "STOP")
|
||||
{
|
||||
tokenUsage = GeminiGenerateContentAcquirer.GetUsage(responseResult!.Value);
|
||||
tokenUsage.SetSupplementalMultiplier(modelDescribe.Multiplier);
|
||||
//如果是图片模型,单独扣费
|
||||
if (modelDescribe.ModelType == ModelTypeEnum.Image)
|
||||
{
|
||||
tokenUsage = new ThorUsageResponse
|
||||
{
|
||||
InputTokens = (int)modelDescribe.Multiplier,
|
||||
OutputTokens = (int)modelDescribe.Multiplier,
|
||||
TotalTokens = (int)modelDescribe.Multiplier
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenUsage.SetSupplementalMultiplier(modelDescribe.Multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
await response.WriteAsync($"data: {JsonSerializer.Serialize(responseResult)}\n\n", Encoding.UTF8,
|
||||
@@ -1019,6 +1046,10 @@ public class AiGateWayManager : DomainService
|
||||
|
||||
//解析json,获取base64字符串
|
||||
var imagePrefixBase64 = GeminiGenerateContentAcquirer.GetImagePrefixBase64(data);
|
||||
if (string.IsNullOrWhiteSpace(imagePrefixBase64))
|
||||
{
|
||||
throw new UserFriendlyException("大模型没有返回图片,请调整提示词或稍后再试");
|
||||
}
|
||||
|
||||
//远程调用上传接口,将base64转换为URL
|
||||
var httpClient = LazyServiceProvider.LazyGetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
|
||||
Reference in New Issue
Block a user