fixed stuff in the UI that I did badly...more to come im sure
This commit is contained in:
parent
d1b59367bd
commit
fe74efde71
@ -1,5 +0,0 @@
|
|||||||
import Claude from "claude-ai";
|
|
||||||
|
|
||||||
export function MakeClaude(apiKey) {
|
|
||||||
return new Claude({ sessionKey: apiKey });
|
|
||||||
}
|
|
@ -146,13 +146,20 @@ function saveApiKeys(openAIKey, claudeKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let envContent = "";
|
let envContent = "";
|
||||||
|
|
||||||
|
// Read the existing .env file if it exists
|
||||||
|
if (fs.existsSync(envFilePath)) {
|
||||||
|
envContent = fs.readFileSync(envFilePath, "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the specific API key
|
||||||
if (openAIKey) {
|
if (openAIKey) {
|
||||||
envContent += `OPENAI_API_KEY=${openAIKey}\n`;
|
envContent = updateOrAddKey(envContent, "OPENAI_API_KEY", openAIKey);
|
||||||
process.env.OPENAI_API_KEY = openAIKey; // Set for current session
|
process.env.OPENAI_API_KEY = openAIKey; // Set for current session
|
||||||
openai = new OpenAI({ apiKey: openAIKey });
|
openai = new OpenAI({ apiKey: openAIKey });
|
||||||
}
|
}
|
||||||
if (claudeKey) {
|
if (claudeKey) {
|
||||||
envContent += `CLAUDE_API_KEY=${claudeKey}\n`;
|
envContent = updateOrAddKey(envContent, "CLAUDE_API_KEY", claudeKey);
|
||||||
process.env.CLAUDE_API_KEY = claudeKey; // Set for current session
|
process.env.CLAUDE_API_KEY = claudeKey; // Set for current session
|
||||||
claude = new Anthropic({ apiKey: claudeKey });
|
claude = new Anthropic({ apiKey: claudeKey });
|
||||||
}
|
}
|
||||||
@ -160,6 +167,18 @@ function saveApiKeys(openAIKey, claudeKey) {
|
|||||||
fs.writeFileSync(envFilePath, envContent.trim());
|
fs.writeFileSync(envFilePath, envContent.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateOrAddKey(envContent, keyName, keyValue) {
|
||||||
|
const keyPattern = new RegExp(`^${keyName}=.*$`, "m");
|
||||||
|
if (keyPattern.test(envContent)) {
|
||||||
|
// Update the existing key
|
||||||
|
envContent = envContent.replace(keyPattern, `${keyName}=${keyValue}`);
|
||||||
|
} else {
|
||||||
|
// Add the new key
|
||||||
|
envContent += `\n${keyName}=${keyValue}`;
|
||||||
|
}
|
||||||
|
return envContent;
|
||||||
|
}
|
||||||
|
|
||||||
async function getOllamaModels() {
|
async function getOllamaModels() {
|
||||||
ollama = new Ollama.Ollama();
|
ollama = new Ollama.Ollama();
|
||||||
const _models = await ollama.list();
|
const _models = await ollama.list();
|
||||||
@ -186,11 +205,16 @@ async function getModels() {
|
|||||||
];
|
];
|
||||||
allModels.claudeModels = claudeModels;
|
allModels.claudeModels = claudeModels;
|
||||||
}
|
}
|
||||||
|
let gptModelsPromise = [];
|
||||||
if (keys.openAIKey) {
|
if (keys.openAIKey) {
|
||||||
openai = new OpenAI({ apiKey: keys.openAIKey });
|
openai = new OpenAI({ apiKey: keys.openAIKey });
|
||||||
// Wrap asynchronous call with a Promise to handle it in parallel
|
// Wrap asynchronous call with a Promise to handle it in parallel
|
||||||
gptModelsPromise = openai.models.list();
|
try {
|
||||||
|
gptModelsPromise = openai.models.list();
|
||||||
|
} catch (error) {
|
||||||
|
gptModelsPromise = [];
|
||||||
|
console.error("Error fetching models from OpenAI:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if ollama exists and has a list method
|
// Check if ollama exists and has a list method
|
||||||
|
@ -168,6 +168,13 @@ document.addEventListener("DOMContentLoaded", async function () {
|
|||||||
submitQuery(message);
|
submitQuery(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.electronAPI.on;
|
||||||
|
"reload-app",
|
||||||
|
() => {
|
||||||
|
// Reload the app
|
||||||
|
loadModels();
|
||||||
|
};
|
||||||
|
|
||||||
// Submit button click handler
|
// Submit button click handler
|
||||||
submitButton.addEventListener("click", async () => {
|
submitButton.addEventListener("click", async () => {
|
||||||
const userInputValue = userInput.value;
|
const userInputValue = userInput.value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user