Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
loganofcdev authored Apr 8, 2024
1 parent c17cc72 commit 38e6465
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ function appendMessage(sender, message) {

async function getBotResponse(userInput) {
try {
// Replace this URL with the actual API endpoint to fetch bot responses
var apiUrl = 'https://example.com/chatbot-api?q=' + encodeURIComponent(userInput);
var response = await fetch(apiUrl);
// Replace 'YOUR_API_KEY' with your actual OpenAI API key
var apiKey = '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';
var apiUrl = 'https://api.openai.com/v1/completions';
var response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey
},
body: JSON.stringify({
model: 'text-davinci-003', // You can use other models as well
prompt: userInput,
max_tokens: 100
})
});
var data = await response.json();
return data.response;
return data.choices[0].text.trim();
} catch (error) {
console.error("Error fetching bot response:", error);
return "Sorry, I couldn't understand that.";
Expand Down

0 comments on commit 38e6465

Please sign in to comment.