74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using FutureMailAPI.Services;
|
||
|
|
using FutureMailAPI.DTOs;
|
||
|
|
|
||
|
|
namespace FutureMailAPI.Controllers
|
||
|
|
{
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/v1/ai")]
|
||
|
|
[Authorize]
|
||
|
|
public class AIAssistantController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly IAIAssistantService _aiAssistantService;
|
||
|
|
|
||
|
|
public AIAssistantController(IAIAssistantService aiAssistantService)
|
||
|
|
{
|
||
|
|
_aiAssistantService = aiAssistantService;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("writing-assistant")]
|
||
|
|
public async Task<ActionResult<ApiResponse<WritingAssistantResponseDto>>> GetWritingAssistance([FromBody] WritingAssistantRequestDto request)
|
||
|
|
{
|
||
|
|
if (!ModelState.IsValid)
|
||
|
|
{
|
||
|
|
return BadRequest(ApiResponse<WritingAssistantResponseDto>.ErrorResult("输入数据无效"));
|
||
|
|
}
|
||
|
|
|
||
|
|
var result = await _aiAssistantService.GetWritingAssistanceAsync(request);
|
||
|
|
|
||
|
|
if (!result.Success)
|
||
|
|
{
|
||
|
|
return BadRequest(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Ok(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("sentiment-analysis")]
|
||
|
|
public async Task<ActionResult<ApiResponse<SentimentAnalysisResponseDto>>> AnalyzeSentiment([FromBody] SentimentAnalysisRequestDto request)
|
||
|
|
{
|
||
|
|
if (!ModelState.IsValid)
|
||
|
|
{
|
||
|
|
return BadRequest(ApiResponse<SentimentAnalysisResponseDto>.ErrorResult("输入数据无效"));
|
||
|
|
}
|
||
|
|
|
||
|
|
var result = await _aiAssistantService.AnalyzeSentimentAsync(request);
|
||
|
|
|
||
|
|
if (!result.Success)
|
||
|
|
{
|
||
|
|
return BadRequest(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Ok(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("future-prediction")]
|
||
|
|
public async Task<ActionResult<ApiResponse<FuturePredictionResponseDto>>> PredictFuture([FromBody] FuturePredictionRequestDto request)
|
||
|
|
{
|
||
|
|
if (!ModelState.IsValid)
|
||
|
|
{
|
||
|
|
return BadRequest(ApiResponse<FuturePredictionResponseDto>.ErrorResult("输入数据无效"));
|
||
|
|
}
|
||
|
|
|
||
|
|
var result = await _aiAssistantService.PredictFutureAsync(request);
|
||
|
|
|
||
|
|
if (!result.Success)
|
||
|
|
{
|
||
|
|
return BadRequest(result);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Ok(result);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|