· 3 years ago · Jul 01, 2022, 05:50 PM
1-- made by BillsTheGod
2
3repeat wait() until game:IsLoaded();
4
5-- // SETTINGS \\ --
6
7local SECRET_KEY = "secret key here"; --https://beta.openai.com/account/api-keys
8local WHITELISTED = {
9 ["seem2006"] = true,
10};
11
12-- // DO NOT CHANGE BELOW \\ --
13
14_G.ForceStop = false;
15
16local ReplicatedStorage = game:GetService("ReplicatedStorage");
17local HttpService = game:GetService("HttpService");
18local Players = game:GetService("Players");
19local SayMessageRequest = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("SayMessageRequest");
20local Debounce = false;
21
22local function MakeRequest(Prompt)
23 return syn.request({
24 Url = "https://api.openai.com/v1/completions",
25 Method = "POST",
26 Headers = {
27 ["Content-Type"] = "application/json",
28 ["Authorization"] = "Bearer " .. SECRET_KEY
29 },
30 Body = HttpService:JSONEncode({
31 model = "text-davinci-002",
32 prompt = Prompt,
33 temperature = 0.9,
34 max_tokens = 49, --150
35 top_p = 1,
36 frequency_penalty = 0.0,
37 presence_penalty = 0.6,
38 stop = {" Human:", " AI:"}
39 });
40 });
41end
42
43for i,v in pairs(Players:GetPlayers()) do
44 if WHITELISTED[v.Name] and v.Name ~= Players.LocalPlayer.Name then
45 print(v.Name .. " is whitelisted");
46
47 v.Chatted:Connect(function(Message)
48 if _G.ForceStop or Debounce or #Message < 15 or #Message > 45 then return end;
49
50 Debounce = true;
51
52 local HttpRequest = MakeRequest("Human: " .. Message .. "\n\nAI:");
53 local Response = string.gsub(string.sub(HttpService:JSONDecode(HttpRequest["Body"]).choices[1].text, 2), "[%p%c]", "");
54
55 if #Response < 200 then
56 warn("Response (unfiltered): " .. HttpService:JSONDecode(HttpRequest["Body"]).choices[1].text);
57 SayMessageRequest:FireServer(v.Name .. ": " .. Response, "All");
58 wait(5);
59 Debounce = false;
60 else
61 SayMessageRequest:FireServer("Unfornately the response was too big to be replied to ROBLOX chat, please try again.", "All");
62 wait(2.5);
63 Debounce = false;
64 end
65 end)
66 end
67end
68