Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

build server into desktop app

Jeffrey Morgand3709f85b5e3
diff --git a/.gitignore b/.gitignore
index e6ff47654..94f1119ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,2 @@
.DS_Store
.vscode
-*.spec
-*/build
-*/dist
-client/resources/server
\ No newline at end of file
diff --git a/client/forge.config.ts b/client/forge.config.ts
index ace7d9005..49e3ae002 100644
--- a/client/forge.config.ts
+++ b/client/forge.config.ts
@@ -13,6 +13,7 @@ const config: ForgeConfig = {
packagerConfig: {
asar: true,
icon: './images/icon',
+ extraResource: ['../server/dist/server'],
},
rebuildConfig: {},
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
diff --git a/client/permissions-plugin.ts b/client/permissions-plugin.ts
deleted file mode 100644
index e65365a55..000000000
--- a/client/permissions-plugin.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import chmodr from 'chmodr'
-import * as path from 'path'
-
-interface PluginOptions {
- resourcePath: string
-}
-
-class PermissionsPlugin {
- options: PluginOptions
-
- constructor(options: PluginOptions) {
- this.options = options
- }
-
- apply(compiler: any) {
- compiler.hooks.afterEmit.tap('PermissionsPlugin', () => {
- chmodr(path.join(this.options.resourcePath), 0o755, err => {
- // this fails on the first call to suppress the error
- })
- })
- }
-}
-
-export default PermissionsPlugin
diff --git a/client/src/app.tsx b/client/src/app.tsx
index bf675ddfc..0c39c86aa 100644
--- a/client/src/app.tsx
+++ b/client/src/app.tsx
@@ -1,6 +1,6 @@
import { useState } from 'react'
-const API_URL = 'http://127.0.0.1:5000'
+const API_URL = 'http://127.0.0.1:5001'
type Message = {
sender: string
diff --git a/client/src/index.ts b/client/src/index.ts
index 0a1ca3d26..4feb0928e 100644
--- a/client/src/index.ts
+++ b/client/src/index.ts
@@ -21,24 +21,32 @@ const createWindow = (): void => {
minWidth: 400,
minHeight: 300,
titleBarStyle: 'hiddenInset',
- // trafficLightPosition: { x: 20, y: 18 },
- // vibrancy: 'titlebar',
transparent: true,
})
+ // and load the index.html of the app.
+ mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
+}
+
+// if the app is packaged then run the server
+if (app.isPackaged) {
+ const resources = process.resourcesPath
+ console.log(resources)
+
// Start the executable
- let pyExecutable = path.join(__dirname, '../renderer/resources/server')
- console.log(`Starting ${pyExecutable}`)
- let pyProcess = spawn(pyExecutable)
- pyProcess.stdout.on('data', data => {
+ const exec = path.join(resources, 'server')
+ console.log(`Starting ${exec}`)
+ const proc = spawn(exec)
+ proc.stdout.on('data', data => {
console.log(`server: ${data}`)
})
- pyProcess.stderr.on('data', data => {
+ proc.stderr.on('data', data => {
console.error(`server: ${data}`)
})
- // and load the index.html of the app.
- mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
+ process.on('exit', () => {
+ proc.kill()
+ })
}
// This method will be called when Electron has finished
diff --git a/client/webpack.plugins.ts b/client/webpack.plugins.ts
index 0e7187f54..ca78adc13 100644
--- a/client/webpack.plugins.ts
+++ b/client/webpack.plugins.ts
@@ -1,19 +1,10 @@
import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
-import * as path from 'path'
-import PermissionsPlugin from './permissions-plugin'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
-const CopyWebpackPlugin = require('copy-webpack-plugin')
export const plugins = [
new ForkTsCheckerWebpackPlugin({
logger: 'webpack-infrastructure',
}),
- new CopyWebpackPlugin({
- patterns: [{ from: 'resources', to: 'resources' }],
- }),
- new PermissionsPlugin({
- resourcePath: '.webpack/renderer/resources/server',
- }),
]
diff --git a/models/.gitignore b/models/.gitignore
new file mode 100644
index 000000000..a8a0dcec4
--- /dev/null
+++ b/models/.gitignore
@@ -0,0 +1 @@
+*.bin
diff --git a/server/.gitignore b/server/.gitignore
new file mode 100644
index 000000000..1b1d3c683
--- /dev/null
+++ b/server/.gitignore
@@ -0,0 +1,5 @@
+.env
+.venv
+*.spec
+build
+dist
diff --git a/server/build.py b/server/build.py
index 38f79652f..f1fecafdc 100644
--- a/server/build.py
+++ b/server/build.py
@@ -1,6 +1,5 @@
import site
import os
-import shutil
from PyInstaller.__main__ import run as pyi_run
# the llama_cpp directory is not included if not explicitly added
@@ -13,10 +12,9 @@ args = [
site_packages_dir,
"--add-data",
f"{llama_cpp_dir}{os.pathsep}llama_cpp",
- "--onefile",
+ "--onefile"
]
# generate the .spec file and run PyInstaller
pyi_run(args)
-shutil.copy2("dist/server", "../client/resources/server")
diff --git a/server/server.py b/server/server.py
index 9fe3fd766..46103a263 100644
--- a/server/server.py
+++ b/server/server.py
@@ -76,4 +76,4 @@ def generate():
if __name__ == "__main__":
- app.run(debug=True, threaded=True, port=5000)
+ app.run(debug=True, threaded=True, port=5001)