This repository has been archived on 2023-11-16. You can view files and clone it, but cannot push or open issues or pull requests.
GOA/LLMApi/Controllers/LLMController.cs
2023-09-24 12:57:19 +02:00

58 lines
1.6 KiB
C#

using LLMApi.Data.Contracts.ChatGpt3_5;
using LLMApi.Data.Contracts.Game.ChatGpt3_5;
using LLMApi.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace LLMApi.Controllers;
[ApiController]
[Route("[controller]")]
public class LLMController : ControllerBase
{
private readonly ILlmApiService _apiService;
public LLMController(ILlmApiService apiService)
{
_apiService = apiService;
}
// [HttpGet(nameof(AnswerToPrompt))]
// public async Task<ActionResult<Choice>> AnswerToPrompt(string prompt = "Hello!")
// {
// try
// {
// var choices = await _apiService.GetAnswerToPrompt(prompt);
// return Ok(choices);
// }
// catch (Exception ex)
// {
// _logger.LogError(ex, null, Array.Empty<object>());
// return StatusCode(500, ex.ToString());
// }
// }
[HttpGet(nameof(Answer))]
public async Task<ActionResult<AnswerResponse>> Answer(AnswerRequest answerRequest)
{
try
{
System.Console.WriteLine(JsonConvert.SerializeObject(answerRequest));
System.Console.WriteLine(">");
var answerResponse = await _apiService.GetAnswer(answerRequest);
System.Console.WriteLine(JsonConvert.SerializeObject(answerResponse));
System.Console.WriteLine();
System.Console.WriteLine();
return Ok(answerResponse);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return StatusCode(500, ex.ToString());
}
}
}