ok... i solve my problem. the problem is on my self. i forgot to add the
return response
which is stupid on my side lol
here's the fixed code
--google palm--
--roblox lua
local Players = game:GetService("Players");
local HttpService = game:GetService("HttpService");
local LocalPlayer = Players.LocalPlayer;
local RequestFunctiom = request;
local function MakeRequest(Prompt)
local success, response = pcall(function()
return RequestFunctiom({
Url = "https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=KEY_HERE",
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
},
Body = HttpService:JSONEncode({
prompt = {
text = Prompt
},
temperature = 0.7,
candidateCount = 1,
topP = 0.95,
topK = 5,
maxOutputTokens = 100,
stopSequences = {"Human:", "Ai:"},
})
})
end)
print(response)
return response
end
print("MakeRequest sending")
print("test1")
local HttpRequest = MakeRequest("Human: Hello how are you today \n\nAI:");
--wait(3) -- if this added the local Response will errored the error is "attempt to index nil with the Body"
local Response = ". " .. string.sub(HttpService:JSONDecode(HttpRequest["Body"]).candidates[1].output, 2);
print(Response)
I'm not sure what language that is but the proper JSon body for the request should be something like this
You defiantly have prompt and stop_sequences wrong.
candidate_count
you have candidate_count set to three which means that
HttpService:JSONDecode(response.Body).candidates
is an array.It may be failing on that