mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 15:41:05 +00:00
Fix some bug (#5048)
* fix: chat log time range * fix: repeat system prompt * perf: nanoid random * fix: get files from histories * fix: ts * ts config * perf: search dataset collection
This commit is contained in:
@@ -8,12 +8,12 @@ import {
|
||||
FlowNodeOutputTypeEnum,
|
||||
FlowNodeTypeEnum
|
||||
} from '../../workflow/node/constant';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { type McpToolConfigType } from '../type';
|
||||
import { i18nT } from '../../../../web/i18n/utils';
|
||||
import { type RuntimeNodeItemType } from '../../workflow/runtime/type';
|
||||
import { type StoreSecretValueType } from '../../../common/secret/type';
|
||||
import { jsonSchema2NodeInput } from '../jsonschema';
|
||||
import { getNanoid } from '../../../common/string/tools';
|
||||
|
||||
export const getMCPToolSetRuntimeNode = ({
|
||||
url,
|
||||
@@ -29,7 +29,7 @@ export const getMCPToolSetRuntimeNode = ({
|
||||
avatar?: string;
|
||||
}): RuntimeNodeItemType => {
|
||||
return {
|
||||
nodeId: nanoid(16),
|
||||
nodeId: getNanoid(16),
|
||||
flowNodeType: FlowNodeTypeEnum.toolSet,
|
||||
avatar,
|
||||
intro: 'MCP Tools',
|
||||
@@ -64,7 +64,7 @@ export const getMCPToolRuntimeNode = ({
|
||||
avatar?: string;
|
||||
}): RuntimeNodeItemType => {
|
||||
return {
|
||||
nodeId: nanoid(16),
|
||||
nodeId: getNanoid(16),
|
||||
flowNodeType: FlowNodeTypeEnum.tool,
|
||||
avatar,
|
||||
intro: tool.description,
|
||||
|
@@ -1,10 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@fastgpt/global/*": ["./*"]
|
||||
}
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts"]
|
||||
}
|
||||
|
@@ -14,10 +14,7 @@
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@fastgpt/plugins/*": ["./*"]
|
||||
}
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts", "../**/*.d.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
|
@@ -105,8 +105,9 @@ export const loadRequestMessages = async ({
|
||||
|
||||
const arrayContent = content
|
||||
.filter((item) => item.text)
|
||||
.map((item) => ({ ...item, text: addEndpointToImageUrl(item.text) }));
|
||||
if (arrayContent.length === 0) return;
|
||||
.map((item) => addEndpointToImageUrl(item.text))
|
||||
.join('\n');
|
||||
|
||||
return arrayContent;
|
||||
};
|
||||
// Parse user content(text and img) Store history => api messages
|
||||
|
@@ -42,8 +42,8 @@ type Response = DispatchNodeResultType<{
|
||||
}>;
|
||||
|
||||
export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<Response> => {
|
||||
const {
|
||||
node: { nodeId, name, isEntry, version },
|
||||
let {
|
||||
node: { nodeId, name, isEntry, version, inputs },
|
||||
runtimeNodes,
|
||||
runtimeEdges,
|
||||
histories,
|
||||
@@ -70,6 +70,11 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
|
||||
|
||||
props.params.aiChatVision = aiChatVision && toolModel.vision;
|
||||
props.params.aiChatReasoning = aiChatReasoning && toolModel.reasoning;
|
||||
const fileUrlInput = inputs.find((item) => item.key === NodeInputKeyEnum.fileUrlList);
|
||||
if (!fileUrlInput || !fileUrlInput.value || fileUrlInput.value.length === 0) {
|
||||
fileLinks = undefined;
|
||||
}
|
||||
console.log(fileLinks, 22);
|
||||
|
||||
const toolNodeIds = filterToolNodeIdByEdges({ nodeId, edges: runtimeEdges });
|
||||
|
||||
|
@@ -13,7 +13,6 @@ import { createChatCompletion } from '../../../ai/config';
|
||||
import type {
|
||||
ChatCompletionMessageParam,
|
||||
CompletionFinishReason,
|
||||
CompletionUsage,
|
||||
StreamChatType
|
||||
} from '@fastgpt/global/core/ai/type.d';
|
||||
import { formatModelChars2Points } from '../../../../support/wallet/usage/utils';
|
||||
@@ -45,7 +44,8 @@ import type { ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/
|
||||
import { responseWriteController } from '../../../../common/response';
|
||||
import { getLLMModel } from '../../../ai/model';
|
||||
import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import type { NodeInputKeyEnum, NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import type { NodeOutputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
|
||||
import { checkQuoteQAValue, getHistories } from '../utils';
|
||||
import { filterSearchResultsByMaxChars } from '../../utils';
|
||||
@@ -82,7 +82,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
||||
retainDatasetCite = true,
|
||||
externalProvider,
|
||||
histories,
|
||||
node: { name, version },
|
||||
node: { name, version, inputs },
|
||||
query,
|
||||
runningUserInfo,
|
||||
workflowStreamResponse,
|
||||
@@ -119,6 +119,11 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
||||
|
||||
aiChatVision = modelConstantsData.vision && aiChatVision;
|
||||
aiChatReasoning = !!aiChatReasoning && !!modelConstantsData.reasoning;
|
||||
// Check fileLinks is reference variable
|
||||
const fileUrlInput = inputs.find((item) => item.key === NodeInputKeyEnum.fileUrlList);
|
||||
if (!fileUrlInput || !fileUrlInput.value || fileUrlInput.value.length === 0) {
|
||||
fileLinks = undefined;
|
||||
}
|
||||
|
||||
const chatHistories = getHistories(history, histories);
|
||||
quoteQA = checkQuoteQAValue(quoteQA);
|
||||
|
@@ -84,10 +84,12 @@ export const filterToolNodeIdByEdges = ({
|
||||
export const getHistories = (history?: ChatItemType[] | number, histories: ChatItemType[] = []) => {
|
||||
if (!history) return [];
|
||||
|
||||
const systemHistories = histories.filter((item) => item.obj === ChatRoleEnum.System);
|
||||
const systemHistoryIndex = histories.findIndex((item) => item.obj !== ChatRoleEnum.System);
|
||||
const systemHistories = histories.slice(0, systemHistoryIndex);
|
||||
const chatHistories = histories.slice(systemHistoryIndex);
|
||||
|
||||
const filterHistories = (() => {
|
||||
if (typeof history === 'number') return histories.slice(-(history * 2));
|
||||
if (typeof history === 'number') return chatHistories.slice(-(history * 2));
|
||||
if (Array.isArray(history)) return history;
|
||||
return [];
|
||||
})();
|
||||
|
@@ -1,10 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@fastgpt/servive/*": ["./*"]
|
||||
}
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts", "../../**/*.d.ts"]
|
||||
}
|
||||
|
@@ -1,12 +1,17 @@
|
||||
import React, { useState, useMemo, useRef, useEffect } from 'react';
|
||||
import { Box, Card, Flex, useTheme, useOutsideClick, Button } from '@chakra-ui/react';
|
||||
import { addDays, format } from 'date-fns';
|
||||
import { type DateRange, DayPicker } from 'react-day-picker';
|
||||
import { DayPicker } from 'react-day-picker';
|
||||
import 'react-day-picker/dist/style.css';
|
||||
import zhCN from 'date-fns/locale/zh-CN';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import MyIcon from '../Icon';
|
||||
|
||||
export type DateRangeType = {
|
||||
from: Date;
|
||||
to: Date;
|
||||
};
|
||||
|
||||
const DateRangePicker = ({
|
||||
onChange,
|
||||
onSuccess,
|
||||
@@ -17,16 +22,16 @@ const DateRangePicker = ({
|
||||
},
|
||||
dateRange
|
||||
}: {
|
||||
onChange?: (date: DateRange) => void;
|
||||
onSuccess?: (date: DateRange) => void;
|
||||
onChange?: (date: DateRangeType) => void;
|
||||
onSuccess?: (date: DateRangeType) => void;
|
||||
position?: 'bottom' | 'top';
|
||||
defaultDate?: DateRange;
|
||||
dateRange?: DateRange;
|
||||
defaultDate?: DateRangeType;
|
||||
dateRange?: DateRangeType;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const OutRangeRef = useRef(null);
|
||||
const [range, setRange] = useState<DateRange | undefined>(defaultDate);
|
||||
const [range, setRange] = useState<DateRangeType>(defaultDate);
|
||||
const [showSelected, setShowSelected] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,28 +92,30 @@ const DateRangePicker = ({
|
||||
defaultMonth={defaultDate.to}
|
||||
selected={range}
|
||||
disabled={[
|
||||
{ from: new Date(2022, 3, 1), to: addDays(new Date(), -90) },
|
||||
{ from: new Date(2022, 3, 1), to: addDays(new Date(), -180) },
|
||||
{ from: addDays(new Date(), 1), to: new Date(2099, 1, 1) }
|
||||
]}
|
||||
onSelect={(date) => {
|
||||
if (date?.from === undefined) {
|
||||
date = {
|
||||
let typeDate = date as DateRangeType;
|
||||
if (!typeDate || typeDate?.from === undefined) {
|
||||
typeDate = {
|
||||
from: range?.from,
|
||||
to: range?.from
|
||||
};
|
||||
}
|
||||
if (date?.to === undefined) {
|
||||
date.to = date.from;
|
||||
if (typeDate?.to === undefined) {
|
||||
typeDate.to = typeDate.from;
|
||||
}
|
||||
|
||||
if (date?.from) {
|
||||
date.from = new Date(date.from.setHours(0, 0, 0, 0));
|
||||
if (typeDate?.from) {
|
||||
typeDate.from = new Date(typeDate.from.setHours(0, 0, 0, 0));
|
||||
}
|
||||
if (date?.to) {
|
||||
date.to = new Date(date.to.setHours(23, 59, 59, 999));
|
||||
if (typeDate?.to) {
|
||||
typeDate.to = new Date(typeDate.to.setHours(23, 59, 59, 999));
|
||||
}
|
||||
setRange(date);
|
||||
onChange?.(date);
|
||||
|
||||
setRange(typeDate);
|
||||
onChange?.(typeDate);
|
||||
}}
|
||||
footer={
|
||||
<Flex justifyContent={'flex-end'}>
|
||||
@@ -139,4 +146,3 @@ const DateRangePicker = ({
|
||||
};
|
||||
|
||||
export default DateRangePicker;
|
||||
export type DateRangeType = DateRange;
|
||||
|
@@ -258,6 +258,7 @@ export function usePagination<DataT, ResT = {}>(
|
||||
|
||||
return {
|
||||
pageNum,
|
||||
setPageNum,
|
||||
pageSize,
|
||||
total: totalDataLength,
|
||||
data,
|
||||
|
@@ -1,10 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@fastgpt/web/*": ["./*"]
|
||||
}
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts", "../**/*.d.ts"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user