using api gateway
This commit is contained in:
1 parent
563b4800ee
commit
b29e7fe660
1 file changed
+5
-23
@@ -8,10 +8,7 @@ extends Control
|
|||||||
@onready var generate_button: Button = $MarginContainer/Scroll/VBox/GenerateRow/GenerateButton
|
@onready var generate_button: Button = $MarginContainer/Scroll/VBox/GenerateRow/GenerateButton
|
||||||
@onready var helper = $VBoxContainer/SubViewportContainer/SubViewport/base_node/helper
|
@onready var helper = $VBoxContainer/SubViewportContainer/SubViewport/base_node/helper
|
||||||
|
|
||||||
const API_URL := "https://apphubai.wolke.uni-greifswald.de/v1" #TODO insert your url to the llm / api-gateway here
|
const API_URL := ""
|
||||||
const API_TOKEN := ""
|
|
||||||
const API_MODEL := "unsloth/gemma-4-31B-it-qat-GGUF:UD-Q4_K_XL"
|
|
||||||
const MAX_RESPONSE_TOKENS := 200
|
|
||||||
var document_id
|
var document_id
|
||||||
|
|
||||||
signal closing_chatbot
|
signal closing_chatbot
|
||||||
@@ -51,20 +48,11 @@ func _on_generate_pressed() -> void:
|
|||||||
combined_user_message = "Dokument:\n%s\n\nFrage: %s" % [document, user_text]
|
combined_user_message = "Dokument:\n%s\n\nFrage: %s" % [document, user_text]
|
||||||
|
|
||||||
var body := {
|
var body := {
|
||||||
"model": API_MODEL,
|
"question": combined_user_message,
|
||||||
"messages": [
|
"prompt": tr("CHATBOT_SYSTEM_PROMPT"),
|
||||||
{"role": "system", "content": tr("CHATBOT_SYSTEM_PROMPT")},
|
|
||||||
{"role": "user", "content": combined_user_message},
|
|
||||||
],
|
|
||||||
"max_tokens": MAX_RESPONSE_TOKENS,
|
|
||||||
"temperature": 0.1,
|
|
||||||
}
|
}
|
||||||
var headers := PackedStringArray([
|
var headers := PackedStringArray(["Content-Type: application/json"])
|
||||||
"Content-Type: application/json",
|
var err := _http.request(API_URL, headers, HTTPClient.METHOD_POST, JSON.stringify(body))
|
||||||
"Authorization: Bearer %s" % API_TOKEN,
|
|
||||||
])
|
|
||||||
var endpoint := API_URL.trim_suffix("/") + "/chat/completions"
|
|
||||||
var err := _http.request(endpoint, headers, HTTPClient.METHOD_POST, JSON.stringify(body))
|
|
||||||
if err != OK:
|
if err != OK:
|
||||||
_stop_helper_animation()
|
_stop_helper_animation()
|
||||||
output_text.text = _request_failed("HTTP %s" % error_string(err))
|
output_text.text = _request_failed("HTTP %s" % error_string(err))
|
||||||
@@ -105,14 +93,8 @@ func _on_request_completed(
|
|||||||
func _extract_reply(json) -> String:
|
func _extract_reply(json) -> String:
|
||||||
if typeof(json) != TYPE_DICTIONARY:
|
if typeof(json) != TYPE_DICTIONARY:
|
||||||
return ""
|
return ""
|
||||||
if json.has("choices") and json["choices"] is Array and not json["choices"].is_empty():
|
|
||||||
var choice = json["choices"][0]
|
|
||||||
if choice is Dictionary and choice.get("message") is Dictionary:
|
|
||||||
return str(choice["message"].get("content", "")).strip_edges()
|
|
||||||
if json.has("content"):
|
if json.has("content"):
|
||||||
return str(json["content"]).strip_edges()
|
return str(json["content"]).strip_edges()
|
||||||
if json.get("message") is Dictionary:
|
|
||||||
return str(json["message"].get("content", "")).strip_edges()
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
func _request_failed(detail: String) -> String:
|
func _request_failed(detail: String) -> String:
|
||||||
|
|||||||
Reference in new issue
Block a user