Skip to content

Commit 0f7035e

Browse files
author
Aki
committed
refactoring
1 parent 045ff09 commit 0f7035e

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# godot-simple-gemini-api
2+
This is Example Project not addon.
23
As simply as possible, call the Gemini API.
34
## API KEYS
45
This app requires an API key. Save it in settings.json. Take care of your keys. By default, it is added to .gitignore.

get_list_model.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func _ready():
1414

1515

1616
# Called every frame. 'delta' is the elapsed time since the previous frame.
17-
func _process(delta):
17+
func _process(_delta):
1818
pass
1919

2020

main.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var settings_path = "res://settings.json"
55
func _ready():
66
var container = find_child("GridContainer")
77
var names = ["send_text","send_text_safety","send_text_config","send_text_stream","chat_text","send_image","get_embedding","batch_embedding","count_tokens","get_list_model"]
8-
for name in names:
8+
for node_name in names:
99
var button = Button.new()
10-
button.text = name
10+
button.text = node_name
1111
button.connect("pressed", Callable(self, "_on_button_pressed").bind(button))
1212
container.add_child(button)
1313

@@ -17,7 +17,7 @@ func _on_button_pressed(button):
1717
var scene_path = "res://"+button.text+".tscn"
1818
get_tree().change_scene_to_file(scene_path)
1919
# Called every frame. 'delta' is the elapsed time since the previous frame.
20-
func _process(delta):
20+
func _process(_delta):
2121
pass
2222

2323
func _update_ui():

project.godot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ config/icon="res://icon.png"
1919

2020
window/size/viewport_width=800
2121
window/size/viewport_height=680
22+
23+
[dotnet]
24+
25+
project/assembly_name="Godot-simple-gemini-api"

send_text_stream.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1717
var 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

5757
func _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

Comments
 (0)