-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
276 lines (242 loc) · 11.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!DOCTYPE html>
<html lang="en">
<link rel="manifest" href="manifest.json" />
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Puter AI</title>
<meta name="description"
content="Puter AI is an artificial intelligence powered by Puter. It can speak in multiple languages, like english, french, spanish, and many more !" />
<link rel="icon" type="image/vnd.icon" href="favicon.ico">
<script>console.log("Puter AI PWA started, ready to send messages.")</script>
<!-- Material Design Web CDN -->
<script type="importmap">
{
"imports": {
"@material/web/": "https://esm.run/@material/web/"
}
}
</script>
<script type="module">
import '@material/web/all.js';
import { styles as typescaleStyles } from '@material/web/typography/md-typescale-styles.js';
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
</script>
<!-- Noto Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&family=Noto+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
body {
font-family: 'Noto Sans', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
flex-direction: column;
}
#chat-container {
width: 80%;
max-width: 600px;
margin: auto;
background: white;
border: 1px solid #ddd;
border-radius: 30px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
#messages {
height: 400px;
overflow-y: auto;
border-bottom: 1px solid #ddd;
margin-bottom: 20px;
padding: 10px;
}
.message {
padding: 5px;
margin: 5px 0;
border-radius: 10px;
background: #2c7aef;
color: white;
}
.user-message {
text-align: right;
background: #f9f9f9;
color: black;
}
.user-message .message {
background: #e0f7fa;
}
#chat-input {
display: flex;
align-items: center;
}
#chat-input md-outlined-text-field {
flex-grow: 1;
margin-right: 10px;
max-width: 489px;
min-height: 78px;
max-height: 686px;
--md-filled-text-field-input-text-font: 'Noto Sans', sans-serif;
--md-filled-text-field-label-text-font: 'Noto Sans', sans-serif;
}
#chat-input md-filled-button {
padding: 10px 20px;
height: 52px;
}
md-filled-button,
md-outlined-button {
--mdc-theme-primary: #007bff;
--mdc-theme-on-primary: white;
font-family: 'Noto Sans', sans-serif;
}
md-outlined-button {
margin-top: 20px;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
:root {
--md-sys-color-primary: #007bff;
--md-sys-color-secondary: #007bffdc;
--md-ref-typeface-brand: 'Noto Sans';
--md-ref-typeface-plain: 'Noto Sans';
}
#icon-buttons {
display: flex;
gap: 10px;
margin-top: 20px;
}
#loading-spinner {
display: none;
margin-top: 20px;
}
</style>
<script src="https://js.puter.com/v2/"></script>
<meta name="google-site-verification" content="Q71qMHrmXHVJS96xLobvU5PdXHzkR23IRRD6gykEZew" />
</head>
<body>
<script>
if (typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.register('offline.js')
}
</script>
<div id="chat-container">
<div id="messages"></div>
<div id="chat-input">
<md-outlined-text-field label="Message" placeholder="Type a message..." id="messageInput"
error-text="Please type a message" style="font-family: 'Noto Sans', sans-serif;"></md-outlined-text-field>
<md-filled-button id="sendButton" style="font-family: 'Noto Sans', sans-serif;">Send
<img slot="icon" src="icons/send.png" alt="Send Icon" />
</md-filled-button>
</div>
</div>
<div id="loading-spinner">
<md-circular-progress indeterminate></md-circular-progress>
</div>
<div id="icon-buttons">
<md-outlined-icon-button aria-label="Settings" href="settings.html">
<md-icon class="material-icons">settings</md-icon>
</md-outlined-icon-button>
<md-outlined-icon-button aria-label="Github" href="https://github.com/Zac0511/Puter-AI-PWA">
<md-icon class="material-icons">code</md-icon>
</md-outlined-icon-button>
</div>
<p>Powered by <a href="https://puter.com">Puter</a></p>
<script type="module">
const messages = [];
function addMessage(msg, isUser) {
const messagesDiv = document.getElementById("messages");
const messageDiv = document.createElement("div");
messageDiv.classList.add("message");
if (isUser) {
messageDiv.classList.add("user-message");
}
messageDiv.textContent = msg;
messagesDiv.appendChild(messageDiv);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
function toggleLoadingSpinner(show) {
const spinner = document.getElementById('loading-spinner');
if (show) {
spinner.style.display = 'block';
} else {
spinner.style.display = 'none';
}
}
function sendMessage(message) {
const input = document.querySelector("#messageInput");
message = message || input.value.trim();
console.log("Message sent to Puter AI");
if (message) {
addMessage(message, true); // Add user message to chat history
input.value = ''; // Clear input field
toggleLoadingSpinner(true); // Show loading indicator
// Create messages array with context for the AI
const messages = [
{
// Gives the AI important info about how it needs to awnser
role: 'system',
content: "You are the AI of a PWA named 'Puter AI PWA' developed by 'Zac0511'.The PWA is powered by Puter.js, allowing websites to use AI for free. You need to remember that Zac0511 is not the one who created you, he only made the PWA which interacts with you thanks to Puter.js, your creator is a company called 'Puter'. Puter is web based operationg system, entierly running in the browser, its creators are only 3 persons, but the projects grows fast as its open source, and more 2000 users contributed to it (including Zac0511, the creator of this PWA). Puter.js is Puter's API, allwoing websites to store files on the user's Puter filesystem, and access AI, which is why your creator is Puter. Your name is 'Puter AI'. Do NOT use Markdown formatting, the PWA in which you run doesn't support markdown."
},
{
// Complementary informations about Puter that the AI could need for some questions
role: 'system',
content: "The following is complementary informations about Puter: The URL to access Puter is 'https://puter.com'. Puter is web-based OS running entierly in the browser. You have been created by Puter. Puter is made by only 3 persons, but grows fast because it is open source. The URL to join Puter's Discord server is 'https://discord.gg/PQcx7Teh8u'"
},
{
// Complementary informations about the Puter AI PWA
role: 'system',
content: "The following is complementary informations about the Puter AI PWA: The current version of the Puter AI PWA is version 2.2.2. The creator of the Puter AI PWA is 'Zac0511'. The Puter AI PWA can be installed on computer and mobile, but it can also be runned (without being installed) on any device with a recent browser (such as computers, phones, consoles, TVs, etc...). The Puter AI PWA can be used without a Puter account, but the user will have less message credits. The user can check how many messages credits are left on his Puter account by opening Puter, clicking the Puter logo in the top left corner (it will open settings), clicking 'Usage' in the settings, and checking the bar named 'puter-chat-completion (complete):'. The Puter AI PWA is also available as a Puter app at the URL 'https://puter.com/app/ai-chat'. The UI of the Puter AI PWA is using Google Material Design V3. The PWA cannot be used offline, as the AI is stored on Puter servers (trying to open the app when offline will show a custom error message). If the user encounters any problem with the Puter AI PWA, or ask for a new feature, he can create an issue at the URL 'https://github.com/Zac0511/Puter-AI-PWA/issues/new/choose'."
},
{
role: 'user',
content: message // User's actual message
}
];
// Call the AI chat function with the messages array
puter.ai.chat(messages)
.then(response => {
addMessage(response, false); // Add AI response to chat history
toggleLoadingSpinner(false); // Hide loading indicator
console.log("AI response received");
})
.catch(error => {
console.error("AI response error:", error);
alert("An error occured, please try again. If the error persists, please create an issue on the GitHub repository (you can access it by clicking the button with a 'code' icon)");
toggleLoadingSpinner(false); // Hide loading indicator in case of error
});
}
}
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
// Check for message in URL query params and send it if present
window.onload = function() {
const message = getQueryParam('message');
if (message) {
sendMessage(message);
}
};
// Sends the message if enter is pressed
document.querySelector("#messageInput").addEventListener("keypress", function (event) {
if (event.key === "Enter") {
event.preventDefault();
sendMessage();
}
});
document.querySelector('#sendButton').addEventListener('click', function () {
sendMessage();
});
</script>
</body>
</html>