Search the Community
Showing results for tags 'openai'.
-
Version 1.7.6
822 downloads
RustGPT integrates OpenAI's powerful ChatGPT directly into Rust, allowing players to interact with ChatGPT through the game chat. This unique plugin enhances the Rust gaming experience by providing color commentary on deaths, answering player questions, and more, all powered by the advanced capabilities of ChatGPT. Features Color Commentary for Deaths: RustGPT adds an entertaining twist to gameplay by providing ChatGPT-powered color commentary on player deaths, with customizable settings for tone and content. ChatGPT Access: Players can use ChatGPT to ask questions or engage in conversation directly through the Rust game chat. Customizable Prompts and Responses: Server admins can customize the system's prompts and responses, tailoring the ChatGPT interaction to fit the server's theme or setting. Cooldown Management: To ensure fair usage and prevent spam, RustGPT includes a cooldown system that limits how often players can use the ChatGPT feature. Discord Integration: Optional integration with Discord via webhooks allows for broadcasting ChatGPT responses or death commentary directly to a Discord server. Configurable Settings: From API keys to response parameters, RustGPT offers extensive configuration options to customize the plugin's behavior and integration with OpenAI's API. User Permissions: Server admins can control who has access to the ChatGPT features through customizable permissions. You should read this entire README if you are using this plugin for the first time. Required OpenAI API Key To run this project, you will need to get yourself a fancy OpenAI API key. Installation Copy the plugin RustGPT.cs into your Carbon or Oxide plugins folder. When the plugin is first loaded it will generate a configuration file and the server console will say Please configure the plugin with the required OpenAI API key. Configure the plugin in the RustGPT.json file located in you Oxide or Carbon configs folder. Permissions In console for oxide: o.grant user <player_name_or_steam_id> RustGPT.chat In console for Carbon: c.grant user <player_name_or_steam_id> RustGPT.chat Restart the plugin. Using Oxide? Do this: o.reload RustGPT.cs Using Carbon? Do this: c.reload RustGPT.cs Do yourself a favor and make a local copy of your RustGPT.json file in case something goes wonky in future updates. Usage/Examples Question Patterns This setting is designed to validate the chat message so only specified text triggers the API call. Currently the default question structure is like this: "Question Pattern": "!gpt" This is an old method to trigger commands in rust. Basically, any chat message that contains the text "!gpt" will send that chat message through the API and trigger a response. You can edit this in the configuration file. Since this is capable of accepting regex expressions you can get crazy with it. For example: "Question Pattern": "(who|what|when|where|why|how|is|are|am|do|does|did|can|could|will|would|should|which|whom).*?$" This will look for a chat message that contains one of the various keywords and ends with a question mark. "Question Pattern": "" And incase you were wondering this will full send everything. Not recommended. If you have a well populated server and a lot of chat enthusiasts, this will cost you some money. Commands /models - admin only, lists the available models. https://github.com/Rust-Haus/RustGPTFree -
Version 1.0.1
29 downloads
For developers to integrate OpenAI endpoints into their plugins. Features API Key Verification: Automatically verifies the provided OpenAI API key. Chat Commands: Provides in-game commands for administrators to interact with the OpenAI API. Model Listing: Fetches and lists available models from OpenAI. Chat Completions: Handles chat-based interactions with OpenAI's language models. Configuration { "DefaultAssistantModel": { "max_completion_tokens": 150, "max_prompt_tokens": 150, "Model": "gpt-4o" }, "DefaultCompletionsModel": { "MaxTokens": 150, "Model": "gpt-4o" }, "OpenAI_Api_Key": { "OpenAI API Key": "your-api-key-here" } } Commands /openaitest Tests the connection to the OpenAI API using a predefined message. Only available to administrators. /listmodels Fetches and lists all available models from the OpenAI API. Only available to administrators. Public Methods There are two main API interactions through the completions and the assistant API. Completions_SimpleChat Example of Completions_SimpleChat - Creates a simple chat interaction with OpenAI. private void AskGptCommand(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, "RustGPT.chat")) { player.ChatMessage("<color=#ff0000>You do not have permission to use this command.</color>"); return; } if (args.Length == 0) { player.ChatMessage("Usage: /askgpt <your question>"); return; } if (!HasCooldownElapsed(player)) { return; } var userMessage = string.Join(" ", args); var messages = new List<object> { new { role = "system", content = _config.DefaultContent }, new { role = "user", content = userMessage } }; player.ChatMessage("Sending your message to OpenAI..."); OpenAI?.Call("Completions_SimpleChat", messages, (System.Action<JObject>)((response) => { if (response != null && response["choices"] != null && response["choices"].HasValues) { string GPT_Chat_Reply = response["choices"][0]["message"]["content"].ToString().Trim(); if (GPT_Chat_Reply.Length > 1200) { CreateNotesForResponse(player, GPT_Chat_Reply); } else { SendChatMessageInChunks(player, $"<color={_config.ReplyPrefixColor}>{_config.ReplyPrefix}</color> {GPT_Chat_Reply}", 250); } } else { player.ChatMessage("<color=#ff0000>Failed to get a valid response from OpenAI. Please try again later.</color>"); } })); } Assistant_CreateAssistant [HookMethod("Assistant_CreateAssistant")] public void Assistant_CreateAssistant(string name = null, string description = null, string instructions = null, List<object> tools = null, object toolResources = null, Dictionary<string, string> metadata = null, double? temperature = null, double? topP = null, object responseFormat = null, Action<JObject> callback = null) Example: var openAIPlugin = (OpenAI)plugins.Find("OpenAI"); openAIPlugin.Assistant_CreateAssistant("MyAssistant", "An assistant for my game", "You are a helpful assistant.", null, null, null, null, null, null, response => { if (response != null) { Puts("Assistant created successfully: " + response.ToString()); } else { Puts("Failed to create assistant."); } }); Assistant_CreateVectorStore Example use of Assistant_CreateVectorStore to save chat interactions in the OpenAI platform using the Assistants API. var openAIPlugin = (OpenAI)plugins.Find("OpenAI"); List<string> fileIds = new List<string>(); // Initially, no file IDs string name = "OpenAIChatHistory"; object expiresAfter = DateTime.UtcNow.AddDays(30); // Expires after 30 days object chunkingStrategy = null; // Define your chunking strategy if any Dictionary<string, string> metadata = new Dictionary<string, string> { { "game", "Rust" }, { "description", "Vector store for storing chat interactions with OpenAI" } }; openAIPlugin.Assistant_CreateVectorStore(fileIds, name, expiresAfter, chunkingStrategy, metadata, response => { if (response != null) { Puts("Vector store created successfully: " + response.ToString()); } else { Puts("Failed to create vector store."); } }); Pubic Methods FetchModels Completions_CreateChat Completions_SimpleChat Assistant_CreateAssistant CreateThread RetrieveThread ModifyThread DeleteThread Assistant_CreateMessage Assistant_ListMessages Assistant_RetrieveMessage Assistant_ModifyMessage Assistant_DeleteMessage Assistant_CreateRun Assistant_CreateThreadAndRun Assistant_ListRuns Assistant_RetrieveRun Assistant_ModifyRun Assistant_CancelRun Assistant_ListRunSteps Assistant_RetrieveRunStep Assistant_CreateVectorStore Assistant_ListVectorStores Assistant_RetrieveVectorStore Assistant_ModifyVectorStore Assistant_DeleteVectorStore Assistant_SubmitToolOutput All of these interactions are built using the OpenAI platform as a scaffold. Using the OpenAI documentation you can see response examples for all of the available methods. https://platform.openai.com/docs/api-reference/introductionFree