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

38 lines
932 B
C#
Raw Permalink Normal View History

2023-09-23 19:57:43 +02:00
using Godot;
using System;
public partial class LLMApiRequest : HttpRequest
{
public record AnswerRequest(
Message[] Context,
string Prompt
);
public record Message(
string Role,
string? Content
);
private bool PostToApiIsSet = false;
// Called when the node enters the scene tree for the first time.
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));
}
}