{"id":"cnezxp","deleted":false,"future_paste":false,"expired":false,"language":"text","created_at":"2023-02-21 01:51:00","expires_at":null,"content":"#include <sourcemod>\r\n\r\npublic Plugin my_chatgpt_plugin = \r\n  new Plugin(\"My ChatGPT Plugin for TF2\", \"1.0\", \"Your Name\");\r\n\r\npublic Action OnClientSay(int client, const char[] message) \r\n{\r\n  if (StrContains(message, \"Kog:\", true) != -1) \r\n  {\r\n    \/\/ Extract the message text without \"Kog:\"\r\n    char[] msg_text[256];\r\n    SubStr(message, 4, -1, msg_text, sizeof(msg_text));\r\n\r\n    \/\/ Use the ChatGPT API to generate a response\r\n    char[] response[256];\r\n    MyChatGPTApi(msg_text, response);\r\n\r\n    \/\/ Send the response to the chat\r\n    PrintToChat(client, \"Kog: %s\", response);\r\n\r\n    \/\/ Log the response for debugging purposes\r\n    LogMessage(\"Generated response to \\\"%s\\\": \\\"%s\\\"\", msg_text, response);\r\n  }\r\n\r\n  return Plugin_Handled;\r\n}\r\n\r\npublic void MyChatGPTApi(const char[] input, char[] output) \r\n{\r\n    \/\/ Define the API endpoint URL\r\n    const char[] api_url = \"https:\/\/api.openai.com\/v1\/engines\/davinci-codex\/completions\";\r\n\r\n    \/\/ Define the API request headers\r\n    const char[] api_headers = \"Content-Type: application\/json\\r\\nAuthorization: Bearer YOUR_API_KEY\";\r\n\r\n    \/\/ Define the API request data\r\n    char[] api_data[512];\r\n    format(api_data, \"{\\\"prompt\\\":\\\"%s\\\",\\\"max_tokens\\\":50,\\\"temperature\\\":0.5}\", input);\r\n\r\n    \/\/ Send the API request and get the response\r\n    char[] api_response[2048];\r\n    HTTPRequest(api_url, api_headers, api_data, api_response, sizeof(api_response), HTTPMETHOD_POST);\r\n\r\n    \/\/ Parse the API response and extract the generated text\r\n    char[] response_text[256];\r\n    JSON_Object obj = JSON_Parse(api_response);\r\n    JSON_Array choices = JSON_GetObjectItem(obj, \"choices\");\r\n    JSON_Object choice = JSON_GetArrayItem(choices, 0);\r\n    JSON_Object text = JSON_GetObjectItem(choice, \"text\");\r\n    JSON_GetStringValue(text, response_text, sizeof(response_text));\r\n    JSON_Delete(obj);\r\n\r\n    \/\/ Copy the generated text to the output buffer\r\n    CopyString(output, response_text, sizeof(output));\r\n}\r\n"}