58 lines
1.6 KiB
C#
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());
|
|
}
|
|
}
|
|
} |