Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Virtual Girl Chatbot</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- margin: 0;
- padding: 0;
- background-color: #f4f4f4;
- }
- #chat-container {
- max-width: 600px;
- margin: 20px auto;
- background-color: #fff;
- border-radius: 10px;
- overflow: hidden;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
- }
- #chat-messages {
- padding: 20px;
- height: 300px;
- overflow-y: auto;
- }
- #user-input {
- padding: 10px;
- display: flex;
- align-items: center;
- }
- #user-message {
- flex: 1;
- padding: 8px;
- border: 1px solid #ddd;
- border-radius: 5px;
- }
- #send-button {
- margin-left: 10px;
- padding: 8px 12px;
- background-color: #4caf50;
- color: #fff;
- border: none;
- border-radius: 5px;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <div id="chat-container">
- <div id="chat-messages"></div>
- <div id="user-input">
- <input type="text" id="user-message" placeholder="Type your message...">
- <button id="send-button" onclick="sendMessage()">Send</button>
- </div>
- </div>
- <img src="angeliq.gif" alt="Virtual Girl" width="300">
- <script>
- async function sendMessage() {
- const userMessage = document.getElementById("user-message").value;
- document.getElementById("user-message").value = "";
- // Add user message to the chat
- addMessage("user", userMessage);
- // Call OpenAI API to get virtual girl's response
- const response = await getOpenAIResponse(userMessage);
- // Add virtual girl's response to the chat
- addMessage("virtualGirl", response);
- }
- function addMessage(sender, message) {
- const chatMessages = document.getElementById("chat-messages");
- const messageElement = document.createElement("div");
- messageElement.innerHTML = `<strong>${sender}:</strong> ${message}`;
- chatMessages.appendChild(messageElement);
- // Scroll to the bottom of the chat
- chatMessages.scrollTop = chatMessages.scrollHeight;
- }
- async function getOpenAIResponse(userMessage) {
- const apiKey = "Your openai api";
- const apiUrl = "https://api.openai.com/v1/engines/davinci-codex/completions";
- const response = await fetch(apiUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "Authorization": `Bearer ${apiKey}`
- },
- body: JSON.stringify({
- prompt: `Virtual girl role play: ${userMessage}`,
- max_tokens: 50
- })
- });
- const data = await response.json();
- return data.choic
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement