Skip to content

Commit

Permalink
- fix dialog crash llm
Browse files Browse the repository at this point in the history
  • Loading branch information
cesare-montresor committed Feb 16, 2025
1 parent 9d230d1 commit 0043701
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions UI/dialogue/dialogue.gd
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ func close():
clear()

func talk():
start_talk()
if LLM.talking: return
var text = LLM.Dialog.llm_input.text
if text.strip_edges() != "":
LLM.talk_npc(LLM.Dialog.llm_input.text)
llm_input.text = ""
set_focus_input()

func start_talk():
if LLM.did_init(): return
var npc = WorldState.current_npc
var system_prompt = npc.data.build_system_prompt()
LLM.init_chat(system_prompt)

# Button SEND
func _on_button_pressed(): talk()

Expand Down
2 changes: 2 additions & 0 deletions elements/npcs/npc.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func _on_body_entered(body: Node2D) -> void:
print(body.name)
if body.name=='Player':
first_touch = false
LLM.clear_chat()
WorldState.set_npc(self)

var quest_step_data = Quests.check_quest(data)
Expand Down Expand Up @@ -77,3 +78,4 @@ func _on_body_exited(_body: Node2D) -> void:
first_touch = true
LLM.Dialog.close()
WorldState.clear_npc()
LLM.clear_chat()
2 changes: 1 addition & 1 deletion elements/quests/quest_data/droid_welcome.tres
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://elements/quests/quest_data.gd" id="2_0anxo"]
[ext_resource type="Script" path="res://elements/quests/quest_step.gd" id="3_7umki"]
[ext_resource type="Script" path="res://elements/items/item_data.gd" id="4_k7ni8"]
[ext_resource type="Resource" path="res://elements/items/item_data/keycard_grey.tres" id="6_2wdob"]
[ext_resource type="Resource" uid="uid://ddgwqudsnpagn" path="res://elements/items/item_data/keycard_grey.tres" id="6_2wdob"]
[ext_resource type="Script" path="res://elements/quests/quest_reward.gd" id="6_kslbd"]
[ext_resource type="Script" path="res://elements/quests/reward_item.gd" id="8_p61oi"]

Expand Down
5 changes: 4 additions & 1 deletion globals/llm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var is_chat_ready: bool = false
func _ready() -> void:
re_newline = RegEx.create_from_string("\n\n+")

func did_init():
return chat_once != null

func clear_chat():
if chat_once != null:
remove_child(chat_once)
Expand All @@ -31,7 +34,7 @@ func init_chat(prompt:String):
chat_once.start_worker()

func talk_npc(prompt: String ):
print("talk_npc_queue:", queue.size() )
#print("talk_npc_queue:", queue.size() )
if WorldState.current_npc == null: return
if talking: return

Expand Down

0 comments on commit 0043701

Please sign in to comment.