You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChatController.cs 1.1 kB

2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. using LLama.Common;
  2. using LLama.WebAPI.Models;
  3. using LLama.WebAPI.Services;
  4. using Microsoft.AspNetCore.Mvc;
  5. using System;
  6. namespace LLama.WebAPI.Controllers
  7. {
  8. [ApiController]
  9. [Route("[controller]")]
  10. public class ChatController : ControllerBase
  11. {
  12. private readonly ILogger<ChatController> _logger;
  13. public ChatController(ILogger<ChatController> logger)
  14. {
  15. _logger = logger;
  16. }
  17. [HttpPost("Send")]
  18. public string SendMessage([FromBody] SendMessageInput input, [FromServices] StatefulChatService _service)
  19. {
  20. return _service.Send(input);
  21. }
  22. [HttpPost("History")]
  23. public async Task<string> SendHistory([FromBody] HistoryInput input, [FromServices] StatelessChatService _service)
  24. {
  25. var history = new ChatHistory();
  26. var messages = input.Messages.Select(m => new ChatHistory.Message(Enum.Parse<AuthorRole>(m.Role), m.Content));
  27. history.Messages.AddRange(messages);
  28. return await _service.SendAsync(history);
  29. }
  30. }
  31. }