Advertisement
MachineFox

Miami

Aug 8th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | Food | 0 0
  1. repeat wait() until game:IsLoaded();
  2.  
  3. -- // SETTINGS \\ --
  4.  
  5. local SECRET_KEY = "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"; --https://beta.openai.com/account/api-keys
  6. local CLOSE_RANGE_ONLY = true;
  7.  
  8. _G.MESSAGE_SETTINGS = {
  9. ["MINIMUM_CHARACTERS"] = 15,
  10. ["MAXIMUM_CHARACTERS"] = 50,
  11. ["MAXIMUM_STUDS"] = 15,
  12. };
  13.  
  14. _G.WHITELISTED = { --Only works if CLOSE_RANGE_ONLY is disabled
  15. ["seem2006"] = true,
  16. };
  17.  
  18. _G.BLACKLISTED = { --Only works if CLOSE_RANGE_ONLY is enabled
  19. ["Builderman"] = true,
  20. };
  21.  
  22. -- // DO NOT CHANGE BELOW \\ --
  23.  
  24. if _G.OpenAI or SECRET_KEY == "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" then return end;
  25.  
  26. _G.OpenAI = true;
  27.  
  28. local ReplicatedStorage = game:GetService("ReplicatedStorage");
  29. local Players = game:GetService("Players");
  30. local HttpService = game:GetService("HttpService");
  31. local LocalPlayer = Players.LocalPlayer;
  32. local SayMessageRequest = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("SayMessageRequest");
  33. local OnMessageDoneFiltering = ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("OnMessageDoneFiltering");
  34. local Debounce = false;
  35.  
  36. local RequestFunctiom = syn and syn.request or request;
  37.  
  38. local function MakeRequest(Prompt)
  39. return RequestFunctiom({
  40. Url = "https://api.openai.com/v1/completions",
  41. Method = "POST",
  42. Headers = {
  43. ["Content-Type"] = "application/json",
  44. ["Authorization"] = "Bearer " .. SECRET_KEY
  45. },
  46. Body = HttpService:JSONEncode({
  47. model = "text-davinci-003",
  48. prompt = Prompt,
  49. temperature = 0.9,
  50. max_tokens = 45, --150
  51. top_p = 1,
  52. frequency_penalty = 0.0,
  53. presence_penalty = 0.6,
  54. stop = {" Human:", " AI:"}
  55. });
  56. });
  57. end
  58.  
  59. OnMessageDoneFiltering.OnClientEvent:Connect(function(Table)
  60. local Message, Instance = Table.Message, Players:FindFirstChild(Table.FromSpeaker);
  61. local Character = Instance and Instance.Character;
  62.  
  63. if Instance == LocalPlayer or string.match(Message, "#") or not Character or not Character:FindFirstChild("Head") or not LocalPlayer.Character or not LocalPlayer.Character:FindFirstChild("Head") then return end;
  64. if Debounce or #Message < _G.MESSAGE_SETTINGS["MINIMUM_CHARACTERS"] or #Message > _G.MESSAGE_SETTINGS["MAXIMUM_CHARACTERS"] then return end;
  65. if CLOSE_RANGE_ONLY then if _G.BLACKLISTED[Instance.Name] or (Character.Head.Position - LocalPlayer.Character.Head.Position).Magnitude > _G.MESSAGE_SETTINGS["MAXIMUM_STUDS"] then return end elseif not _G.WHITELISTED[Instance.Name] then return end;
  66.  
  67. Debounce = true;
  68.  
  69. local HttpRequest = MakeRequest("Human: " .. Message .. "\n\nAI:");
  70. local Response = Instance.Name .. ": " .. string.sub(HttpService:JSONDecode(HttpRequest["Body"]).choices[1].text, 2);
  71.  
  72. if #Response < 128 then --200
  73. SayMessageRequest:FireServer(Response, "All");
  74. wait(5);
  75. Debounce = false;
  76. else
  77. --warn("Response (> 128): " .. Response);
  78. if #Response - 128 < 128 then
  79. SayMessageRequest:FireServer(string.sub(Response, 1, 128), "All");
  80. delay(3, function()
  81. SayMessageRequest:FireServer(string.sub(Response, 129), "All");
  82. wait(5);
  83. Debounce = false;
  84. end)
  85. else
  86. SayMessageRequest:FireServer("Sorry but the answer was too big, please try again.", "All");
  87. wait(2.5);
  88. Debounce = false;
  89. end
  90. end
  91. end)
  92.  
  93. warn("Script has been executed with success.");
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement