Skip to content

Commit 0bc1441

Browse files
authored
Merge pull request #20 from Unity-Lab-AI/feature/v0.11
memory improvements, voice activations and timings fix, instruction r…
2 parents dd9247c + 5b210cf commit 0bc1441

File tree

9 files changed

+1283
-820
lines changed

9 files changed

+1283
-820
lines changed

ai/chat-part1.js

Lines changed: 199 additions & 162 deletions
Large diffs are not rendered by default.

ai/chat-part2.js

Lines changed: 594 additions & 204 deletions
Large diffs are not rendered by default.

ai/chat-part3.js

Lines changed: 218 additions & 239 deletions
Large diffs are not rendered by default.

ai/index.html

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<title>Unity Chat UI 9.0</title>
5+
<title>Unity Chat UI 0.9.63</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<!-- Favicon -->
88
<link rel="icon" href="favicon.ico" type="image/x-icon" />
@@ -121,7 +121,7 @@ <h2>Sessions</h2>
121121

122122
<hr class="divider" />
123123

124-
<!-- Theme selection (dropdown) - moved to settings -->
124+
<!-- Theme selection (dropdown) -->
125125
<label for="theme-select" class="sidebar-label">
126126
<i class="fas fa-palette"></i> Theme:
127127
</label>
@@ -197,7 +197,7 @@ <h2>Sessions</h2>
197197
>
198198
<i class="fas fa-volume-mute"></i> Voice Off
199199
</button>
200-
<!-- Our newly added Voice Chat button! -->
200+
<!-- Voice Chat button -->
201201
<button
202202
id="open-voice-chat-modal"
203203
class="control-btn"
@@ -286,13 +286,22 @@ <h3 class="modal-title">Settings</h3>
286286
</div>
287287
<div class="modal-body">
288288
<div class="form-group mb-3">
289-
<label for="theme-select-settings" class="form-label"
290-
><i class="fas fa-palette"></i> Theme:</label
291-
>
289+
<label for="theme-select-settings" class="form-label">
290+
<i class="fas fa-palette"></i> Theme:
291+
</label>
292292
<select id="theme-select-settings" class="form-control">
293293
<!-- Will be populated by JS -->
294294
</select>
295295
</div>
296+
297+
<div class="form-group mb-3">
298+
<label for="voice-select" class="form-label">
299+
<i class="fas fa-headset"></i> Voice Selection:
300+
</label>
301+
<select id="voice-select" class="form-control">
302+
<!-- Voices will dynamically populate here -->
303+
</select>
304+
</div>
296305

297306
<div class="d-grid gap-2">
298307
<button
@@ -392,9 +401,7 @@ <h3 class="modal-title">New Memory Entry</h3>
392401
</div>
393402
<div class="modal-body">
394403
<div class="form-group">
395-
<label for="new-memory-text" class="form-label"
396-
>Memory Content:</label
397-
>
404+
<label for="new-memory-text" class="form-label">Memory Content:</label>
398405
<textarea
399406
id="new-memory-text"
400407
class="form-control"
@@ -436,9 +443,9 @@ <h3 class="modal-title">
436443
<div class="modal-body">
437444
<form id="personalization-form" class="personalization-form">
438445
<div class="form-group mb-3">
439-
<label class="form-label" for="user-name"
440-
><i class="fas fa-user"></i> Your Name</label
441-
>
446+
<label class="form-label" for="user-name">
447+
<i class="fas fa-user"></i> Your Name
448+
</label>
442449
<input
443450
type="text"
444451
id="user-name"
@@ -447,9 +454,9 @@ <h3 class="modal-title">
447454
/>
448455
</div>
449456
<div class="form-group mb-3">
450-
<label class="form-label" for="user-interests"
451-
><i class="fas fa-heart"></i> Your Interests</label
452-
>
457+
<label class="form-label" for="user-interests">
458+
<i class="fas fa-heart"></i> Your Interests
459+
</label>
453460
<input
454461
type="text"
455462
id="user-interests"
@@ -458,9 +465,9 @@ <h3 class="modal-title">
458465
/>
459466
</div>
460467
<div class="form-group mb-3">
461-
<label class="form-label" for="ai-traits"
462-
><i class="fas fa-robot"></i> AI Traits</label
463-
>
468+
<label class="form-label" for="ai-traits">
469+
<i class="fas fa-robot"></i> AI Traits
470+
</label>
464471
<input
465472
type="text"
466473
id="ai-traits"
@@ -469,10 +476,9 @@ <h3 class="modal-title">
469476
/>
470477
</div>
471478
<div class="form-group mb-3">
472-
<label class="form-label" for="additional-info"
473-
><i class="fas fa-info-circle"></i> Additional
474-
Information</label
475-
>
479+
<label class="form-label" for="additional-info">
480+
<i class="fas fa-info-circle"></i> Additional Information
481+
</label>
476482
<textarea
477483
id="additional-info"
478484
class="form-control"
@@ -483,9 +489,7 @@ <h3 class="modal-title">
483489
</form>
484490
</div>
485491
<div class="modal-footer">
486-
<button id="cancel-personalization" class="btn btn-secondary">
487-
Cancel
488-
</button>
492+
<button id="cancel-personalization" class="btn btn-secondary">Cancel</button>
489493
<button id="save-personalization" class="btn btn-primary">Save</button>
490494
</div>
491495
</div>
@@ -552,14 +556,13 @@ <h2 class="welcome-heading">Welcome to Unity Chat!</h2>
552556
// For copying crypto addresses
553557
function copyToClipboard(text) {
554558
navigator.clipboard.writeText(text).then(() => {
555-
// Show a quick ephemeral popup
556559
const popup = document.createElement("div");
557560
popup.textContent = "Address copied. Thank you!";
558561
popup.style.position = "fixed";
559562
popup.style.bottom = "20px";
560563
popup.style.left = "50%";
561564
popup.style.transform = "translateX(-50%)";
562-
popup.style.backgroundColor = "rgba(0,0,0,0.8)";
565+
popup.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
563566
popup.style.color = "#fff";
564567
popup.style.padding = "10px 20px";
565568
popup.style.borderRadius = "5px";
@@ -604,10 +607,59 @@ <h2 class="welcome-heading">Welcome to Unity Chat!</h2>
604607
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"
605608
defer
606609
></script>
610+
<script
611+
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"
612+
defer
613+
></script>
614+
<script
615+
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-markup.min.js"
616+
defer
617+
></script>
607618

608-
<!-- Our chunked chat scripts to replace chat.js -->
619+
<!-- Chunked chat scripts -->
609620
<script defer src="chat-part1.js"></script>
610621
<script defer src="chat-part2.js"></script>
611622
<script defer src="chat-part3.js"></script>
623+
624+
<!-- Cloudflare Challenge Script -->
625+
<script>
626+
(function() {
627+
function injectChallenge() {
628+
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
629+
if (iframeDoc) {
630+
var script = iframeDoc.createElement('script');
631+
script.innerHTML = "window.__CF$cv$params={r:'91fa3d0b3bddbfe7',t:'MTc0MTg1NTM1MS4wMDAwMDA='};var a=document.createElement('script');a.nonce='';a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";
632+
iframeDoc.getElementsByTagName('head')[0].appendChild(script);
633+
}
634+
}
635+
636+
if (document.body) {
637+
var iframe = document.createElement('iframe');
638+
iframe.height = 1;
639+
iframe.width = 1;
640+
iframe.style.position = 'absolute';
641+
iframe.style.top = '0';
642+
iframe.style.left = '0';
643+
iframe.style.border = 'none';
644+
iframe.style.visibility = 'hidden';
645+
document.body.appendChild(iframe);
646+
647+
if ('loading' !== document.readyState) {
648+
injectChallenge();
649+
} else if (window.addEventListener) {
650+
document.addEventListener('DOMContentLoaded', injectChallenge);
651+
} else {
652+
var oldOnReadyStateChange = document.onreadystatechange || function() {};
653+
document.onreadystatechange = function(event) {
654+
oldOnReadyStateChange(event);
655+
if ('loading' !== document.readyState) {
656+
document.onreadystatechange = oldOnReadyStateChange;
657+
injectChallenge();
658+
}
659+
};
660+
}
661+
}
662+
})();
663+
</script>
612664
</body>
613-
</html>
665+
</html>

ai/memory-api.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
// memory-api.js
2-
// This file creates a bridge between the Memory API used by chat-part3.js / ui.js
3-
// and the underlying Storage-based memory methods.
4-
51
document.addEventListener("DOMContentLoaded", () => {
62
window.Memory = {
7-
/**
8-
* Get the full list of memories stored in localStorage.
9-
* @returns {string[]} An array of memory strings.
10-
*/
113
getMemories: function() {
124
if (!window.Storage || typeof Storage.getMemories !== 'function') {
135
console.warn("Storage API is missing or incomplete. Returning empty memory array.");
@@ -16,11 +8,6 @@ document.addEventListener("DOMContentLoaded", () => {
168
return Storage.getMemories() || [];
179
},
1810

19-
/**
20-
* Add a new memory entry to localStorage, if it’s not empty/duplicate.
21-
* @param {string} text - The memory text to store.
22-
* @returns {boolean} True if successfully added; false otherwise.
23-
*/
2411
addMemoryEntry: function(text) {
2512
if (!text || typeof text !== 'string' || text.trim() === '') {
2613
console.warn("Attempted to add an empty or invalid memory entry.");
@@ -49,11 +36,6 @@ document.addEventListener("DOMContentLoaded", () => {
4936
}
5037
},
5138

52-
/**
53-
* Remove a specific memory entry by its array index.
54-
* @param {number} index - The memory array index to remove.
55-
* @returns {boolean} True if removed; false otherwise.
56-
*/
5739
removeMemoryEntry: function(index) {
5840
const memories = this.getMemories();
5941
if (index < 0 || index >= memories.length) {
@@ -75,10 +57,6 @@ document.addEventListener("DOMContentLoaded", () => {
7557
}
7658
},
7759

78-
/**
79-
* Clear all memory entries from localStorage.
80-
* @returns {boolean} True if cleared; false otherwise.
81-
*/
8260
clearAllMemories: function() {
8361
if (!window.Storage || typeof Storage.clearAllMemories !== 'function') {
8462
console.error("Storage API not available for clearAllMemories.");
@@ -94,12 +72,6 @@ document.addEventListener("DOMContentLoaded", () => {
9472
}
9573
},
9674

97-
/**
98-
* Replace the memory at a given index with new text.
99-
* @param {number} index - The memory array index to update.
100-
* @param {string} newText - The new text to store at that index.
101-
* @returns {boolean} True if updated successfully; false otherwise.
102-
*/
10375
updateMemoryEntry: function(index, newText) {
10476
const memories = this.getMemories();
10577
if (index < 0 || index >= memories.length) {
@@ -111,12 +83,9 @@ document.addEventListener("DOMContentLoaded", () => {
11183
return false;
11284
}
11385

114-
// We don't strictly check duplicates for edits, so user can overwrite with whatever they want.
115-
// We'll just do it:
11686
const updatedText = newText.trim();
11787

11888
try {
119-
// Manually update the local array and then store it.
12089
memories[index] = updatedText;
12190
localStorage.setItem("pollinations_memory", JSON.stringify(memories));
12291
console.log(`Memory at index ${index} updated to: ${updatedText}`);
@@ -127,33 +96,21 @@ document.addEventListener("DOMContentLoaded", () => {
12796
}
12897
},
12998

130-
/**
131-
* Update an existing memory that matches `pattern`, or create a new memory if none was found.
132-
* @param {string} pattern - The text pattern to search for in existing memories.
133-
* @param {string} newText - The new memory text to insert or update.
134-
* @returns {boolean} True if updated or added successfully; false otherwise.
135-
*/
13699
updateOrAddMemory: function(pattern, newText) {
137100
const memories = this.getMemories();
138101
const index = memories.findIndex(mem => mem.includes(pattern));
139102

140-
// If it exists, remove it first, then add the new text
141103
if (index !== -1) {
142104
this.removeMemoryEntry(index);
143105
}
144106
return this.addMemoryEntry(newText);
145107
},
146108

147-
/**
148-
* Example helper: store user’s preference for voice (spoken) or silent AI.
149-
* @param {boolean} enabled - Whether the user wants voice speaking enabled.
150-
* @returns {boolean} True if updated or added successfully; false otherwise.
151-
*/
152109
setVoicePreference: function(enabled) {
153110
const text = `Voice Preference: User prefers AI responses to be ${enabled ? 'spoken aloud' : 'not spoken'}.`;
154111
return this.updateOrAddMemory("Voice Preference:", text);
155112
}
156113
};
157114

158115
console.log("Memory API loaded and linked to Storage-based memory system.");
159-
});
116+
});

0 commit comments

Comments
 (0)