1
mirror of https://github.com/cocktailpeanut/dalai synced 2025-03-28 22:43:05 +01:00

fix the https issue

was using webcrypto sha256 to generate unique ID for messages but it was too much hassle when trying to use it on http that's not localhost (such as 0.0.0.0) so just started using timestamp + random number instead.
This commit is contained in:
cocktailpeanut 2023-03-18 01:21:40 -04:00
parent 6145e97138
commit 2cfe069aa2
5 changed files with 40 additions and 42 deletions

@ -180,7 +180,9 @@ form.addEventListener('submit', (e) => {
e.stopPropagation() e.stopPropagation()
if (input.textContent) { if (input.textContent) {
config.prompt = input.textContent config.prompt = input.textContent
config.id = "TS-" + Date.now() + "-" + Math.floor(Math.random() * 100000)
socket.emit('request', config) socket.emit('request', config)
config.id = null
loading(config.prompt) loading(config.prompt)
input.textContent = ""; input.textContent = "";
} }
@ -226,7 +228,7 @@ socket.on('result', async ({ request, response }) => {
} else { } else {
if (response == "\n\n<end>") { if (response == "\n\n<end>") {
} else { } else {
const id = await sha256(request.prompt) const id = request.id
let existing = document.querySelector(`[data-id='${id}']`) let existing = document.querySelector(`[data-id='${id}']`)
if (existing) { if (existing) {
existing.textContent = existing.textContent + response existing.textContent = existing.textContent + response

@ -12,7 +12,7 @@ const { io } = require("socket.io-client");
const term = require( 'terminal-kit' ).terminal; const term = require( 'terminal-kit' ).terminal;
const Downloader = require("nodejs-file-downloader"); const Downloader = require("nodejs-file-downloader");
const semver = require('semver'); const semver = require('semver');
const _7z = require('7zip-min'); //const _7z = require('7zip-min');
const axios = require('axios') const axios = require('axios')
const platform = os.platform() const platform = os.platform()
const shell = platform === 'win32' ? 'powershell.exe' : 'bash'; const shell = platform === 'win32' ? 'powershell.exe' : 'bash';
@ -111,34 +111,34 @@ class Dalai {
console.log("cleaning up temp files") console.log("cleaning up temp files")
await fs.promises.rm(path.resolve(this.home, filename)) await fs.promises.rm(path.resolve(this.home, filename))
} }
async mingw() { // async mingw() {
const mingw = "https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z" // const mingw = "https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"
const downloader = new Downloader({ // const downloader = new Downloader({
url: mingw, // url: mingw,
directory: this.home, // directory: this.home,
onProgress: (percentage, chunk, remainingSize) => { // onProgress: (percentage, chunk, remainingSize) => {
this.progress("download mingw", percentage) // this.progress("download mingw", percentage)
}, // },
}); // });
try { // try {
await this.startProgress("download mingw") // await this.startProgress("download mingw")
await downloader.download(); // await downloader.download();
} catch (error) { // } catch (error) {
console.log(error); // console.log(error);
} // }
this.progressBar.update(1); // this.progressBar.update(1);
await new Promise((resolve, reject) => { // await new Promise((resolve, reject) => {
_7z.unpack(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"), this.home, (err) => { // _7z.unpack(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"), this.home, (err) => {
if (err) { // if (err) {
reject(err) // reject(err)
} else { // } else {
resolve() // resolve()
} // }
}) // })
}) // })
console.log("cleaning up temp files") // console.log("cleaning up temp files")
await fs.promises.rm(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z")) // await fs.promises.rm(path.resolve(this.home, "x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z"))
} // }
async query(req, cb) { async query(req, cb) {
console.log(`> query:`, req) console.log(`> query:`, req)
@ -205,6 +205,11 @@ class Dalai {
} }
} }
async install(core, ...models) { async install(core, ...models) {
const venv_path = path.join(this.home, "venv")
let ve = await exists(venv_path)
if (!ve) {
await this.setup()
}
// first install // first install
let engine = this.cores[core] let engine = this.cores[core]
let e = await exists(path.resolve(engine.home)); let e = await exists(path.resolve(engine.home));

5
package-lock.json generated

@ -1,16 +1,15 @@
{ {
"name": "dalai", "name": "dalai",
"version": "0.2.23", "version": "0.2.26",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "dalai", "name": "dalai",
"version": "0.2.23", "version": "0.2.26",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"7zip-min": "^1.4.4",
"axios": "^1.3.4", "axios": "^1.3.4",
"ejs": "^3.1.8", "ejs": "^3.1.8",
"express": "^4.18.2", "express": "^4.18.2",

@ -1,6 +1,6 @@
{ {
"name": "dalai", "name": "dalai",
"version": "0.2.23", "version": "0.2.26",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"author": "cocktailpeanut", "author": "cocktailpeanut",
@ -16,7 +16,6 @@
"postinstall": "node setup" "postinstall": "node setup"
}, },
"dependencies": { "dependencies": {
"7zip-min": "^1.4.4",
"axios": "^1.3.4", "axios": "^1.3.4",
"ejs": "^3.1.8", "ejs": "^3.1.8",
"express": "^4.18.2", "express": "^4.18.2",

@ -41,13 +41,6 @@
resolved "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.1.1.tgz" resolved "https://registry.npmjs.org/7zip-bin/-/7zip-bin-5.1.1.tgz"
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ== integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
"7zip-min@^1.4.4":
version "1.4.4"
resolved "https://registry.npmjs.org/7zip-min/-/7zip-min-1.4.4.tgz"
integrity sha512-mYB1WW5tcXfZxUN4+2joKk4+6j8jp+mpO2YiMU5z1gNNFbACxI2ADasffsdNPovZSwn/E662ZIH5gRkFPMufmA==
dependencies:
"7zip-bin" "5.1.1"
accepts@~1.3.4, accepts@~1.3.8: accepts@~1.3.4, accepts@~1.3.8:
version "1.3.8" version "1.3.8"
resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz" resolved "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz"