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

58 lines
1.6 KiB
C#
Raw Permalink Normal View History

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;
}
// [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
{
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);
}
catch (Exception ex)
{
2023-09-24 12:57:19 +02:00
Console.WriteLine(ex.ToString());
return StatusCode(500, ex.ToString());
}
2023-09-23 11:21:46 +02:00
}
}