mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
feat: sandbox support str to base64 function;feat: compiance text ui (#2702)
* feat: sandbox strToBase64 function * feat: compiance text ui
This commit is contained in:
@@ -18,7 +18,8 @@ weight: 813
|
||||
1.
|
||||
2. 新增 - 聊天记录滚动加载,不再只加载 30 条。
|
||||
3. 新增 - 工作流增加触摸板优先模式。
|
||||
4. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
|
||||
4. 新增 - 沙盒增加字符串转 base64 全局方法。
|
||||
5. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
|
||||
5. 优化 - 工作流 handler 性能优化。
|
||||
6. 优化 - 工作流快捷键,避免调试测试时也会触发。
|
||||
7. 优化 - 流输出,切换 tab 时仍可以继续输出。
|
||||
|
@@ -1,15 +1,6 @@
|
||||
import { useSpeech } from '@/web/common/hooks/useSpeech';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import {
|
||||
Box,
|
||||
CircularProgress,
|
||||
CircularProgressLabel,
|
||||
Flex,
|
||||
HStack,
|
||||
Image,
|
||||
Spinner,
|
||||
Textarea
|
||||
} from '@chakra-ui/react';
|
||||
import { Box, CircularProgress, Flex, HStack, Image, Spinner, Textarea } from '@chakra-ui/react';
|
||||
import React, { useRef, useEffect, useCallback, useMemo } from 'react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
@@ -38,7 +29,7 @@ import { clone } from 'lodash';
|
||||
import { formatFileSize } from '@fastgpt/global/common/file/tools';
|
||||
import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
import ComplianceTip from '@/components/support/compliance/ComplianceTip';
|
||||
import ComplianceTip from '@/components/common/ComplianceTip/index';
|
||||
|
||||
const InputGuideBox = dynamic(() => import('./InputGuideBox'));
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import Markdown from '@/components/Markdown';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
import AIResponseBox from '../../../components/AIResponseBox';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import ComplianceTip from '@/components/support/compliance/ComplianceTip';
|
||||
import ComplianceTip from '@/components/common/ComplianceTip/index';
|
||||
const RenderOutput = () => {
|
||||
const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v);
|
||||
const { t } = useTranslation();
|
||||
|
@@ -20,7 +20,7 @@ import AIModelSelector from '@/components/Select/AIModelSelector';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import { useSystem } from '@fastgpt/web/hooks/useSystem';
|
||||
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
|
||||
import ComplianceTip from '@/components/support/compliance/ComplianceTip';
|
||||
import ComplianceTip from '@/components/common/ComplianceTip/index';
|
||||
|
||||
export type CreateDatasetType =
|
||||
| DatasetTypeEnum.dataset
|
||||
|
5
projects/sandbox/src/sandbox/jsFn/str2Base64.ts
Normal file
5
projects/sandbox/src/sandbox/jsFn/str2Base64.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const strToBase64 = (str: string, prefix: string) => {
|
||||
const base64_string = Buffer.from(str, 'utf-8').toString('base64');
|
||||
|
||||
return `${prefix}${base64_string}`;
|
||||
};
|
@@ -2,13 +2,18 @@ import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto'
|
||||
import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm';
|
||||
import { countToken } from './jsFn/tiktoken';
|
||||
import { timeDelay } from './jsFn/delay';
|
||||
import { strToBase64 } from './jsFn/str2Base64';
|
||||
|
||||
const CustomLogStr = 'CUSTOM_LOG';
|
||||
|
||||
/*
|
||||
Rewrite code to add custom functions: Promise function; Log.
|
||||
*/
|
||||
*/
|
||||
function getFnCode(code: string) {
|
||||
// rewrite log
|
||||
code = code.replace(/console\.log/g, `${CustomLogStr}`);
|
||||
|
||||
// Promise function rewrite
|
||||
const rewriteSystemFn = `
|
||||
const thisDelay = (...args) => global_delay.applySyncPromise(undefined,args)
|
||||
`;
|
||||
@@ -16,9 +21,6 @@ function getFnCode(code: string) {
|
||||
// rewrite delay
|
||||
code = code.replace(/delay\((.*)\)/g, `thisDelay($1)`);
|
||||
|
||||
// rewrite log
|
||||
code = code.replace(/console\.log/g, `${CustomLogStr}`);
|
||||
|
||||
const runCode = `
|
||||
(async() => {
|
||||
try {
|
||||
@@ -35,11 +37,12 @@ function getFnCode(code: string) {
|
||||
return runCode;
|
||||
}
|
||||
|
||||
// Register global function
|
||||
function registerSystemFn(jail: IsolatedVM.Reference<Record<string | number | symbol, any>>) {
|
||||
return Promise.all([
|
||||
// delay
|
||||
jail.set('global_delay', new Reference(timeDelay)),
|
||||
jail.set('countToken', countToken)
|
||||
jail.set('countToken', countToken),
|
||||
jail.set('strToBase64', strToBase64)
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user