2023-09-23 15:33:16 +02:00
|
|
|
using LLMApi.Data.Contracts.ChatGpt3_5;
|
|
|
|
using LLMApi.Data.Contracts.Game.ChatGpt3_5;
|
2023-09-23 11:21:46 +02:00
|
|
|
using LLMApi.Services;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-09-24 12:57:19 +02:00
|
|
|
using Newtonsoft.Json;
|
2023-09-23 11:21:46 +02:00
|
|
|
|
|
|
|
namespace LLMApi.Controllers;
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
[Route("[controller]")]
|
|
|
|
public class LLMController : ControllerBase
|
|
|
|
{
|
|
|
|
private readonly ILlmApiService _apiService;
|
|
|
|
|
2023-09-24 12:57:19 +02:00
|
|
|
public LLMController(ILlmApiService apiService)
|
2023-09-23 11:21:46 +02:00
|
|
|
{
|
|
|
|
_apiService = apiService;
|
|
|
|
}
|
|
|
|
|
2023-09-23 15:33:16 +02:00
|
|
|
// [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)
|
2023-09-23 11:21:46 +02:00
|
|
|
{
|
2023-09-23 15:33:16 +02:00
|
|
|
try
|
|
|
|
{
|
2023-09-24 12:57:19 +02:00
|
|
|
System.Console.WriteLine(JsonConvert.SerializeObject(answerRequest));
|
|
|
|
System.Console.WriteLine(">");
|
2023-09-23 11:21:46 +02:00
|
|
|
|
2023-09-24 12:57:19 +02:00
|
|
|
var answerResponse = await _apiService.GetAnswer(answerRequest);
|
|
|
|
|
|
|
|
System.Console.WriteLine(JsonConvert.SerializeObject(answerResponse));
|
|
|
|
System.Console.WriteLine();
|
|
|
|
System.Console.WriteLine();
|
|
|
|
|
|
|
|
return Ok(answerResponse);
|
2023-09-23 15:33:16 +02:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2023-09-24 12:57:19 +02:00
|
|
|
Console.WriteLine(ex.ToString());
|
2023-09-23 15:33:16 +02:00
|
|
|
return StatusCode(500, ex.ToString());
|
|
|
|
}
|
2023-09-23 11:21:46 +02:00
|
|
|
}
|
|
|
|
}
|