more stuff
This commit is contained in:
parent
0b5029aab1
commit
661093e9a3
@ -1,36 +1,61 @@
|
||||
using Godot;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
public partial class LLMApiRequests : HttpRequest
|
||||
{
|
||||
private TextEdit Scenario;
|
||||
private TextEdit Input;
|
||||
|
||||
private bool PostToApiIsSet = false;
|
||||
|
||||
private Message[]? Context;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetProcess(false);
|
||||
Scenario = GetNode<TextEdit>("/root/MainMenu/MainMenuCanvas/VBoxContainer/ScenarioTextEdit");
|
||||
Input = GetNode<TextEdit>("/root/Ingame/IngameCanvas/Eingabe/TextEdit");
|
||||
}
|
||||
|
||||
public void PostToApi()
|
||||
{
|
||||
if(!PostToApiIsSet)
|
||||
{
|
||||
RequestCompleted += OnRequestCompleted;
|
||||
PostToApiIsSet = true;
|
||||
}
|
||||
|
||||
AnswerRequest? request;
|
||||
if (Context is null)
|
||||
{
|
||||
request = new(null, Scenario.Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
request = new(Context, Input.Text);
|
||||
}
|
||||
|
||||
Request($"http://localhost:5246/LLM/Test", new[] { "Content-Type: application/json" }, HttpClient.Method.Get, JsonConvert.SerializeObject(request));
|
||||
}
|
||||
|
||||
public void OnRequestCompleted(long result, long responseCode, string[] headers, byte[] body)
|
||||
{
|
||||
// Godot.Collections.Dictionary json = Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary();
|
||||
// GD.Print(json["name"]);
|
||||
// GD.Print(Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary());
|
||||
GD.Print(System.Text.Encoding.UTF8.GetString(body));
|
||||
|
||||
// TODO: Store context in var
|
||||
}
|
||||
}
|
||||
|
||||
public record AnswerRequest(
|
||||
Message[] Context,
|
||||
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));
|
||||
}
|
||||
}
|
||||
);
|
@ -15,7 +15,7 @@ public partial class Playbutton : Button
|
||||
|
||||
public override void _Pressed()
|
||||
{
|
||||
llmApiRequests?.PostToApi(OnRequestCompleted);
|
||||
llmApiRequests?.PostToApi();
|
||||
// GD.Print("is null? " + llmApiRequests is null);
|
||||
|
||||
GD.Print("a");
|
||||
@ -25,12 +25,4 @@ public partial class Playbutton : Button
|
||||
var GParent = this.GetTree().Root.GetNode<CanvasLayer>("Root/MainMenu/MainMenuCanvas");
|
||||
GParent.Hide();
|
||||
}
|
||||
|
||||
private void OnRequestCompleted(long result, long responseCode, string[] headers, byte[] body)
|
||||
{
|
||||
// Godot.Collections.Dictionary json = Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary();
|
||||
// GD.Print(json["name"]);
|
||||
// GD.Print(Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary());
|
||||
GD.Print(System.Text.Encoding.UTF8.GetString(body));
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ popup/item_10/id = 10
|
||||
popup/item_11/text = "Krimi 2"
|
||||
popup/item_11/id = 11
|
||||
|
||||
[node name="TextEdit" type="TextEdit" parent="MainMenu/MainMenuCanvas/VBoxContainer"]
|
||||
[node name="ScenarioTextEdit" type="TextEdit" parent="MainMenu/MainMenuCanvas/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(520, 300)
|
||||
layout_direction = 1
|
||||
layout_mode = 2
|
||||
|
Reference in New Issue
Block a user