Merge branch 'refs/heads/abp' into digital-collectibles
This commit is contained in:
@@ -23,14 +23,13 @@ namespace Yi.Framework.ChatHub.Application.Services
|
||||
/// <param name="chatContext"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
|
||||
public async Task ChatAsync([FromBody] List<AiChatContextDto> chatContext)
|
||||
[HttpPost("ai-chat/chat/{model}")]
|
||||
public async Task ChatAsync([FromRoute]string model, [FromBody] List<AiChatContextDto> chatContext)
|
||||
{
|
||||
const int maxChar = 10;
|
||||
var contextId = Guid.NewGuid();
|
||||
Queue<string> stringQueue = new Queue<string>();
|
||||
await foreach (var aiResult in _aiManager.ChatAsStreamAsync(chatContext))
|
||||
await foreach (var aiResult in _aiManager.ChatAsStreamAsync(model,chatContext))
|
||||
{
|
||||
stringQueue.Enqueue(aiResult);
|
||||
|
||||
@@ -42,7 +41,7 @@ namespace Yi.Framework.ChatHub.Application.Services
|
||||
var str = stringQueue.Dequeue();
|
||||
currentStr.Append(str);
|
||||
}
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(currentStr.ToString(), CurrentUser.Id!.Value, contextId));
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(currentStr.ToString(), CurrentUser.Id!.Value, contextId),model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +51,7 @@ namespace Yi.Framework.ChatHub.Application.Services
|
||||
var str = stringQueue.Dequeue();
|
||||
currentEndStr.Append(str);
|
||||
}
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(currentEndStr.ToString(), CurrentUser.Id!.Value, contextId));
|
||||
|
||||
//await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(null, CurrentUser.Id!.Value, contextId));
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(currentEndStr.ToString(), CurrentUser.Id!.Value, contextId),model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,19 +24,8 @@ namespace Yi.Framework.ChatHub.Domain.Managers
|
||||
}
|
||||
private OpenAIService OpenAIService { get; }
|
||||
|
||||
public async IAsyncEnumerable<string> ChatAsStreamAsync(List<AiChatContextDto> aiChatContextDtos)
|
||||
public async IAsyncEnumerable<string> ChatAsStreamAsync(string model, List<AiChatContextDto> aiChatContextDtos)
|
||||
{
|
||||
//var temp = "站长正在接入ChatGpt,敬请期待~";
|
||||
|
||||
//for (var i = 0; i < temp.Length; i++)
|
||||
//{
|
||||
// await Task.Delay(200);
|
||||
// yield return temp[i].ToString();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
if (aiChatContextDtos.Count == 0)
|
||||
{
|
||||
yield return null;
|
||||
@@ -56,7 +45,7 @@ namespace Yi.Framework.ChatHub.Domain.Managers
|
||||
var completionResult = OpenAIService.ChatCompletion.CreateCompletionAsStream(new ChatCompletionCreateRequest
|
||||
{
|
||||
Messages = messages,
|
||||
Model = Models.Gpt_4o_mini
|
||||
Model =model
|
||||
});
|
||||
|
||||
HttpStatusCode? error = null;
|
||||
|
||||
@@ -31,7 +31,14 @@ namespace Yi.Framework.ChatHub.Domain.Managers
|
||||
private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService<IRedisClient>();
|
||||
private string CacheKeyPrefix => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpDistributedCacheOptions>>().Value.KeyPrefix;
|
||||
|
||||
public async Task SendMessageAsync(MessageContext context)
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="context">消息内容</param>
|
||||
/// <param name="relStr">关联字符</param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task SendMessageAsync(MessageContext context,string relStr=null)
|
||||
{
|
||||
switch (context.MessageType)
|
||||
{
|
||||
@@ -39,20 +46,20 @@ namespace Yi.Framework.ChatHub.Domain.Managers
|
||||
var userModel = await GetUserAsync(context.ReceiveId.Value);
|
||||
if (userModel is not null)
|
||||
{
|
||||
await _hubContext.Clients.Client(userModel.ClientId).SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType, context);
|
||||
await _hubContext.Clients.Client(userModel.ClientId).SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType,relStr, context);
|
||||
}
|
||||
break;
|
||||
case MessageTypeEnum.Group:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case MessageTypeEnum.All:
|
||||
await _hubContext.Clients.All.SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType, context);
|
||||
await _hubContext.Clients.All.SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType,relStr, context);
|
||||
break;
|
||||
case MessageTypeEnum.Ai:
|
||||
var userModel2 = await GetUserAsync(context.ReceiveId.Value);
|
||||
if (userModel2 is not null)
|
||||
{
|
||||
await _hubContext.Clients.Client(userModel2.ClientId).SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType, context);
|
||||
await _hubContext.Clients.Client(userModel2.ClientId).SendAsync(ChatConst.ClientActionReceiveMsg, context.MessageType,relStr, context);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Yi.Framework.Rbac.Application.Contracts.Dtos.Role
|
||||
{
|
||||
public class UpdateDataScpoceInput
|
||||
public class UpdateDataScopeInput
|
||||
{
|
||||
public Guid RoleId { get; set; }
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
||||
|
||||
private ISqlSugarRepository<UserRoleEntity> _userRoleRepository;
|
||||
|
||||
public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input)
|
||||
public async Task UpdateDataScopeAsync(UpdateDataScopeInput input)
|
||||
{
|
||||
//只有自定义的需要特殊处理
|
||||
if (input.DataScope == DataScopeEnum.CUSTOM)
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DistributedLock.Redis" Version="1.0.3" />
|
||||
<PackageReference Include="Volo.Abp.DistributedLocking" Version="$(AbpVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Caching.FreeRedis\Yi.Framework.Caching.FreeRedis.csproj" />
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Medallion.Threading;
|
||||
using Medallion.Threading.Redis;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StackExchange.Redis;
|
||||
using Volo.Abp.AspNetCore.SignalR;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.DistributedLocking;
|
||||
using Volo.Abp.Domain;
|
||||
using Volo.Abp.Imaging;
|
||||
using Volo.Abp.Modularity;
|
||||
@@ -20,7 +24,8 @@ namespace Yi.Framework.Rbac.Domain
|
||||
typeof(AbpAspNetCoreSignalRModule),
|
||||
typeof(AbpDddDomainModule),
|
||||
typeof(AbpCachingModule),
|
||||
typeof(AbpImagingImageSharpModule)
|
||||
typeof(AbpImagingImageSharpModule),
|
||||
typeof(AbpDistributedLockingModule)
|
||||
)]
|
||||
public class YiFrameworkRbacDomainModule : AbpModule
|
||||
{
|
||||
@@ -36,6 +41,15 @@ namespace Yi.Framework.Rbac.Domain
|
||||
|
||||
//配置阿里云短信
|
||||
Configure<AliyunOptions>(configuration.GetSection(nameof(AliyunOptions)));
|
||||
|
||||
//分布式锁
|
||||
context.Services.AddSingleton<IDistributedLockProvider>(sp =>
|
||||
{
|
||||
var connection = ConnectionMultiplexer
|
||||
.Connect(configuration["Redis:Configuration"]);
|
||||
return new
|
||||
RedisDistributedSynchronizationProvider(connection.GetDatabase());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user