@@ -15,7 +15,7 @@ func _ready():
1515@onready var path_text_regex = RegEx .new ()
1616# Called every frame. 'delta' is the elapsed time since the previous frame.
1717var receiving = false
18- func _process (delta ):
18+ func _process (_delta ):
1919
2020 path_text_regex .compile (r '"parts":\s *\[\s *{\s *"text":\s *"((?:[^"\\ ]|\\ .)*)"\s *}\s *\] ' )
2121
@@ -56,9 +56,8 @@ func _on_send_button_pressed():
5656
5757func _request_text (prompt ):
5858 find_child ("ResponseEdit" ).text = ""
59- var url = "https://generativelanguage.googleapis.com/v1/models/gemini-pro:streamGenerateContent?key=%s " % api_key
6059
61- var body = JSON .new (). stringify ({
60+ var body = JSON .stringify ({
6261 "contents" :[
6362 { "parts" :[{
6463 "text" : prompt
@@ -94,13 +93,19 @@ func _request_text(prompt):
9493 # while http_client.get_status() == HTTPClient.STATUS_CONNECTING or http_client.get_status() == HTTPClient.STATUS_RESOLVING:
9594 # print(http_client.get_status())
9695
97- var query_string = http_client .query_string_from_dict (fields )
9896
9997 var error = http_client .request (HTTPClient .METHOD_POST ,"/v1/models/gemini-pro:streamGenerateContent?key=%s " % api_key , ["User-Agent: Pirulo/1.0 (Godot)" ,"Accept: */*" ,"Content-Type: application/json" ], body )
10098 if error != OK :
10199 push_error ("requested but error happen code = %s " % error )
102100
103- func _on_request_completed (result , responseCode , headers , body ):
101+ func _on_request_completed (result , responseCode , _headers , body ):
102+ if result != OK :
103+ print ("request faild error code: " , result )
104+ return
105+ if responseCode != 200 :
106+ print ("response is not 200 error code: " , responseCode )
107+ return
108+
104109 find_child ("SendButton" ).disabled = false
105110 var json = JSON .new ()
106111 json .parse (body .get_string_from_utf8 ())
0 commit comments