using System; using robotManager.Helpful; using wManager.Wow.Helpers; using wManager.Wow.Enums; using wManager.Plugin; using robotManager.Products; using System.Net.Http; using System.Text; using Newtonsoft.Json; using System.Threading.Tasks; using System.Threading; public class Main : IPlugin { private bool _isLaunched; private readonly string _apiUrl = "http://127.0.0.1:1234/v1/chat/completions"; // Notice the endpoint here! public void Initialize() { _isLaunched = true; Logging.Write("[WhisperResponder] Started."); var chat = new Channel(); while (_isLaunched && Products.IsStarted) { try { while (chat.ActuelRead != Channel.GetMsgActuelInWow && Products.IsStarted) { var msg = chat.ReadMsg(); if (msg.Channel == ChatTypeId.WHISPER) { Logging.Write("[WhisperResponder] Whisper from " + msg.UserName + ": " + msg.Msg); // Add delay before LLM call Thread.Sleep(8000); // Delay 8 seconds // Call the local LLM async method and wait for result string response = SendToLocalLLMAsync(msg.Msg).Result; // Respond to the whisper Chat.SendChatMessageWhisper(response, msg.UserName); } } } catch (Exception e) { Logging.WriteError("[WhisperResponder]: " + e); } Thread.Sleep(150); } } public void Dispose() { _isLaunched = false; Logging.Write("[WhisperResponder] Stopped."); } public void Settings() { // No settings for this example } private async Task SendToLocalLLMAsync(string userMessage) { try { using (HttpClient client = new HttpClient()) { var payload = new { model = "nous-hermes-2-mistral-7b-dpo", messages = new[] { new { role = "system", content = "You are a new World of Warcraft player who barely speaks English. " + "You do NOT greet people, do NOT say 'hello', 'hi', or 'how can I help you?'. " + "You speak very broken English with bad grammar and no punctuation. " + "You answer only what is asked, with very short and simple sentences. " + "If someone says 'hello' or 'hi', you respond like a confused beginner, not with greetings. " + "Never ask questions back or offer help. Just respond as a clueless noob player." }, new { role = "user", content = userMessage } } }; string jsonPayload = JsonConvert.SerializeObject(payload); var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); var response = await client.PostAsync(_apiUrl, content); string responseBody = await response.Content.ReadAsStringAsync(); Logging.Write("[WhisperResponder] LLM raw response: " + responseBody); dynamic jsonResponse = JsonConvert.DeserializeObject(responseBody); if (jsonResponse != null && jsonResponse.choices != null && jsonResponse.choices.Count > 0) { string assistantMessage = jsonResponse.choices[0].message.content; return assistantMessage.Trim(); } else { return "sorry i no understand"; } } } catch (Exception ex) { Logging.WriteError("[WhisperResponder] LLM request failed: " + ex.Message); return "sorry i no understand"; } } }