game-dev #8

Merged
leon merged 9 commits from game-dev into dev/game 2023-09-24 13:32:16 +02:00
3 changed files with 45 additions and 7 deletions
Showing only changes of commit 0b5029aab1 - Show all commits

36
godot/LLMApiRequests.cs Normal file
View File

@ -0,0 +1,36 @@
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));
}
}

View File

@ -4,21 +4,19 @@ using System.Net.Cache;
public partial class Playbutton : Button public partial class Playbutton : Button
{ {
// private LLMApiRequest llmApiRequest; private LLMApiRequests llmApiRequests;
// Called when the node enters the scene tree for the first time. // Called when the node enters the scene tree for the first time.
public override void _Ready() public override void _Ready()
{ {
SetProcess(false); SetProcess(false);
// llmApiRequest = GetNode<LLMApiRequest>("/root/Node2D/HTTPRequests"); llmApiRequests = GetNode<LLMApiRequests>("/root/LLMApiRequests");
} }
public override void _Pressed() public override void _Pressed()
{ {
// llmApiRequest.RequestCompleted += OnRequestCompleted; llmApiRequests?.PostToApi(OnRequestCompleted);
// llmApiRequest.Request("https://api.github.com/repos/godotengine/godot/releases/latest"); // GD.Print("is null? " + llmApiRequests is null);
// llmApiRequest?.PostToApi(OnRequestCompleted);
GD.Print("a"); GD.Print("a");
var node = this.GetTree().Root.GetNode<CanvasLayer>("Root/Ingame/IngameCanvas"); var node = this.GetTree().Root.GetNode<CanvasLayer>("Root/Ingame/IngameCanvas");

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://1gar30yhw8ay"] [gd_scene load_steps=6 format=3 uid="uid://1gar30yhw8ay"]
[ext_resource type="Script" path="res://MainMenu.cs" id="1_m0gay"] [ext_resource type="Script" path="res://MainMenu.cs" id="1_m0gay"]
[ext_resource type="Texture2D" uid="uid://vn2ficr8n4n5" path="res://GodofAi.jpg" id="2_m684j"] [ext_resource type="Texture2D" uid="uid://vn2ficr8n4n5" path="res://GodofAi.jpg" id="2_m684j"]
[ext_resource type="Script" path="res://Playbutton.cs" id="3_ucfae"] [ext_resource type="Script" path="res://Playbutton.cs" id="3_ucfae"]
[ext_resource type="Script" path="res://LLMApiRequests.cs" id="4_ff2gi"]
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_ncw85"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_ncw85"]
@ -361,3 +362,6 @@ offset_bottom = 719.0
texture = SubResource("CompressedTexture2D_ncw85") texture = SubResource("CompressedTexture2D_ncw85")
expand_mode = 1 expand_mode = 1
stretch_mode = 1 stretch_mode = 1
[node name="LLMApiRequests" type="HTTPRequest" parent="."]
script = ExtResource("4_ff2gi")