Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jul 11, 2024
1 parent c2d08fb commit b919744
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 29 deletions.
3 changes: 1 addition & 2 deletions packages/global/core/chat/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export enum ChatFileTypeEnum {
export enum ChatItemValueTypeEnum {
text = 'text',
file = 'file',
tool = 'tool',
plugin = 'plugin'
tool = 'tool'
}

export enum ChatSourceEnum {
Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ChatWithAppSchema = Omit<ChatSchema, 'appId'> & {
};

export type UserChatItemValueItemType = {
type: ChatItemValueTypeEnum.text | ChatItemValueTypeEnum.file | ChatItemValueTypeEnum.plugin;
type: ChatItemValueTypeEnum.text | ChatItemValueTypeEnum.file;
text?: {
content: string;
};
Expand Down
8 changes: 6 additions & 2 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ export const getElseIFLabel = (i: number) => {
return i === 0 ? IfElseResultEnum.IF : `${IfElseResultEnum.ELSE_IF} ${i}`;
};

export const updateNodeInputs = (nodes: RuntimeNodeItemType[], variables: Record<string, any>) => {
// add value to plugin input node when run plugin
export const updatePluginInputNodeInputs = (
nodes: RuntimeNodeItemType[],
variables: Record<string, any>
) => {
return nodes.map((node) =>
node.nodeId === nodes[0].nodeId
node.flowNodeType === FlowNodeTypeEnum.pluginInput
? {
...node,
inputs: node.inputs.map((input) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@ import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
import {
AIChatItemValueItemType,
ChatSiteItemType,
SystemChatItemValueItemType,
UserChatItemValueItemType
} from '@fastgpt/global/core/chat/type';
import React from 'react';
import MyIcon from '@fastgpt/web/components/common/Icon';

type props = {
value: UserChatItemValueItemType | SystemChatItemValueItemType | AIChatItemValueItemType;
value: UserChatItemValueItemType | AIChatItemValueItemType;
index: number;
contentkey: string;
chat: ChatSiteItemType;
isLastChild: boolean;
isChatting: boolean;
questionGuides: string[];
};

const ChatContent = ({
const AIResponseBox = ({
value,
index,
contentkey,
chat,
isLastChild,
isChatting,
Expand All @@ -55,15 +52,14 @@ ${JSON.stringify(questionGuides)}`;

return (
<Markdown
key={contentkey}
source={source}
showAnimation={isLastChild && isChatting && index === chat.value.length - 1}
/>
);
}
if (value.type === ChatItemValueTypeEnum.tool && value.tools) {
return (
<Box key={contentkey}>
<Box>
{value.tools.map((tool) => {
const toolParams = (() => {
try {
Expand Down Expand Up @@ -135,4 +131,4 @@ ${toolResponse}`}
return null;
};

export default React.memo(ChatContent);
export default React.memo(AIResponseBox);
5 changes: 2 additions & 3 deletions projects/app/src/components/ChatBox/components/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ChatRoleEnum, ChatStatusEnum } from '@fastgpt/global/core/chat/constant
import FilesBlock from './FilesBox';
import { ChatBoxContext } from '../Provider';
import { useContextSelector } from 'use-context-selector';
import ChatContent from './ChatContent';
import AIResponseBox from './AIResponseBox';

const colorMap = {
[ChatStatusEnum.loading]: {
Expand Down Expand Up @@ -84,9 +84,8 @@ const ChatItem = ({
const key = `${chat.dataId}-ai-${i}`;

return (
<ChatContent
<AIResponseBox
key={key}
contentkey={key}
value={value}
index={i}
chat={chat}
Expand Down
9 changes: 2 additions & 7 deletions projects/app/src/components/ChatBox/components/PluginBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from 'react';
import { Control, Controller, FieldValues, UseFormHandleSubmit } from 'react-hook-form';
import { ChatSiteItemType } from '@fastgpt/global/core/chat/type';
import { ChatBoxInputType, StartChatFnProps } from '../type';
import ChatContent from './ChatContent';
import AIResponseBox from './AIResponseBox';
import Markdown from '@/components/Markdown';
import { ResponseBox } from './WholeResponseModal';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
Expand All @@ -25,8 +25,6 @@ const PluginBox = ({
sendPrompt,
chatHistories,
isChatting,
shareId,
teamId,
onStartChat
}: {
chatType: `${ChatTypeEnum}`;
Expand All @@ -48,8 +46,6 @@ const PluginBox = ({
}) => void;
chatHistories: ChatSiteItemType[];
isChatting: boolean;
shareId: string | undefined;
teamId: string | undefined;
onStartChat?: (e: StartChatFnProps) => Promise<
StreamResponseType & {
isNewChat?: boolean;
Expand Down Expand Up @@ -201,9 +197,8 @@ const PluginBox = ({
{chatHistories[1]?.value.map((value, i) => {
const key = `${chatHistories[1].dataId}-ai-${i}`;
return (
<ChatContent
<AIResponseBox
key={key}
contentkey={key}
value={value}
index={i}
chat={chatHistories[1]}
Expand Down
2 changes: 0 additions & 2 deletions projects/app/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,6 @@ const ChatBox = (
sendPrompt={sendPrompt}
chatHistories={chatHistories}
isChatting={isChatting}
shareId={shareId}
teamId={teamId}
onStartChat={onStartChat}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/api/v1/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { NextAPI } from '@/service/middleware/entry';
import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { updateNodeInputs } from '@fastgpt/global/core/workflow/utils';
import { updatePluginInputNodeInputs } from '@fastgpt/global/core/workflow/utils';

type FastGptWebChatProps = {
chatId?: string; // undefined: nonuse history, '': new chat, 'xxxxx': use history
Expand Down Expand Up @@ -202,7 +202,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
responseChatItemId,
runtimeNodes:
appType === AppTypeEnum.plugin
? updateNodeInputs(
? updatePluginInputNodeInputs(
storeNodes2RuntimeNodes(nodes, getDefaultEntryNodeIds(nodes)),
variables
)
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/app/detail/components/useChatTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { StoreEdgeItemType } from '@fastgpt/global/core/workflow/type/edge';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { ChatTypeEnum } from '@/components/ChatBox/constants';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { updateNodeInputs } from '@fastgpt/global/core/workflow/utils';
import { updatePluginInputNodeInputs } from '@fastgpt/global/core/workflow/utils';

export const useChatTest = ({
nodes,
Expand Down Expand Up @@ -49,7 +49,7 @@ export const useChatTest = ({
prompt: appDetail.type === AppTypeEnum.plugin ? [] : chatList[chatList.length - 2].value,
nodes:
appDetail.type === AppTypeEnum.plugin
? updateNodeInputs(
? updatePluginInputNodeInputs(
storeNodes2RuntimeNodes(nodes, getDefaultEntryNodeIds(nodes)),
variables
)
Expand Down

0 comments on commit b919744

Please sign in to comment.