Agent Zero AI framework
Mic js and embedding menu + styles
Alessandrod84469dff6b4
diff --git a/python/helpers/settings.py b/python/helpers/settings.pyindex 045575573..06d9b312e 100644--- a/python/helpers/settings.py+++ b/python/helpers/settings.py@@ -78,7 +78,7 @@ def convert_out(settings: Settings) -> dict[str, Any]:})- chat_model_seciton = {+ chat_model_section = {"title": "Chat Model","description": "Selection and settings for main chat model used by Agent Zero","fields": chat_model_fields,@@ -129,13 +129,51 @@ def convert_out(settings: Settings) -> dict[str, Any]:})- util_model_seciton = {+ util_model_section = {"title": "Utility model","description": "Smaller, cheaper, faster model for handling utility tasks like organizing memory, preparing prompts, summarizing.","fields": util_model_fields,}- result = {"sections": [chat_model_seciton, util_model_seciton]}+ # embedding model section+ embed_model_fields = []+ embed_model_fields.append(+ {+ "id": "embed_model_provider",+ "title": "Embedding model provider",+ "description": "Select provider for embedding model used by the framework",+ "type": "select",+ "value": settings["embed_model_provider"],+ "options": [{"value": p.name, "label": p.value} for p in ModelProvider],+ }+ )+ embed_model_fields.append(+ {+ "id": "embed_model_name",+ "title": "Embedding model name",+ "description": "Exact name of model from selected provider",+ "type": "input",+ "value": settings["embed_model_name"],+ }+ )++ embed_model_fields.append(+ {+ "id": "embed_model_kwargs",+ "title": "Embedding model additional parameters",+ "description": "Any other parameters supported by the model. Format is KEY=VALUE on individual lines, just like .env file.",+ "type": "textarea",+ "value": _dict_to_env(settings["embed_model_kwargs"]),+ }+ )++ embed_model_section = {+ "title": "Embedding Model",+ "description": "Settings for the embedding model used by Agent Zero.",+ "fields": embed_model_fields,+ }++ result = {"sections": [chat_model_section, util_model_section, embed_model_section]}return resultdef convert_in(settings: dict[str, Any]) -> Settings:diff --git a/webui/index.css b/webui/index.cssindex c65bc8730..c9edf4289 100644--- a/webui/index.css+++ b/webui/index.css@@ -371,7 +371,7 @@ pre {display: flex;flex-direction: column;flex-grow: 1;- overflow-y: auto;+ overflow-y: scroll;scroll-behavior: smooth;overflow-x: hidden;padding: var(--spacing-md) var(--spacing-md) 0;@@ -889,6 +889,7 @@ pre {background-color: var(--color-primary-light);}+/* MIC BUTTON */#microphone-button {background-color: #3270e2;}@@ -896,6 +897,9 @@ pre {#microphone-button:hover {background-color: #4382e8;}+#microphone-button.recording {+ background-color: #ff4136; /* Red color for recording */+}.chat-button svg {width: 1.5rem;diff --git a/webui/index.html b/webui/index.htmlindex b14877aa7..d20a1903c 100644--- a/webui/index.html+++ b/webui/index.html@@ -236,17 +236,19 @@<!-- Microphone button --><button class="chat-button" id="microphone-button" aria-label="Start/Stop recording">- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="24" height="24">- <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1 1.9c-2.7-.4-4.8-2.6-5-5.4h-2c.2 3.8 3.1 6.9 7 7.5V20h2v-2.6c3.9-.6 6.8-3.7 7-7.5h-2c-.2 2.8-2.3 5-5 5.4V15z"/>+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 18" fill="currentColor" width="24" height="24">+ <path d="m8,12c1.66,0,3-1.34,3-3V3c0-1.66-1.34-3-3-3s-3,1.34-3,3v6c0,1.66,1.34,3,3,3Zm-1,1.9c-2.7-.4-4.8-2.6-5-5.4H0c.2,3.8,3.1,6.9,7,7.5v2h2v-2c3.9-.6,6.8-3.7,7-7.5h-2c-.2,2.8-2.3,5-5,5.4h-2Z"/></svg>+</button>- </div>++ </div></div><!-- Bottom row with text buttons --><div class="text-buttons-row"><button class="text-button"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5"></path></svg>Import knowledge</button>- <button class="text-button"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 122.88 89.09"><g><path stroke-width="3.5" stroke="currentColor" fill="none" d="M3.97,9.75l-3.93,8.73l122.77,0.01l-3.96-8.74H55.82c-1.59,0-2.88-1.29-2.88-2.88V0H11.97v6.87 c0,1.59-1.29,2.88-2.88,2.88H3.97L3.97,9.75L3.97,9.75z"></path><path stroke-width="3.5" stroke="currentColor" fill="none" d="M4.63,18.48H0l7.03,67.03c0.11,1.07,0.55,2.02,1.2,2.69c0.55,0.55,1.28,0.89,2.11,0.89h100.1 c0.82,0,1.51-0.33,2.05-0.87c0.68-0.68,1.13-1.67,1.28-2.79l9.1-66.94H4.63V18.48L4.63,18.48z"></path></g></svg>work_dir Browser</button>+ <button class="text-button"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 122.88 89.09"><g><path stroke-width="3.5" stroke="currentColor" fill="none" d="M3.97,9.75l-3.93,8.73l122.77,0.01l-3.96-8.74H55.82c-1.59,0-2.88-1.29-2.88-2.88V0H11.97v6.87 c0,1.59-1.29,2.88-2.88,2.88H3.97L3.97,9.75L3.97,9.75z"></path><path stroke-width="3.5" stroke="currentColor" fill="none" d="M4.63,18.48H0l7.03,67.03c0.11,1.07,0.55,2.02,1.2,2.69c0.55,0.55,1.28,0.89,2.11,0.89h100.1 c0.82,0,1.51-0.33,2.05-0.87c0.68-0.68,1.13-1.67,1.28-2.79l9.1-66.94H4.63V18.48L4.63,18.48z"></path></g></svg>work_dir Browser</button><button class="text-button" @click="pauseAgent(!paused)"><!-- Dynamic path that switches between pause and play icons --><template x-if="!paused">diff --git a/webui/index.js b/webui/index.jsindex 19ec79277..df5ac7beb 100644--- a/webui/index.js+++ b/webui/index.js@@ -12,11 +12,13 @@ const chatsSection = document.getElementById('chats-section');const scrollbarThumb = document.querySelector('#chat-history::-webkit-scrollbar-thumb');const progressBar = document.getElementById('progress-bar');const autoScrollSwitch = document.getElementById('auto-scroll-switch');-+const microphoneButton = document.getElementById('microphone-button');let autoScroll = true;let context = "";+let microphoneInput = null;+// Initialize the toggle buttonsetupSidebarToggle();@@ -95,6 +97,59 @@ chatInput.addEventListener('keydown', (e) => {sendButton.addEventListener('click', sendMessage);++// MICROPHONE INPUT++async function initializeMicrophoneInput() {+ microphoneInput = new MicrophoneInput(updateChatInput);+ await microphoneInput.initialize();+}+function updateChatInput(text) {+ chatInput.value += text + ' ';+ adjustTextareaHeight();+}+microphoneButton.addEventListener('click', () => {+ if (!microphoneInput) {+ initializeMicrophoneInput().then(() => {+ toggleRecording();+ });+ } else {+ toggleRecording();+ }+});+function toggleRecording() {+ if (microphoneInput.isRecording) {+ microphoneInput.stopRecording();+ microphoneButton.classList.remove('recording');+ } else {+ microphoneInput.startRecording();+ microphoneButton.classList.add('recording');+ }+}+// Some error handling for microphone input+async function requestMicrophonePermission() {+ try {+ await navigator.mediaDevices.getUserMedia({ audio: true });+ return true;+ } catch (err) {+ console.error('Error accessing microphone:', err);+ toast('Microphone access denied. Please enable microphone access in your browser settings.', 'error');+ return false;+ }+}+// microphoneButton click event listener modifier+microphoneButton.addEventListener('click', async () => {+ const hasPermission = await requestMicrophonePermission();+ if (!hasPermission) return;+ if (!microphoneInput) {+ initializeMicrophoneInput().then(() => {+ toggleRecording();+ });+ } else {+ toggleRecording();+ }+});+function updateUserTime() {const now = new Date();const hours = now.getHours();@@ -142,8 +197,9 @@ function setMessage(id, type, heading, content, temp, kvps = null) {if (!document.getElementById(`message-${id}`)) {chatHistory.appendChild(messageContainer);}-- if (autoScroll) chatHistory.scrollTop = chatHistory.scrollHeight;++ // Remove the automatic scrolling+ // if (autoScroll) chatHistory.scrollTop = chatHistory.scrollHeight;}@@ -181,31 +237,29 @@ let lastLogVersion = 0;let lastLogGuid = ""async function poll() {- let updated = false+ let updated = false;try {const response = await sendJsonData("/poll", { log_from: lastLogVersion, context });- //console.log(response)if (response.ok) {-- if (!context) setContext(response.context)- if (response.context != context) return //skip late polls after context change+ if (!context) setContext(response.context);+ if (response.context != context) return; // Skip if context changedif (lastLogGuid != response.log_guid) {- chatHistory.innerHTML = ""- lastLogVersion = 0+ chatHistory.innerHTML = "";+ lastLogVersion = 0;}if (lastLogVersion != response.log_version) {- updated = true+ updated = true;for (const log of response.logs) {setMessage(log.no, log.type, log.heading, log.content, log.temp, log.kvps);}}- updateProgress(response.log_progress)+ updateProgress(response.log_progress);- //set ui model vars from backend+ // Set UI model vars from backendconst inputAD = Alpine.$data(inputSection);inputAD.paused = response.paused;const statusAD = Alpine.$data(statusSection);@@ -215,17 +269,22 @@ async function poll() {lastLogVersion = response.log_version;lastLogGuid = response.log_guid;--}-} catch (error) {console.error('Error:', error);const statusAD = Alpine.$data(statusSection);statusAD.connected = false;}- return updated+ if (updated && autoScroll) {+ const lastMessage = chatHistory.lastElementChild;+ if (lastMessage) {+ // Scroll the last message into view+ lastMessage.scrollIntoView({ behavior: 'auto' });+ }+ }++ return updated;}function updateProgress(progress) {@@ -289,8 +348,17 @@ window.killChat = async function (id) {}window.selectChat = async function (id) {- setContext(id)- updateAfterScroll()+ setContext(id);+ updateAfterScroll();++ // Optionally, wait for poll to load messages and then scroll+ const updated = await poll();+ if (updated && autoScroll) {+ const lastMessage = chatHistory.lastElementChild;+ if (lastMessage) {+ lastMessage.scrollIntoView({ behavior: 'auto' });+ }+ }}const setContext = function (id) {