Create dropdown box to select which model to use in the GUI on startup

This commit is contained in:
Wizzard 2024-03-09 05:43:40 -05:00
parent e5419b0108
commit 437831aea5
6 changed files with 54 additions and 9 deletions

View File

@ -72,6 +72,37 @@ body {
background-color: #2980b9; background-color: #2980b9;
color: #ecf0f1; color: #ecf0f1;
} }
#modelSelectionContainer {
margin-bottom: 20px;
color: #ecf0f1;
}
#modelSelect {
padding: 10px;
border: 1px solid #34495e;
border-radius: 5px;
background-color: #2c3e50;
color: #ecf0f1;
font-family: Arial, sans-serif;
cursor: pointer;
}
#modelSelect:focus {
outline: none;
border-color: #2980b9;
}
label {
color: #ecf0f1;
margin-right: 10px;
}
#modelSelectionContainer {
display: flex;
align-items: center;
justify-content: start;
gap: 10px;
margin-bottom: 10px;
}
@keyframes ellipsis { @keyframes ellipsis {
0%, 20% { 0%, 20% {
content: ''; content: '';

View File

@ -10,6 +10,13 @@
<header> <header>
<h1>Welcome to Kuzco Chat</h1> <h1>Welcome to Kuzco Chat</h1>
</header> </header>
<div id="modelSelectionContainer">
<label for="modelSelect">Choose AI Model:</label>
<select id="modelSelect">
<option value="mistral">Mistral</option>
<option value="llama2">Llama2</option>
</select>
</div>
<main id="chatHistory" class="chat-history"> <main id="chatHistory" class="chat-history">
</main> </main>
<footer> <footer>

View File

@ -72,6 +72,7 @@ app.on('window-all-closed', () => {
const kuzcoCore = new KuzcoCore(); const kuzcoCore = new KuzcoCore();
ipcMain.handle('send-prompt', async (event, prompt) => { ipcMain.handle('send-prompt', async (event, { prompt, model }) => {
return await kuzcoCore.sendPrompt(prompt); console.log("Received model in main process:", model);
}); return await kuzcoCore.sendPrompt(prompt, model);
});

View File

@ -36,7 +36,8 @@ class KuzcoCore {
return fs.existsSync(this.configPath) && this.API_KEY !== ''; return fs.existsSync(this.configPath) && this.API_KEY !== '';
} }
async sendPrompt(prompt) { async sendPrompt(prompt, model) {
console.log("Model received in sendPrompt:", model)
try { try {
const response = await fetch('https://relay.kuzco.xyz/v1/chat/completions', { const response = await fetch('https://relay.kuzco.xyz/v1/chat/completions', {
method: 'POST', method: 'POST',
@ -46,7 +47,7 @@ class KuzcoCore {
}, },
body: JSON.stringify({ body: JSON.stringify({
messages: [{ role: 'user', 'content': prompt + '\n' }], messages: [{ role: 'user', 'content': prompt + '\n' }],
model: 'mistral', model: model,
stream: false, stream: false,
}), }),
}); });

View File

@ -1,6 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron'); const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
sendPrompt: (prompt) => ipcRenderer.invoke('send-prompt', prompt), sendPrompt: (prompt, model) => ipcRenderer.invoke('send-prompt', { prompt, model }),
onApiKeySaved: (callback) => ipcRenderer.on('api-key-saved', callback), onApiKeySaved: (callback) => ipcRenderer.on('api-key-saved', callback),
}); });

View File

@ -17,13 +17,18 @@ function displayMessage(message, sender) {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const chatForm = document.getElementById('chatForm'); const chatForm = document.getElementById('chatForm');
const promptInput = document.getElementById('promptInput'); const promptInput = document.getElementById('promptInput');
const modelSelect = document.getElementById('modelSelect');
const sendButton = document.getElementById('sendButton'); const sendButton = document.getElementById('sendButton');
const modelSelectionContainer = document.getElementById('modelSelectionContainer');
if (chatForm && promptInput) { if (chatForm && promptInput && modelSelect) {
chatForm.addEventListener('submit', async (event) => { chatForm.addEventListener('submit', async (event) => {
event.preventDefault(); event.preventDefault();
const userInput = promptInput.value; const userInput = promptInput.value;
const selectedModel = modelSelect.value;
promptInput.value = ''; promptInput.value = '';
modelSelectionContainer.style.display = 'none';
sendButton.disabled = true; sendButton.disabled = true;
promptInput.disabled = true; promptInput.disabled = true;
@ -33,7 +38,7 @@ document.addEventListener('DOMContentLoaded', () => {
const typingIndicator = displayTypingIndicator(); const typingIndicator = displayTypingIndicator();
try { try {
const response = await window.electronAPI.sendPrompt(userInput); const response = await window.electronAPI.sendPrompt(userInput, selectedModel);
const assistantMessage = response.choices[0].message.content.trim(); const assistantMessage = response.choices[0].message.content.trim();
displayMessage(assistantMessage, 'assistant'); displayMessage(assistantMessage, 'assistant');
} catch (error) { } catch (error) {