Added SoftwareDevChatbot

This commit is contained in:
2025-11-11 10:59:18 +01:00
parent 0ffeb914c3
commit 378228b208
11 changed files with 1123 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Software Dev Chatbot</title>
</head>
<body>
<div class="main-container">
<div class="chat-container">
<div class="header">
<img src="chat.png" alt="Logo" class="logo">
<h2 class="name">Chat Window</h2>
</div>
<div class="chat-log" id="chat-log"></div>
<div class="input-container">
<input type="text" id="user-input" placeholder="Ask me anything...">
<button onclick="sendMessage()">Send</button>
</div>
</div>
</div>
<script src="main.js"></script>
</body>
</html>

View File

@@ -0,0 +1,40 @@
const chatLog = document.getElementById('chat-log');
const userInput = document.getElementById('user-input');
function sendMessage() {
const message = userInput.value;
// Display user's message
displayMessage('user', message);
// Call OpenAI API to get chatbot's response
getChatbotResponse(message);
// Clear user input
userInput.value = '';
}
function displayMessage(sender, message) {
const messageElement = document.createElement('div');
messageElement.classList.add('message', sender);
// Wrap the message in a <p> tag
const messageParagraph = document.createElement('p');
messageParagraph.innerText = message;
// Append the <p> tag to the message element
messageElement.appendChild(messageParagraph);
chatLog.appendChild(messageElement);
}
function getChatbotResponse(userMessage) {
// Make a request to your server with the user's message
fetch('/getChatbotResponse', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ userMessage }),
})
.then(response => response.json())
.then(data => {
// Display chatbot's response
displayMessage('chatbot', data.chatbotResponse);
})
.catch(error => console.error('Error:', error));
}

View File

@@ -0,0 +1,90 @@
.chat-container {
max-width: 600px;
margin: 20px auto;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
overflow: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 80vh;
position: relative;
background: linear-gradient(to bottom, #1e5799, #2989d8);
}
.logo {
width: auto;
height: 50px;
margin-left: 10px;
margin-top: 10px;
margin-bottom: 10px;
border-radius: 50px;
}
.name {
font-size: 20px;
font-weight: bold;
margin: 10px;
color: #fff;
margin-left: 10px;
margin-right: 10px;
}
.chat-window {
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: flex-end;
padding: 20px;
background-color: #fff;
overflow-y: auto;
}
.input-container {
display: flex;
align-items: center;
padding: 20px;
background-color: #fff;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
outline: none;
font-size: 16px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.chat-log {
height: 400px;
padding: 20px;
overflow-y: auto;
background-color: rgba(255, 255, 255, 0.8);
}
/* Added space between user prompts */
.chat-log p {
margin: 10px 0;
}
.input-container input[type="text"] {
flex: 1;
height: 40px;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
outline: none;
}
.input-container button {
margin-left: 10px;
padding: 8px 16px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: #fff;
font-size: 16px;
cursor: pointer;
}
.input-container button:hover {
background-color: #45a049;
}
html, body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}