Merge remote-tracking branch 'origin/ai-hub' into ai-hub
This commit is contained in:
@@ -64,6 +64,13 @@ public class ImageGenerationJob : AsyncBackgroundJob<ImageGenerationJobArgs>, IT
|
||||
{
|
||||
contents = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
role = "user", parts = new List<object>
|
||||
{
|
||||
new { text = "我只要图片,直接生成图片,不要询问我" }
|
||||
}
|
||||
},
|
||||
new { role = "user", parts }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -264,7 +264,7 @@ public class AiImageService : ApplicationService
|
||||
ErrorInfo = x.ErrorInfo,
|
||||
UserName = x.UserName,
|
||||
UserId = x.UserId,
|
||||
IsAnonymous =x.IsAnonymous
|
||||
IsAnonymous = x.IsAnonymous
|
||||
})
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
|
||||
@@ -272,6 +272,17 @@ public class AiImageService : ApplicationService
|
||||
return new PagedResult<ImageTaskOutput>(total, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除个人图片
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
[HttpDelete("ai-image/my-tasks")]
|
||||
public async Task DeleteMyTaskAsync([FromBody] List<Guid> ids)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
await _imageTaskRepository.DeleteAsync(x => ids.Contains(x.Id) && x.UserId == userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询图片广场(已发布的图片)
|
||||
/// </summary>
|
||||
@@ -285,8 +296,9 @@ public class AiImageService : ApplicationService
|
||||
.Where(x => x.TaskStatus == TaskStatusEnum.Success)
|
||||
.WhereIF(input.TaskStatus is not null, x => x.TaskStatus == input.TaskStatus)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Prompt), x => x.Prompt.Contains(input.Prompt))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Categories), x => SqlFunc.JsonLike(x.Categories, input.Categories))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName),x=>x.UserName.Contains(input.UserName) )
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Categories),
|
||||
x => SqlFunc.JsonLike(x.Categories, input.Categories))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), x => x.UserName.Contains(input.UserName))
|
||||
.WhereIF(input.StartTime is not null && input.EndTime is not null,
|
||||
x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
@@ -303,9 +315,9 @@ public class AiImageService : ApplicationService
|
||||
ErrorInfo = null,
|
||||
UserName = x.UserName,
|
||||
UserId = x.UserId,
|
||||
|
||||
})
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); ;
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
;
|
||||
|
||||
|
||||
output.ForEach(x =>
|
||||
@@ -316,7 +328,7 @@ public class AiImageService : ApplicationService
|
||||
x.UserId = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return new PagedResult<ImageTaskOutput>(total, output);
|
||||
}
|
||||
|
||||
@@ -345,7 +357,7 @@ public class AiImageService : ApplicationService
|
||||
}
|
||||
|
||||
//设置发布
|
||||
task.SetPublish(input.IsAnonymous,input.Categories);
|
||||
task.SetPublish(input.IsAnonymous, input.Categories);
|
||||
await _imageTaskRepository.UpdateAsync(task);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||
using Yi.Framework.AiHub.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos;
|
||||
|
||||
public class AiModelDescribe
|
||||
{
|
||||
@@ -66,4 +68,9 @@ public class AiModelDescribe
|
||||
/// 是否为尊享模型
|
||||
/// </summary>
|
||||
public bool IsPremium { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模型类型(聊天/图片等)
|
||||
/// </summary>
|
||||
public ModelTypeEnum ModelType { get; set; }
|
||||
}
|
||||
@@ -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