diff --git a/mooncal/chat.js b/mooncal/chat.js new file mode 100644 index 0000000..5d5604d --- /dev/null +++ b/mooncal/chat.js @@ -0,0 +1,32 @@ +async function getChatGPTResponse(prompt) { + const url = `https://mooncalendar.glitch.me/api/chatgpt`; + + try { + const response = await fetch(url, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ prompt }) + }); + + if (!response.ok) { + throw new Error(`Error: ${response.statusText}`); + } + + const data = await response.json(); + console.log("ChatGPT response:", data.response); + + return data.response; // Return the chatbot's response + } catch (error) { + console.error("Failed to get response from ChatGPT:", error); + } + + return null; // Default to null if fetching fails + } + + // Example Usage + getChatGPTResponse("Tell me a joke about programming.").then(response => { + if (response) { + console.log("ChatGPT says:", response); + } + }); + \ No newline at end of file diff --git a/mooncal/index.html b/mooncal/index.html index 0ef7dd7..4b5ca01 100644 --- a/mooncal/index.html +++ b/mooncal/index.html @@ -21,6 +21,7 @@