feat:聊天新增ai
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.ChatHub.Application.Dtos
|
||||
{
|
||||
public class AiChatContextDto
|
||||
{
|
||||
public AnswererTypeEnum AnswererType { get; set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
|
||||
public int Number { get; set; }
|
||||
}
|
||||
|
||||
public enum AnswererTypeEnum
|
||||
{
|
||||
Ai,
|
||||
User
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Yi.Framework.ChatHub.Domain.Managers;
|
||||
using Yi.Framework.ChatHub.Domain.Shared.Dtos;
|
||||
using Yi.Framework.ChatHub.Domain.Shared.Model;
|
||||
using Yi.Framework.ChatHub.Domain.SignalRHubs;
|
||||
|
||||
namespace Yi.Framework.ChatHub.Application.Services
|
||||
{
|
||||
@@ -19,14 +14,24 @@ namespace Yi.Framework.ChatHub.Application.Services
|
||||
private readonly UserMessageManager _userMessageManager;
|
||||
public AiChatService(AiManager aiManager, UserMessageManager userMessageManager) { _aiManager = aiManager; _userMessageManager = userMessageManager; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ai聊天
|
||||
/// </summary>
|
||||
/// <param name="chatContext"></param>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task ChatAsync()
|
||||
|
||||
public async Task ChatAsync([FromBody] List<AiChatContextDto> chatContext)
|
||||
{
|
||||
await foreach (var aiResult in _aiManager.ChatAsStreamAsync())
|
||||
var contextId = Guid.NewGuid();
|
||||
await foreach (var aiResult in _aiManager.ChatAsStreamAsync(chatContext))
|
||||
{
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(aiResult, CurrentUser.Id!.Value));
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(aiResult, CurrentUser.Id!.Value, contextId));
|
||||
}
|
||||
|
||||
await _userMessageManager.SendMessageAsync(MessageContext.CreateAi(null, CurrentUser.Id!.Value, contextId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user