Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>SwagGPT</title>
- <style>
- body {
- background-color: #333;
- color: #fff;
- font-family: 'Courier New', monospace;
- }
- #chatWindow {
- width: 60%;
- height: 400px;
- margin: 20px auto;
- border: 2px solid #fff;
- border-radius: 5px;
- padding: 20px;
- overflow-y: scroll;
- background-color: #000;
- }
- #inputField {
- width: 58%;
- margin: 20px auto;
- padding: 10px;
- display: block;
- background-color: #000;
- color: #fff;
- border: none;
- border-radius: 5px;
- }
- #sendButton {
- display: block;
- width: 60%;
- margin: 0 auto;
- padding: 10px;
- background-color: #ff4500;
- color: #fff;
- border: none;
- border-radius: 5px;
- cursor: pointer;
- }
- #sendButton:hover {
- background-color: #ff6347;
- }
- #logo {
- display: block;
- width: 200px;
- margin: 20px auto;
- }
- #subtitle {
- text-align: center;
- font-style: italic;
- }
- </style>
- </head>
- <body>
- <img id="logo" src="swaggpt.png" alt="SwagGPT Logo">
- <div id="subtitle">SwagGPT, powered by Der Postillon & c't 3003</div>
- <div id="chatWindow">
- <ul id="chat"></ul>
- </div>
- <input id="inputField" type="text" placeholder="Type your message here..." />
- <button id="sendButton" onclick="generateResponse()">Drop the beat</button>
- <script>
- const OPENAI_API_KEY = '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';
- var messages = [{role:'system', content: 'Du bist SwagGPT, ein eher unfreundlicher, aber dafür umso swaggiger Chatbot. Du bist der beste Rapper der Welt, wie. Benutze Füllwörter wie "sheesh", "Diggi","turn up". Ersetze "ein" immer durch "1". Benutze "vong".'}];
- // Add an event listener to the input field that listens for key down events
- document.getElementById('inputField').addEventListener('keydown', function(event) {
- // Check if the key pressed was the enter key
- if (event.key === 'Enter') {
- // Prevent the default action to stop the enter key from creating a new line in the input field
- event.preventDefault();
- // Call the generateResponse function
- generateResponse();
- }
- });
- async function generateResponse() {
- var inputText = document.getElementById('inputField').value;
- let chat = document.getElementById('chat');
- chat.innerHTML += `<li>Du: ${inputText}</li>`;
- var sentMessages = [...messages];
- document.getElementById('inputField').value = '';
- messages.push({ role: "user", content: inputText });
- sentMessages.push({ role: "user", content: inputText + '\n Antworte als SwagGPT in maximal 30 Wörtern.' });
- console.log(messages);
- console.log(sentMessages);
- const response = await fetch('https://api.openai.com/v1/chat/completions', {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${OPENAI_API_KEY}`,
- },
- body: JSON.stringify({
- model: "gpt-3.5-turbo",
- messages: sentMessages,
- temperature: 1.0,
- }),
- });
- if (response.ok) {
- const data = await response.json();
- console.log(data);
- let outputText = data.choices[0].message.content;
- chat.innerHTML += `<li>SwagGPT: ${outputText}</li>`;
- messages.push({ role: "assistant", content: outputText });
- }
- else {
- console.error(`Error: ${response.status}`);
- return null;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment