\begin{Verbatim}[commandchars=\\\{\}] \PYZsh{}include \PYZlt{}sourcemod\PYZgt{} public Plugin my\PYZus{}chatgpt\PYZus{}plugin = new Plugin(\PYZdq{}My ChatGPT Plugin for TF2\PYZdq{}, \PYZdq{}1.0\PYZdq{}, \PYZdq{}Your Name\PYZdq{}); public Action OnClientSay(int client, const char[] message) \PYZob{} if (StrContains(message, \PYZdq{}Kog:\PYZdq{}, true) != \PYZhy{}1) \PYZob{} // Extract the message text without \PYZdq{}Kog:\PYZdq{} char[] msg\PYZus{}text[256]; SubStr(message, 4, \PYZhy{}1, msg\PYZus{}text, sizeof(msg\PYZus{}text)); // Use the ChatGPT API to generate a response char[] response[256]; MyChatGPTApi(msg\PYZus{}text, response); // Send the response to the chat PrintToChat(client, \PYZdq{}Kog: \PYZpc{}s\PYZdq{}, response); // Log the response for debugging purposes LogMessage(\PYZdq{}Generated response to \PYZbs{}\PYZdq{}\PYZpc{}s\PYZbs{}\PYZdq{}: \PYZbs{}\PYZdq{}\PYZpc{}s\PYZbs{}\PYZdq{}\PYZdq{}, msg\PYZus{}text, response); \PYZcb{} return Plugin\PYZus{}Handled; \PYZcb{} public void MyChatGPTApi(const char[] input, char[] output) \PYZob{} // Define the API endpoint URL const char[] api\PYZus{}url = \PYZdq{}https://api.openai.com/v1/engines/davinci\PYZhy{}codex/completions\PYZdq{}; // Define the API request headers const char[] api\PYZus{}headers = \PYZdq{}Content\PYZhy{}Type: application/json\PYZbs{}r\PYZbs{}nAuthorization: Bearer YOUR\PYZus{}API\PYZus{}KEY\PYZdq{}; // Define the API request data char[] api\PYZus{}data[512]; format(api\PYZus{}data, \PYZdq{}\PYZob{}\PYZbs{}\PYZdq{}prompt\PYZbs{}\PYZdq{}:\PYZbs{}\PYZdq{}\PYZpc{}s\PYZbs{}\PYZdq{},\PYZbs{}\PYZdq{}max\PYZus{}tokens\PYZbs{}\PYZdq{}:50,\PYZbs{}\PYZdq{}temperature\PYZbs{}\PYZdq{}:0.5\PYZcb{}\PYZdq{}, input); // Send the API request and get the response char[] api\PYZus{}response[2048]; HTTPRequest(api\PYZus{}url, api\PYZus{}headers, api\PYZus{}data, api\PYZus{}response, sizeof(api\PYZus{}response), HTTPMETHOD\PYZus{}POST); // Parse the API response and extract the generated text char[] response\PYZus{}text[256]; JSON\PYZus{}Object obj = JSON\PYZus{}Parse(api\PYZus{}response); JSON\PYZus{}Array choices = JSON\PYZus{}GetObjectItem(obj, \PYZdq{}choices\PYZdq{}); JSON\PYZus{}Object choice = JSON\PYZus{}GetArrayItem(choices, 0); JSON\PYZus{}Object text = JSON\PYZus{}GetObjectItem(choice, \PYZdq{}text\PYZdq{}); JSON\PYZus{}GetStringValue(text, response\PYZus{}text, sizeof(response\PYZus{}text)); JSON\PYZus{}Delete(obj); // Copy the generated text to the output buffer CopyString(output, response\PYZus{}text, sizeof(output)); \PYZcb{} \end{Verbatim}