game-dev #8
36
godot/LLMApiRequests.cs
Normal file
36
godot/LLMApiRequests.cs
Normal 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));
|
||||
}
|
||||
}
|
@ -4,22 +4,20 @@ using System.Net.Cache;
|
||||
|
||||
public partial class Playbutton : Button
|
||||
{
|
||||
// private LLMApiRequest llmApiRequest;
|
||||
private LLMApiRequests llmApiRequests;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
SetProcess(false);
|
||||
// llmApiRequest = GetNode<LLMApiRequest>("/root/Node2D/HTTPRequests");
|
||||
llmApiRequests = GetNode<LLMApiRequests>("/root/LLMApiRequests");
|
||||
}
|
||||
|
||||
public override void _Pressed()
|
||||
{
|
||||
// llmApiRequest.RequestCompleted += OnRequestCompleted;
|
||||
// llmApiRequest.Request("https://api.github.com/repos/godotengine/godot/releases/latest");
|
||||
// llmApiRequest?.PostToApi(OnRequestCompleted);
|
||||
llmApiRequests?.PostToApi(OnRequestCompleted);
|
||||
// GD.Print("is null? " + llmApiRequests is null);
|
||||
|
||||
|
||||
GD.Print("a");
|
||||
var node = this.GetTree().Root.GetNode<CanvasLayer>("Root/Ingame/IngameCanvas");
|
||||
node.SetProcess(true);
|
||||
|
@ -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="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://LLMApiRequests.cs" id="4_ff2gi"]
|
||||
|
||||
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_ncw85"]
|
||||
|
||||
@ -361,3 +362,6 @@ offset_bottom = 719.0
|
||||
texture = SubResource("CompressedTexture2D_ncw85")
|
||||
expand_mode = 1
|
||||
stretch_mode = 1
|
||||
|
||||
[node name="LLMApiRequests" type="HTTPRequest" parent="."]
|
||||
script = ExtResource("4_ff2gi")
|
||||
|
Reference in New Issue
Block a user