Skip to content

Commit

Permalink
getApp
Browse files Browse the repository at this point in the history
  • Loading branch information
chatbookai committed Jun 2, 2024
1 parent 01e8322 commit efbcc1a
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 202 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added express/demo/avatarforapp/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
442 changes: 243 additions & 199 deletions express/src/utils/app.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions express/src/utils/db.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion express/src/utils/llms.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ let ChatBaiduWenxinModel = null
ChatOpenAIModel = new ChatOpenAI({
modelName: "gpt-3.5-turbo",
openAIApiKey: OPENAI_API_KEY,
temperature: temperature(temperature ?? 0.5),
temperature: temperature ?? 0.5,
streaming: true,
});
}
Expand Down
51 changes: 51 additions & 0 deletions express/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,49 @@ export function enableDir(directoryPath) {
}
}

export function copyFolderRecursiveSync(source, target) {
let files = [];

const targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder);
}

if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source);
files.forEach((file) => {
const curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync2(curSource, targetFolder);
}
});
}
}

export function isFolderEmptySync(folderPath) {
try {
const files = fs.readdirSync(folderPath);
return files.length === 0;
} catch (err) {
console.error('Error reading the folder:', err);
return false;
}
}

function copyFileSync2(source, target) {
let targetFile = target;

if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source));
}
}

fs.writeFileSync(targetFile, fs.readFileSync(source));
}

export async function getLLMSSetting(datasetId) {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()

Expand Down Expand Up @@ -105,6 +148,7 @@ export async function setTemplate(Params) {
}

export function uploadfiles() {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, DataDir + '/uploadfiles/'); // 设置上传文件保存的目录
Expand All @@ -121,6 +165,7 @@ export function uploadfiles() {
}

export function uploadavatar() {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, DataDir + '/avatarforapp/'); // 设置上传文件保存的目录
Expand All @@ -138,6 +183,7 @@ export function uploadavatar() {
}

export function uploadAvatarForDataset() {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, DataDir + '/avatarfordataset/'); // 设置上传文件保存的目录
Expand All @@ -155,6 +201,7 @@ export function uploadAvatarForDataset() {
}

export function uploadImageForVideo() {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, DataDir + '/imageforvideo/'); // 设置上传文件保存的目录
Expand All @@ -172,6 +219,7 @@ export function uploadImageForVideo() {
}

export function uploadImageForImageGenerateImage() {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, DataDir + '/imageforimage/'); // 设置上传文件保存的目录
Expand All @@ -189,6 +237,7 @@ export function uploadImageForImageGenerateImage() {
}

export async function uploadfilesInsertIntoDb(files, datasetId, userId) {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const filesInfo = files.map((file) => {
const filePath = path.join(DataDir, 'uploadfiles', file.filename);
const fileHash = calculateFileHashSync(filePath);
Expand Down Expand Up @@ -424,6 +473,7 @@ export function calculateFileHashSync(filePath) {
}

export function readFile(Dir, FileName, Mark, OpenFormat) {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const filePath = DataDir + '/' + Dir + '/' + FileName;
if(isFile(filePath)) {
console.log("filePath", filePath)
Expand All @@ -439,6 +489,7 @@ export function readFile(Dir, FileName, Mark, OpenFormat) {
}

export function writeFile(Dir, FileName, FileContent, Mark) {
const { DataDir, db, getDbRecord, getDbRecordALL } = ChatBookDbPool()
const directoryPath = DataDir + '/' + Dir;
enableDir(directoryPath)
const TxFilePath = directoryPath + "/" + FileName
Expand Down

0 comments on commit efbcc1a

Please sign in to comment.