Skip to content

Commit ddb64b6

Browse files
committed
Save and Load
Saving and loading working now.
1 parent 35de997 commit ddb64b6

7 files changed

+252
-2
lines changed

ButtonTest2.gd

+24-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ var assistant = "Your name is Bob. You will respond with nothing other than exac
4242

4343
var g_LLM_INPUT
4444

45+
func get_save_dict():
46+
var save_dict = {}
47+
48+
var llm_tokens = $"../Node/HBoxContainer/TextEdit_tokens"
49+
var llm_temp = $"../Node/HBoxContainer/TextEdit_temp"
50+
var llm_fpnlty = $"../Node/HBoxContainer/TextEdit_f"
51+
var llm_ppnlty = $"../Node/HBoxContainer/TextEdit_p"
52+
53+
54+
max_tokens = int(llm_tokens.text)
55+
temperature = float(llm_temp.text)
56+
frequency_penalty = float(llm_fpnlty.text)
57+
presence_penalty = float(llm_ppnlty.text)
58+
59+
save_dict.messages = messages
60+
save_dict.assistant = assistant
61+
62+
save_dict.max_tokens = max_tokens
63+
save_dict.temperature = temperature
64+
save_dict.frequency_penalty = frequency_penalty
65+
save_dict.presence_penalty = presence_penalty
66+
67+
4568

4669
func llm_set_assistant(assistant):
4770
assistant = assistant # assistant is always the first message
@@ -251,7 +274,7 @@ func llm_response_return(result, response_code, headers, body):
251274
output += msg["role"] + ": " + msg["content"] + "\r\n-----\r\n"
252275

253276

254-
$LLM_OUTPUT.text = output
277+
$LLM_OUTPUT.text = output # obsolete
255278

256279
# clear the input
257280
g_LLM_INPUT.text = ""

Button_load.gd

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extends Button
2+
3+
4+
# Called when the node enters the scene tree for the first time.
5+
func _ready():
6+
pass # Replace with function body.
7+
8+
9+
# Called every frame. 'delta' is the elapsed time since the previous frame.
10+
func _process(delta):
11+
pass
12+
13+
14+
15+
func _on_button_up():
16+
print("loading dialog")
17+
$"../../FileDialog_load".show()
18+
pass # Replace with function body.

Button_save.gd

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
extends Button
2+
3+
4+
# Called when the node enters the scene tree for the first time.
5+
func _ready():
6+
pass # Replace with function body.
7+
8+
9+
# Called every frame. 'delta' is the elapsed time since the previous frame.
10+
func _process(delta):
11+
pass
12+
13+
14+
func get_save_dict():
15+
var save_dict = {}
16+
17+
var llm_tokens = $"../Node/HBoxContainer/TextEdit_tokens"
18+
var llm_temp = $"../Node/HBoxContainer/TextEdit_temp"
19+
var llm_fpnlty = $"../Node/HBoxContainer/TextEdit_f"
20+
var llm_ppnlty = $"../Node/HBoxContainer/TextEdit_p"
21+
22+
23+
var max_tokens = int(llm_tokens.text)
24+
var temperature = float(llm_temp.text)
25+
var frequency_penalty = float(llm_fpnlty.text)
26+
var presence_penalty = float(llm_ppnlty.text)
27+
28+
save_dict.messages = $"../../ButtonTest2".messages
29+
save_dict.assistant = $"../../ButtonTest2".assistant
30+
31+
save_dict.max_tokens = max_tokens
32+
save_dict.temperature = temperature
33+
save_dict.frequency_penalty = frequency_penalty
34+
save_dict.presence_penalty = presence_penalty
35+
36+
37+
38+
39+
40+
func _on_button_up():
41+
$"../../FileDialog_save".show()
42+
pass # Replace with function body.

FileDialog_load.gd

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
extends FileDialog
2+
3+
@onready var file_dialog_save = $"."
4+
5+
# Called when the node enters the scene tree for the first time.
6+
func _ready():
7+
pass # Replace with function body.
8+
9+
10+
# Called every frame. 'delta' is the elapsed time since the previous frame.
11+
func _process(delta):
12+
pass
13+
14+
15+
16+
17+
18+
func get_save_dict():
19+
var save_dict = {}
20+
21+
var llm_tokens = $"../Node/HBoxContainer/TextEdit_tokens"
22+
var llm_temp = $"../Node/HBoxContainer/TextEdit_temp"
23+
var llm_fpnlty = $"../Node/HBoxContainer/TextEdit_f"
24+
var llm_ppnlty = $"../Node/HBoxContainer/TextEdit_p"
25+
26+
27+
var max_tokens = int(llm_tokens.text)
28+
var temperature = float(llm_temp.text)
29+
var frequency_penalty = float(llm_fpnlty.text)
30+
var presence_penalty = float(llm_ppnlty.text)
31+
32+
save_dict.messages = $"../ButtonTest2".messages
33+
save_dict.assistant = $"../ButtonTest2".assistant
34+
35+
save_dict.max_tokens = max_tokens
36+
save_dict.temperature = temperature
37+
save_dict.frequency_penalty = frequency_penalty
38+
save_dict.presence_penalty = presence_penalty
39+
40+
return save_dict
41+
42+
43+
44+
func _on_file_selected(path):
45+
print("loading")
46+
var load_file = FileAccess.open(path, FileAccess.READ)
47+
var the_dict = load_file.get_var()
48+
49+
print(JSON.stringify(the_dict))
50+
51+
var llm_assistant = $"../VBoxContainer/TextEdit_LLM_AGENT"
52+
var llm_tokens = $"../Node/HBoxContainer/TextEdit_tokens"
53+
var llm_temp = $"../Node/HBoxContainer/TextEdit_temp"
54+
var llm_fpnlty = $"../Node/HBoxContainer/TextEdit_f"
55+
var llm_ppnlty = $"../Node/HBoxContainer/TextEdit_p"
56+
57+
$"../ButtonTest2".messages = the_dict.messages
58+
llm_assistant.text = str(the_dict.assistant)
59+
llm_tokens.text = str(the_dict.max_tokens)
60+
llm_temp.text = str(the_dict.temperature)
61+
llm_fpnlty.text = str(the_dict.frequency_penalty)
62+
llm_ppnlty.text = str(the_dict.presence_penalty)
63+
#var save_dict = {}
64+
#
65+
#save_file.store_var(get_save_dict())
66+
# update output
67+
$"../ButtonTest2".update_output()
68+

FileDialog_saveconvo.gd

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
extends FileDialog
2+
3+
@onready var file_dialog_save = $"."
4+
5+
# Called when the node enters the scene tree for the first time.
6+
func _ready():
7+
pass # Replace with function body.
8+
9+
10+
# Called every frame. 'delta' is the elapsed time since the previous frame.
11+
func _process(delta):
12+
pass
13+
14+
15+
func _on_file_dialog_save_file_selected(path):
16+
print("saving")
17+
18+
19+
pass
20+
21+
22+
23+
24+
func get_save_dict():
25+
var save_dict = {}
26+
27+
var llm_tokens = $"../Node/HBoxContainer/TextEdit_tokens"
28+
var llm_temp = $"../Node/HBoxContainer/TextEdit_temp"
29+
var llm_fpnlty = $"../Node/HBoxContainer/TextEdit_f"
30+
var llm_ppnlty = $"../Node/HBoxContainer/TextEdit_p"
31+
32+
33+
var max_tokens = int(llm_tokens.text)
34+
var temperature = float(llm_temp.text)
35+
var frequency_penalty = float(llm_fpnlty.text)
36+
var presence_penalty = float(llm_ppnlty.text)
37+
38+
save_dict.messages = $"../ButtonTest2".messages
39+
save_dict.assistant = $"../ButtonTest2".assistant
40+
41+
save_dict.max_tokens = max_tokens
42+
save_dict.temperature = temperature
43+
save_dict.frequency_penalty = frequency_penalty
44+
save_dict.presence_penalty = presence_penalty
45+
46+
return save_dict
47+
48+
49+
50+
func _on_file_selected(path):
51+
var save_file = FileAccess.open(path, FileAccess.WRITE)
52+
var save_dict = {}
53+
54+
save_file.store_var(get_save_dict())
55+
56+

api_demo.tscn

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=12 format=3 uid="uid://ckacadt42a56c"]
1+
[gd_scene load_steps=16 format=3 uid="uid://ckacadt42a56c"]
22

33
[ext_resource type="StyleBox" uid="uid://cqv0hefs7tiy6" path="res://scroll_convo.tres" id="2_hesce"]
44
[ext_resource type="Script" path="res://LLM_INPUT.gd" id="2_k8qgm"]
@@ -10,6 +10,10 @@
1010
[ext_resource type="StyleBox" uid="uid://fins1ecscv1a" path="res://assistant_message.tres" id="6_nn07k"]
1111
[ext_resource type="Script" path="res://ScrollContainer_convo.gd" id="8_qhyod"]
1212
[ext_resource type="Theme" uid="uid://f63p5wbvmhsm" path="res://theme_input_options.tres" id="10_758b3"]
13+
[ext_resource type="Script" path="res://FileDialog_saveconvo.gd" id="11_gyqoa"]
14+
[ext_resource type="Script" path="res://Button_save.gd" id="11_rigmi"]
15+
[ext_resource type="Script" path="res://FileDialog_load.gd" id="12_6oa4w"]
16+
[ext_resource type="Script" path="res://Button_load.gd" id="14_xr3dg"]
1317

1418
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_n8se8"]
1519

@@ -402,4 +406,43 @@ layout_mode = 2
402406
size_flags_horizontal = 8
403407
text = " send message "
404408

409+
[node name="FileDialog_save" type="FileDialog" parent="."]
410+
initial_position = 2
411+
size = Vector2i(800, 600)
412+
access = 2
413+
root_subfolder = "saved"
414+
filters = PackedStringArray("*.gsav")
415+
script = ExtResource("11_gyqoa")
416+
417+
[node name="FileDialog_load" type="FileDialog" parent="."]
418+
title = "Open a File"
419+
initial_position = 2
420+
size = Vector2i(800, 600)
421+
ok_button_text = "Open"
422+
file_mode = 0
423+
access = 2
424+
root_subfolder = "saved"
425+
filters = PackedStringArray("*.gsav")
426+
script = ExtResource("12_6oa4w")
427+
428+
[node name="HBoxContainer" type="HBoxContainer" parent="."]
429+
offset_left = 5.0
430+
offset_top = 95.0
431+
offset_right = 161.0
432+
offset_bottom = 131.0
433+
434+
[node name="Button_save" type="Button" parent="HBoxContainer"]
435+
layout_mode = 2
436+
text = " save "
437+
script = ExtResource("11_rigmi")
438+
439+
[node name="Button_load" type="Button" parent="HBoxContainer"]
440+
layout_mode = 2
441+
text = " load "
442+
script = ExtResource("14_xr3dg")
443+
405444
[connection signal="button_up" from="ButtonTest2" to="ButtonTest2" method="_on_button_up"]
445+
[connection signal="file_selected" from="FileDialog_save" to="FileDialog_save" method="_on_file_selected"]
446+
[connection signal="file_selected" from="FileDialog_load" to="FileDialog_load" method="_on_file_selected"]
447+
[connection signal="button_up" from="HBoxContainer/Button_save" to="HBoxContainer/Button_save" method="_on_button_up"]
448+
[connection signal="button_up" from="HBoxContainer/Button_load" to="HBoxContainer/Button_load" method="_on_button_up"]

saved/test.gsav

820 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)