-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAiController.cs
More file actions
46 lines (41 loc) · 1.79 KB
/
AiController.cs
File metadata and controls
46 lines (41 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TalentManagementAPI.Application.Interfaces;
namespace TalentManagementAPI.WebApi.Controllers.v1
{
[ApiVersion("1.0")]
[AllowAnonymous]
[Route("api/v{version:apiVersion}/ai")]
public sealed class AiController : BaseApiController
{
private readonly IAiChatService _aiChatService;
private readonly IFeatureManagerSnapshot _featureManager;
public AiController(IAiChatService aiChatService, IFeatureManagerSnapshot featureManager)
{
_aiChatService = aiChatService;
_featureManager = featureManager;
}
/// <summary>
/// Send a message to the AI assistant and receive a reply.
/// </summary>
/// <param name="request">The chat message and optional system prompt.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The AI-generated reply.</returns>
[HttpPost("chat")]
public async Task<IActionResult> Chat([FromBody] AiChatRequest request, CancellationToken cancellationToken)
{
if (!await _featureManager.IsEnabledAsync("AiEnabled"))
{
return Problem(
detail: "AI chat is disabled. Enable FeatureManagement:AiEnabled to use this endpoint.",
title: "AI chat is disabled",
statusCode: StatusCodes.Status503ServiceUnavailable);
}
var reply = await _aiChatService.ChatAsync(request.Message, request.SystemPrompt, cancellationToken);
return Ok(new AiChatResponse(reply));
}
}
public record AiChatRequest(string Message, string? SystemPrompt = null);
public record AiChatResponse(string Reply);
}