Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/AiChatController.cs
glz bf333cd718 feat: 新增AI聊天服务,重构任务提示词相关逻辑
1.  新增AI聊天服务接口、实现、控制器及相关DTO、配置类
2.  调整JournalPageTaskTypeEnum枚举值修正
3.  合并任务的基础Prompt和自定义Prompt为单个Prompt字段
4.  精简任务输出DTO冗余属性
2026-06-24 15:06:40 +08:00

51 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Enum;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
/// <summary>
/// AI聊天控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class AiChatController : BaseController
{
private readonly IAiChatService _aiChatService;
private readonly ILogger<AiChatController> _logger;
public AiChatController(IAiChatService aiChatService, ILogger<AiChatController> logger)
{
_aiChatService = aiChatService;
_logger = logger;
}
/// <summary>
/// AI聊天根据需求生成提示词
/// </summary>
/// <param name="input">用户需求消息</param>
/// <returns>AI生成的提示词Markdown格式</returns>
[HttpPost]
public async Task<BaseResponse<AiChatOutput>> ChatAsync([FromBody] AiChatInput input)
{
try
{
var result = await _aiChatService.ChatAsync(input);
return Success(result, "AI聊天成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "AI聊天业务异常: {Message}", ex.Message);
return BaseResponse<AiChatOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "AI聊天系统异常参数{Input}", input);
return BaseResponse<AiChatOutput>.Fail("AI聊天失败请稍后重试");
}
}
}