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/godot/LLMApiRequests.cs
2023-09-24 12:10:42 +02:00

37 lines
854 B
C#

using Godot;
using System;
public partial class LLMApiRequests : HttpRequest
{
public record AnswerRequest(
Message[] Context,
string Prompt
);
public record Message(
string Role,
string? Content
);
private bool PostToApiIsSet = false;
public override void _Ready()
{
SetProcess(false);
}
public void PostToApi(Action<long, long, string[], byte[]> action)
{
if(!PostToApiIsSet)
{
RequestCompleted += (long result, long responseCode, string[] headers, byte[] body) => action(result, responseCode, headers, body);
PostToApiIsSet = true;
}
var answerRequest = new AnswerRequest(new[] { new Message("user", "Hello!"), }, "aodneris");
Request($"http://localhost:5246/LLM/Test", new[] { "Content-Type: application/json" }, HttpClient.Method.Get, Newtonsoft.Json.JsonConvert.SerializeObject(answerRequest));
}
}