From 7eb5f953d7e5352abdfc770ce471b4005ed6c88d Mon Sep 17 00:00:00 2001 From: Jonathan Dunn Date: Mon, 1 Apr 2024 09:42:00 -0400 Subject: [PATCH] added functionality to gui to create your own patterns --- installer/client/gui/chatgpt.js | 45 ----- installer/client/gui/index.html | 21 +++ installer/client/gui/main.js | 174 ++++++++++++------ installer/client/gui/static/js/index.js | 83 +++++++-- .../client/gui/static/stylesheet/style.css | 24 +++ 5 files changed, 224 insertions(+), 123 deletions(-) delete mode 100644 installer/client/gui/chatgpt.js diff --git a/installer/client/gui/chatgpt.js b/installer/client/gui/chatgpt.js deleted file mode 100644 index 1fe7c7f..0000000 --- a/installer/client/gui/chatgpt.js +++ /dev/null @@ -1,45 +0,0 @@ -const { OpenAI } = require("openai"); -require("dotenv").config({ - path: require("os").homedir() + "/.config/fabric/.env", -}); - -let openaiClient = null; - -// Function to initialize and get the OpenAI client -function getOpenAIClient() { - if (!process.env.OPENAI_API_KEY) { - throw new Error( - "The OPENAI_API_KEY environment variable is missing or empty." - ); - } - return new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); -} - -async function queryOpenAI(system, user, callback) { - const openai = getOpenAIClient(); // Ensure the client is initialized here - const messages = [ - { role: "system", content: system }, - { role: "user", content: user }, - ]; - try { - const stream = await openai.chat.completions.create({ - model: "gpt-4-1106-preview", // Adjust the model as necessary. - messages: messages, - temperature: 0.0, - top_p: 1, - frequency_penalty: 0.1, - presence_penalty: 0.1, - stream: true, - }); - - for await (const chunk of stream) { - const message = chunk.choices[0]?.delta?.content || ""; - callback(message); // Process each chunk of data - } - } catch (error) { - console.error("Error querying OpenAI:", error); - callback("Error querying OpenAI. Please try again."); - } -} - -module.exports = { queryOpenAI }; diff --git a/installer/client/gui/index.html b/installer/client/gui/index.html index a178e56..b1c1ca2 100644 --- a/installer/client/gui/index.html +++ b/installer/client/gui/index.html @@ -36,6 +36,9 @@ > Update Patterns +
Dark @@ -53,6 +56,24 @@ >
+