Browse Source

Electron Packaging + OpenAI Client functions optimization

pull/173/head
Dani Goland 1 year ago
parent
commit
07d94746e9
  1. 2
      installer/client/gui/.gitignore
  2. 7
      installer/client/gui/chatgpt.js
  3. 5
      installer/client/gui/main.js
  4. 7497
      installer/client/gui/package-lock.json
  5. 59
      installer/client/gui/package.json

2
installer/client/gui/.gitignore vendored

@ -1,3 +1,5 @@
node_modules/ node_modules/
dist/ dist/
build/ build/
out/

7
installer/client/gui/chatgpt.js

@ -3,7 +3,7 @@ require("dotenv").config({
path: require("os").homedir() + "/.config/fabric/.env", path: require("os").homedir() + "/.config/fabric/.env",
}); });
let openaiClient = null; let openAIClient = null;
// Function to initialize and get the OpenAI client // Function to initialize and get the OpenAI client
function getOpenAIClient() { function getOpenAIClient() {
@ -12,7 +12,10 @@ function getOpenAIClient() {
"The OPENAI_API_KEY environment variable is missing or empty." "The OPENAI_API_KEY environment variable is missing or empty."
); );
} }
return new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); if(!openAIClient){
openAIClient = new OpenAI({apiKey: process.env.OPENAI_API_KEY});
}
return openAIClient
} }
async function queryOpenAI(system, user, callback) { async function queryOpenAI(system, user, callback) {

5
installer/client/gui/main.js

@ -16,6 +16,10 @@ const unzipper = require("unzipper");
let win; let win;
const iconPath = process.platform === 'darwin' ? 'assets/logo.icns' :
process.platform === 'win32' ? 'assets/logo.ico' :
'assets/logo.png';
function promptUserForApiKey() { function promptUserForApiKey() {
// Create a new window to prompt the user for the API key // Create a new window to prompt the user for the API key
const promptWindow = new BrowserWindow({ const promptWindow = new BrowserWindow({
@ -161,6 +165,7 @@ function createWindow() {
win = new BrowserWindow({ win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
icon: path.join(__dirname, iconPath),
webPreferences: { webPreferences: {
contextIsolation: true, contextIsolation: true,
nodeIntegration: false, nodeIntegration: false,

7497
installer/client/gui/package-lock.json generated

File diff suppressed because it is too large Load Diff

59
installer/client/gui/package.json

@ -1,22 +1,71 @@
{ {
"name": "fabric_electron", "name": "fabric",
"version": "1.0.0", "version": "1.0.0",
"description": "a fabric electron app", "description": "a fabric electron app",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"start": "electron ." "start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"config": {
"forge": {
"packagerConfig": {
"icon": "assets/logo.icns"
},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "fabric"
}
},
{
"name": "@electron-forge/maker-dmg",
"config": {
"format": "ULFO",
"name": "fabric",
"icon": "assets/logo.icns"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
},
"devDependencies": { "devDependencies": {
"dotenv": "^16.4.1", "@electron-forge/cli": "^7.3.0",
"electron": "^28.2.2", "@electron-forge/maker-deb": "^7.3.0",
"openai": "^4.27.0" "@electron-forge/maker-dmg": "^7.3.0",
"@electron-forge/maker-rpm": "^7.3.0",
"@electron-forge/maker-squirrel": "^7.3.0",
"@electron-forge/maker-zip": "^7.3.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.3.0",
"@electron-forge/plugin-fuses": "^7.3.0",
"electron": "^28.2.2"
}, },
"dependencies": { "dependencies": {
"axios": "^1.6.7", "axios": "^1.6.7",
"dotenv": "^16.4.1",
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^11.2.0",
"mammoth": "^1.6.0", "mammoth": "^1.6.0",
"node-fetch": "^2.6.7", "node-fetch": "^2.6.7",
"openai": "^4.27.0",
"pdf-parse": "^1.1.1", "pdf-parse": "^1.1.1",
"unzipper": "^0.10.14" "unzipper": "^0.10.14"
} }

Loading…
Cancel
Save