đŠOpenAi RedM Assistant
A lua rest api for RedM.
Add ChatGPT 4.0 Turbo in your server RedM Chat
_______ _______ _________
( ___ )( ____ )\__ __/
| ( ) || ( )| ) (
| (___) || (____)| | |
| ___ || _____) | |
| ( ) || ( | |
| ) ( || ) ___) (___
|/ \||/ \_______/

How To Use
Copy the folder inside the resouce folder of your server, start the script inside server.cfg
To get the Api key go to your account on https://beta.openai.com/account/api-keys and copy the key.
In this example i've used Davinci gpt 3.5 Turbo model, you can change the model and use what you need.
Change the value with your OpenAi Api key inside the config
-- API endpoint URL
local url = "https://api.openai.com/v1/chat/completions"
-- API key for authentication
local api_key = "YOUR API KEY"
```lua
local data = {
model = "gpt-3.5-turbo",
messages = {
{
role = "user",
content = tostring(arg[1]),
},
{
role = "system",
content = "You are a personal assistant for a RedM online server called 1889, based on Red Dead Redemption 2 game",
}
}
}
```
Add Response to Chat

To get response text, you can use:
if statusCode == 200 then
-- Process the response data
local decoded_response = json.decode(response)
local completion = decoded_response.choices[1].message.content
print("Completion:", completion)
TriggerClientEvent('chat:addMessage', _src, {color = {255, 0, 0}, args = {"open_ai","" ..completion.. ""}})
Commands
Use /chatgpt
"custom prompt" inside redm
You can change the command inside the server.lua
RegisterCommand("chatgpt", function(_src, arg)
OpenAI
The OpenAI API can be applied to virtually any task that involves understanding or generating natural language or code.
Support
If you need more help join our Discord Community and open a ticket:
â¨SupportCopyright
License MIT
IT'S MANDATORY TO GIVE CREDITS IF YOU REUSE THE CODE!
DO NOT CHANGE CREDITS INSIDE THE CODE.
You need to add credis like: "Copyright Ruxo 2024, https://github.com/turangarusso/"
Thank you
Last updated