mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
perf: tool promot and reg slice;query extension prompt (#1576)
This commit is contained in:
@@ -64,4 +64,22 @@ export const getNanoid = (size = 12) => {
|
||||
return `${firstChar}${randomsStr}`;
|
||||
};
|
||||
|
||||
/* Custom text to reg, need to replace special chats */
|
||||
export const replaceRegChars = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
|
||||
/* slice json str */
|
||||
export const sliceJsonStr = (str: string) => {
|
||||
str = str.replace(/(\\n|\\)/g, '').replace(/ /g, '');
|
||||
|
||||
const jsonRegex = /{[^{}]*}/g;
|
||||
const matches = str.match(jsonRegex);
|
||||
|
||||
if (!matches) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// 找到第一个完整的 JSON 字符串
|
||||
const jsonStr = matches[0];
|
||||
|
||||
return jsonStr;
|
||||
};
|
||||
|
Reference in New Issue
Block a user