4.6.4-alpha (#582)

This commit is contained in:
Archer
2023-12-08 15:01:11 +08:00
committed by GitHub
parent 54d52d8d25
commit b58249fc3a
66 changed files with 962 additions and 527 deletions

View File

@@ -1,8 +1,8 @@
import { GET, POST, PUT, DELETE } from '@/web/common/api/request';
import type { UploadImgProps } from '@fastgpt/global/common/file/api.d';
import { AxiosProgressEvent } from 'axios';
export const postUploadImg = (base64Img: string, expiredTime?: Date) =>
POST<string>('/common/file/uploadImage', { base64Img, expiredTime });
export const postUploadImg = (e: UploadImgProps) => POST<string>('/common/file/uploadImage', e);
export const postUploadFiles = (
data: FormData,

View File

@@ -1,4 +1,5 @@
import { postUploadImg, postUploadFiles } from '@/web/common/file/api';
import { UploadImgProps } from '@fastgpt/global/common/file/api';
import { BucketNameEnum } from '@fastgpt/global/common/file/constants';
/**
@@ -34,23 +35,24 @@ export const uploadFiles = ({
* @param maxSize The max size of the compressed image
*/
export const compressBase64ImgAndUpload = ({
base64,
base64Img,
maxW = 1080,
maxH = 1080,
maxSize = 1024 * 500, // 300kb
expiredTime
}: {
base64: string;
expiredTime,
metadata,
shareId
}: UploadImgProps & {
maxW?: number;
maxH?: number;
maxSize?: number;
expiredTime?: Date;
}) => {
return new Promise<string>((resolve, reject) => {
const fileType = /^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/.exec(base64)?.[1] || 'image/jpeg';
const fileType =
/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,/.exec(base64Img)?.[1] || 'image/jpeg';
const img = new Image();
img.src = base64;
img.src = base64Img;
img.onload = async () => {
let width = img.width;
let height = img.height;
@@ -86,7 +88,12 @@ export const compressBase64ImgAndUpload = ({
}
try {
const src = await postUploadImg(compressedDataUrl, expiredTime);
const src = await postUploadImg({
shareId,
base64Img: compressedDataUrl,
expiredTime,
metadata
});
resolve(src);
} catch (error) {
reject(error);
@@ -100,18 +107,20 @@ export const compressImgFileAndUpload = async ({
maxW,
maxH,
maxSize,
expiredTime
expiredTime,
shareId
}: {
file: File;
maxW?: number;
maxH?: number;
maxSize?: number;
expiredTime?: Date;
shareId?: string;
}) => {
const reader = new FileReader();
reader.readAsDataURL(file);
const base64 = await new Promise<string>((resolve, reject) => {
const base64Img = await new Promise<string>((resolve, reject) => {
reader.onload = async () => {
resolve(reader.result as string);
};
@@ -122,10 +131,11 @@ export const compressImgFileAndUpload = async ({
});
return compressBase64ImgAndUpload({
base64,
base64Img,
maxW,
maxH,
maxSize,
expiredTime
expiredTime,
shareId
});
};

View File

@@ -107,7 +107,7 @@ export const readPdfContent = (file: File) =>
/**
* read docx to markdown
*/
export const readDocContent = (file: File) =>
export const readDocContent = (file: File, metadata: Record<string, any>) =>
new Promise<string>((resolve, reject) => {
try {
const reader = new FileReader();
@@ -120,7 +120,7 @@ export const readDocContent = (file: File) =>
arrayBuffer: target.result as ArrayBuffer
});
const rawText = await formatMarkdown(res?.value);
const rawText = await formatMarkdown(res?.value, metadata);
resolve(rawText);
} catch (error) {
@@ -173,24 +173,25 @@ export const readCsvContent = async (file: File) => {
* 1. upload base64
* 2. replace \
*/
export const formatMarkdown = async (rawText: string = '') => {
export const formatMarkdown = async (rawText: string = '', metadata: Record<string, any>) => {
// match base64, upload and replace it
const base64Regex = /data:image\/.*;base64,([^\)]+)/g;
const base64Arr = rawText.match(base64Regex) || [];
// upload base64 and replace it
await Promise.all(
base64Arr.map(async (base64) => {
base64Arr.map(async (base64Img) => {
try {
const str = await compressBase64ImgAndUpload({
base64,
base64Img,
maxW: 4329,
maxH: 4329,
maxSize: 1024 * 1024 * 5
maxSize: 1024 * 1024 * 5,
metadata
});
rawText = rawText.replace(base64, str);
rawText = rawText.replace(base64Img, str);
} catch (error) {
rawText = rawText.replace(base64, '');
rawText = rawText.replace(base64Img, '');
rawText = rawText.replace(/!\[.*\]\(\)/g, '');
}
})

View File

@@ -4,7 +4,7 @@ export const useToast = (props?: UseToastOptions) => {
const toast = uToast({
position: 'top',
duration: 2000,
...props
...(props && props)
});
return {

View File

@@ -1,5 +1,6 @@
export enum EventNameEnum {
guideClick = 'guideClick',
sendQuestion = 'sendQuestion',
editQuestion = 'editQuestion',
updaterNode = 'updaterNode'
}
type EventNameType = `${EventNameEnum}`;

View File

@@ -368,20 +368,7 @@ export const appTemplates: (AppItemType & {
type: 'slider',
label: '单次搜索上限',
description: '最多取 n 条记录作为本次问题引用',
value: 5,
min: 1,
max: 20,
step: 1,
markList: [
{
label: '1',
value: 1
},
{
label: '20',
value: 20
}
],
value: 1500,
connected: true
},
{
@@ -1418,22 +1405,9 @@ export const appTemplates: (AppItemType & {
{
key: 'limit',
type: 'slider',
label: '单次搜索上限',
description: '最多取 n 条记录作为本次问题引用',
value: 5,
min: 1,
max: 20,
step: 1,
markList: [
{
label: '1',
value: 1
},
{
label: '20',
value: 20
}
],
label: '引用上限',
description: '单次搜索最大的 Tokens 数量中文约1字=1.7Tokens英文约1字=1Tokens',
value: 1500,
connected: true
},
{

View File

@@ -7,7 +7,8 @@ import type {
getHistoriesProps,
ClearHistoriesProps,
DelHistoryProps,
UpdateHistoryProps
UpdateHistoryProps,
DeleteChatItemProps
} from '@/global/core/chat/api';
import {
delChatHistoryById,
@@ -31,7 +32,7 @@ type State = {
setLastChatAppId: (id: string) => void;
lastChatId: string;
setLastChatId: (id: string) => void;
delOneHistoryItem: (e: { chatId: string; contentId?: string; index: number }) => Promise<any>;
delOneHistoryItem: (e: DeleteChatItemProps & { index: number }) => Promise<any>;
};
export const useChatStore = create<State>()(
@@ -119,7 +120,8 @@ export const useChatStore = create<State>()(
});
}
},
async delOneHistoryItem({ chatId, contentId, index }) {
async delOneHistoryItem({ index, ...props }) {
const { chatId, contentId } = props;
if (!chatId || !contentId) return;
try {
@@ -127,7 +129,7 @@ export const useChatStore = create<State>()(
...state,
history: state.history.filter((_, i) => i !== index)
}));
await delChatRecordById({ chatId, contentId });
await delChatRecordById(props);
} catch (err) {
console.log(err);
}