بهترین فیلم‌ها و سریال‌ها را در سینما 24 ببینید!

<!DOCTYPE html>

<html lang=”fa”>

<head>

<meta charset=”UTF-8″>

<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>

<title>چت با هوش مصنوعی</title>

<style>

body {

font-family: ‘Arial’, sans-serif;

background-color: #f0f0f0;

color: #333;

margin: 0;

padding: 0;

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

}

 

.chat-container {

width: 400px;

background-color: #fff;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

border-radius: 5px;

overflow: hidden;

}

 

.chat-header {

background-color: #007bff;

color: #fff;

padding: 10px;

text-align: center;

}

 

.chat-messages {

height: 300px;

overflow-y: auto;

padding: 10px;

border-bottom: 1px solid #ddd;

}

 

.chat-input {

display: flex;

padding: 10px;

}

 

.chat-input input {

flex: 1;

padding: 10px;

border: 1px solid #ddd;

border-radius: 3px;

}

 

.chat-input button {

padding: 10px 20px;

border: none;

background-color: #007bff;

color: #fff;

cursor: pointer;

border-radius: 3px;

margin-left: 10px;

}

</style>

</head>

<body>

<div class=”chat-container”>

<div class=”chat-header”>چت با هوش مصنوعی</div>

<div class=”chat-messages” id=”chat-messages”></div>

<div class=”chat-input”>

<input type=”text” id=”user-input” placeholder=”پیام خود را وارد کنید…”>

<button id=”send-button”>ارسال</button>

</div>

</div>

 

<script>

const apiKey = ‘YOUR_OPENAI_API_KEY’; // کلید API که ارائه داده‌اید

 

document.addEventListener(‘DOMContentLoaded’, () => {

const chatMessages = document.getElementById(‘chat-messages’);

const userInput = document.getElementById(‘user-input’);

const sendButton = document.getElementById(‘send-button’);

 

sendButton.addEventListener(‘click’, () => {

const userMessage = userInput.value;

if (userMessage) {

addMessageToChat(‘کاربر’, userMessage);

userInput.value = ”;

fetchChatResponse(userMessage);

}

});

 

function addMessageToChat(sender, message) {

const messageElement = document.createElement(‘div’);

messageElement.classList.add(‘chat-message’);

messageElement.innerHTML = `<strong>${sender}:</strong> ${message}`;

chatMessages.appendChild(messageElement);

chatMessages.scrollTop = chatMessages.scrollHeight;

}

 

function fetchChatResponse(message) {

fetch(‘https://api.openai.com/v1/engines/davinci-codex/completions’, {

method: ‘POST’,

headers: {

‘Content-Type’: ‘application/json’,

‘Authorization’: `Bearer ${apiKey}`

},

body: JSON.stringify({

prompt: message,

max_tokens: 150

})

})

.then(response => response.json())

.then(data => {

const aiMessage = data.choices[0].text.trim();

addMessageToChat(‘هوش مصنوعی’, aiMessage);

})

.catch(error => console.error(‘Error fetching chat response:’, error));

}

});

</script>

</body>

</html>

Website with Footer Ad

بهترین فیلم‌ها و سریال‌ها را در سینما 24 ببینید!

Website with Footer Ad

بهترین فیلم‌ها و سریال‌ها را در سینما 24 ببینید!