From 80a31e9cbff59b1ca1a70d5fc07ad01e4e78141a Mon Sep 17 00:00:00 2001 From: Purplebored Date: Sat, 30 Sep 2023 00:24:10 +0200 Subject: [PATCH] final commit --- Program.cs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 5360f3f..8245ff5 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,9 @@ using System.Reflection; using Newtonsoft.Json.Linq; using System.Globalization; using Microsoft.Extensions.Configuration; +using System.Text; +using Newtonsoft.Json; +using System.Collections.Generic; class Program { @@ -1171,5 +1174,64 @@ public class Commands : ModuleBase } // End of scary + // AI commands. + + // Begning of GPT Command. + // Assuming you have a dictionary to store conversation history + Dictionary> userConversations = new Dictionary>(); + + [Command("gpt")] + public async Task GPT([Remainder] string input) + { + string apiKey = "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"; // Replace with your ChatGPT API key + string apiUrl = "https://api.openai.com/v1/chat/completions"; + + HttpClient client = new HttpClient(); + client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); + + string userId = Guid.NewGuid().ToString(); + + if (!userConversations.ContainsKey(userId)) + { + userConversations[userId] = new List + { + new + { + role = "system", + content = "You are a doomer you dont really care and your responses are small and staright to the point." + } + }; + } + + userConversations[userId].Add(new + { + role = "user", + content = input + }); + + HttpResponseMessage response = await client.PostAsync(apiUrl, new StringContent(JsonConvert.SerializeObject(new + { + model = "gpt-3.5-turbo", + messages = userConversations[userId], + }), Encoding.UTF8, "application/json")); + + if (response.IsSuccessStatusCode) + { + string responseBody = await response.Content.ReadAsStringAsync(); + dynamic result = JsonConvert.DeserializeObject(responseBody); + + string botReply = result.choices[0].message.content; + + await ReplyAsync(botReply); + } + else + { + await ReplyAsync("Error: Unable to generate response."); + } + } + // End of GPT command. + + + // End of AI commands. // End of the Bot } \ No newline at end of file diff --git a/README.md b/README.md index 405b714..daf9f4a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Chrobry - +# This repo is no longer maintained A king among revolt bots 👑 ![Chrobry(1).png](Assets/Chrobry(1).png)