Skip to content

Commit

Permalink
4.8 test (#1394)
Browse files Browse the repository at this point in the history
* fix: chat variable sync

* feat: chat save variable config

* fix: target handle hidden

* adapt v1 chat init

* adapt v1 chat init

* adapt v1 chat init

* adapt v1 chat init
  • Loading branch information
c121914yu authored May 8, 2024
1 parent 7b75a99 commit 3c6e5a6
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 242 deletions.
4 changes: 2 additions & 2 deletions packages/global/core/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
const {
welcomeText,
variableModules,
variableNodes,
questionGuide,
ttsConfig,
whisperConfig,
Expand All @@ -114,7 +114,7 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {

defaultAppForm.userGuide = {
welcomeText: welcomeText,
variables: variableModules,
variables: variableNodes,
questionGuide: questionGuide,
tts: ttsConfig,
whisper: whisperConfig,
Expand Down
8 changes: 5 additions & 3 deletions packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { FlowNodeTypeEnum } from '../workflow/node/constant';
import { NodeOutputKeyEnum } from '../workflow/constants';
import { DispatchNodeResponseKeyEnum } from '../workflow/runtime/constants';
import { AppSchema } from '../app/type';
import { AppSchema, VariableItemType } from '../app/type';
import type { AppSchema as AppType } from '@fastgpt/global/core/app/type.d';
import { DatasetSearchModeEnum } from '../dataset/constants';
import { ChatBoxInputType } from '../../../../projects/app/src/components/ChatBox/type';
Expand All @@ -27,11 +27,13 @@ export type ChatSchema = {
title: string;
customTitle: string;
top: boolean;
variables: Record<string, any>;
source: `${ChatSourceEnum}`;
shareId?: string;
outLinkUid?: string;
content: ChatItemType[];

variableList?: VariableItemType[];
welcomeText?: string;
variables: Record<string, any>;
metadata?: Record<string, any>;
};

Expand Down
42 changes: 38 additions & 4 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ export const checkInputIsReference = (input: FlowNodeInputItemType) => {

/* node */
export const getGuideModule = (modules: StoreNodeItemType[]) =>
modules.find((item) => item.flowNodeType === FlowNodeTypeEnum.systemConfig);

modules.find(
(item) =>
item.flowNodeType === FlowNodeTypeEnum.systemConfig ||
// @ts-ignore (adapt v1)
item.flowType === FlowNodeTypeEnum.systemConfig
);
export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
const welcomeText: string =
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.welcomeText)?.value || '';

const variableModules: VariableItemType[] =
const variableNodes: VariableItemType[] =
guideModules?.inputs.find((item) => item.key === NodeInputKeyEnum.variables)?.value || [];

const questionGuide: boolean =
Expand All @@ -63,13 +67,43 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {

return {
welcomeText,
variableModules,
variableNodes,
questionGuide,
ttsConfig,
whisperConfig,
scheduledTriggerConfig
};
};
export const replaceAppChatConfig = ({
node,
variableList,
welcomeText
}: {
node?: StoreNodeItemType;
variableList?: VariableItemType[];
welcomeText?: string;
}): StoreNodeItemType | undefined => {
if (!node) return;
return {
...node,
inputs: node.inputs.map((input) => {
if (input.key === NodeInputKeyEnum.variables && variableList) {
return {
...input,
value: variableList
};
}
if (input.key === NodeInputKeyEnum.welcomeText && welcomeText) {
return {
...input,
value: welcomeText
};
}

return input;
})
};
};

export const getOrInitModuleInputValue = (input: FlowNodeInputItemType) => {
if (input.value !== undefined || !input.valueType) return input.value;
Expand Down
4 changes: 4 additions & 0 deletions packages/service/core/ai/rerank/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function reRankRecall({
.then((data) => {
addLog.info('ReRank finish:', { time: Date.now() - start });

if (!data?.results || data?.results?.length === 0) {
addLog.error('ReRank error, empty result', data);
}

return data?.results?.map((item) => ({
id: documents[item.index].id,
score: item.relevance_score
Expand Down
8 changes: 8 additions & 0 deletions packages/service/core/chat/chatSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ const ChatSchema = new Schema({
outLinkUid: {
type: String
},

variableList: {
type: Array
},
welcomeText: {
type: String
},
variables: {
// variable value
type: Object,
default: {}
},
Expand Down
8 changes: 4 additions & 4 deletions projects/app/src/components/ChatBox/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ChatSiteItemType } from '@fastgpt/global/core/chat/type';

type useChatStoreType = OutLinkChatAuthProps & {
welcomeText: string;
variableModules: VariableItemType[];
variableNodes: VariableItemType[];
questionGuide: boolean;
ttsConfig: AppTTSConfigType;
whisperConfig: AppWhisperConfigType;
Expand Down Expand Up @@ -41,7 +41,7 @@ type useChatStoreType = OutLinkChatAuthProps & {
};
const StateContext = createContext<useChatStoreType>({
welcomeText: '',
variableModules: [],
variableNodes: [],
questionGuide: false,
ttsConfig: {
type: 'none',
Expand Down Expand Up @@ -110,7 +110,7 @@ const Provider = ({
}: ChatProviderProps) => {
const [chatHistories, setChatHistories] = useState<ChatSiteItemType[]>([]);

const { welcomeText, variableModules, questionGuide, ttsConfig, whisperConfig } = useMemo(
const { welcomeText, variableNodes, questionGuide, ttsConfig, whisperConfig } = useMemo(
() => splitGuideModule(userGuideModule),
[userGuideModule]
);
Expand Down Expand Up @@ -150,7 +150,7 @@ const Provider = ({
teamId,
teamToken,
welcomeText,
variableModules,
variableNodes,
questionGuide,
ttsConfig,
whisperConfig,
Expand Down
32 changes: 7 additions & 25 deletions projects/app/src/components/ChatBox/components/VariableInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VariableItemType } from '@fastgpt/global/core/app/type.d';
import React, { useEffect, useState } from 'react';
import React from 'react';
import { UseFormReturn } from 'react-hook-form';
import { useTranslation } from 'next-i18next';
import { Box, Button, Card, Input, Textarea } from '@chakra-ui/react';
Expand All @@ -12,34 +12,19 @@ import { ChatBoxInputFormType } from '../type.d';

const VariableInput = ({
appAvatar,
variableModules,
variableIsFinish,
variableNodes,
chatForm,
onSubmitVariables
}: {
appAvatar?: string;
variableModules: VariableItemType[];
variableIsFinish: boolean;
variableNodes: VariableItemType[];
onSubmitVariables: (e: Record<string, any>) => void;
chatForm: UseFormReturn<ChatBoxInputFormType>;
}) => {
const { t } = useTranslation();
const { register, unregister, setValue, handleSubmit: handleSubmitChat, watch } = chatForm;
const { register, setValue, handleSubmit: handleSubmitChat, watch } = chatForm;
const variables = watch('variables');

useEffect(() => {
// 重新注册所有字段
variableModules.forEach((item) => {
register(`variables.${item.key}`, { required: item.required });
});

return () => {
// 组件卸载时注销所有字段
variableModules.forEach((item) => {
unregister(`variables.${item.key}`);
});
};
}, [register, unregister, variableModules]);
const chatStarted = watch('chatStarted');

return (
<Box py={3}>
Expand All @@ -55,7 +40,7 @@ const VariableInput = ({
bg={'white'}
boxShadow={'0 0 8px rgba(0,0,0,0.15)'}
>
{variableModules.map((item) => (
{variableNodes.map((item) => (
<Box key={item.id} mb={4}>
<Box as={'label'} display={'inline-block'} position={'relative'} mb={1}>
{item.label}
Expand All @@ -73,7 +58,6 @@ const VariableInput = ({
</Box>
{item.type === VariableInputEnum.input && (
<Input
isDisabled={variableIsFinish}
bg={'myWhite.400'}
{...register(`variables.${item.key}`, {
required: item.required
Expand All @@ -82,7 +66,6 @@ const VariableInput = ({
)}
{item.type === VariableInputEnum.textarea && (
<Textarea
isDisabled={variableIsFinish}
bg={'myWhite.400'}
{...register(`variables.${item.key}`, {
required: item.required
Expand All @@ -94,7 +77,6 @@ const VariableInput = ({
{item.type === VariableInputEnum.select && (
<MySelect
width={'100%'}
isDisabled={variableIsFinish}
list={(item.enums || []).map((item) => ({
label: item.value,
value: item.value
Expand All @@ -110,7 +92,7 @@ const VariableInput = ({
)}
</Box>
))}
{!variableIsFinish && (
{!chatStarted && (
<Button
leftIcon={<MyIcon name={'core/chat/chatFill'} w={'16px'} />}
size={'sm'}
Expand Down
Loading

0 comments on commit 3c6e5a6

Please sign in to comment.