Skip to content

Commit

Permalink
fix: chat
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jul 15, 2024
1 parent 356a94d commit 5f35f73
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 24 deletions.
8 changes: 6 additions & 2 deletions packages/web/components/common/Textarea/JsonEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type Props = Omit<BoxProps, 'resize' | 'onChange'> & {
variables?: EditorVariablePickerType[];
defaultHeight?: number;
placeholder?: string;
isDisabled?: boolean;
isInvalid?: boolean;
};

const options = {
Expand Down Expand Up @@ -55,6 +57,8 @@ const JSONEditor = ({
variables = [],
placeholder,
defaultHeight = 100,
isDisabled = false,
isInvalid = false,
...props
}: Props) => {
const { toast } = useToast();
Expand Down Expand Up @@ -209,9 +213,9 @@ const JSONEditor = ({

return (
<Box
borderWidth={'1px'}
borderWidth={isInvalid ? '2px' : '1px'}
borderRadius={'md'}
borderColor={'myGray.200'}
borderColor={isInvalid ? 'red.500' : 'myGray.200'}
py={2}
height={height}
position={'relative'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const RenderInput = () => {
useContextSelector(PluginRunContext, (v) => v);

const { t } = useTranslation();
const { control, handleSubmit } = variablesForm;
const {
control,
handleSubmit,
formState: { errors }
} = variablesForm;
const isDisabledInput = histories.length > 0;

return (
Expand All @@ -36,6 +40,7 @@ const RenderInput = () => {
required={input.required}
min={input.min}
max={input.max}
isInvalid={errors && Object.keys(errors).includes(input.key)}
/>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const RenderPluginInput = ({
placeholder,
required,
min,
max
max,
isInvalid
}: {
value: any;
onChange: () => void;
Expand All @@ -38,6 +39,7 @@ const RenderPluginInput = ({
required?: boolean;
min?: number;
max?: number;
isInvalid: boolean;
}) => {
const { t } = useTranslation();

Expand All @@ -50,12 +52,20 @@ const RenderPluginInput = ({
isDisabled={isDisabled}
placeholder={t(placeholder)}
bg={'myGray.50'}
isInvalid={isInvalid}
/>
);
}
if (valueType === WorkflowIOValueTypeEnum.number) {
return (
<NumberInput step={1} min={min} max={max} bg={'myGray.50'} isDisabled={isDisabled}>
<NumberInput
step={1}
min={min}
max={max}
bg={'myGray.50'}
isDisabled={isDisabled}
isInvalid={isInvalid}
>
<NumberInputField value={value} onChange={onChange} />
<NumberInputStepper>
<NumberIncrementStepper />
Expand All @@ -65,7 +75,14 @@ const RenderPluginInput = ({
);
}
if (valueType === WorkflowIOValueTypeEnum.boolean) {
return <Switch isChecked={value} onChange={onChange} isDisabled={isDisabled} />;
return (
<Switch
isChecked={value}
onChange={onChange}
isDisabled={isDisabled}
isInvalid={isInvalid}
/>
);
}

return (
Expand All @@ -75,6 +92,7 @@ const RenderPluginInput = ({
resize
value={value}
onChange={onChange}
isInvalid={isInvalid}
/>
);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,36 @@ const PluginRunContextProvider = ({
}
]);

const { responseData } = await onStartChat({
messages: [],
controller: chatController.current,
generatingMessage,
variables: e
});

setHistories((state) =>
state.map((item, index) => {
if (index !== state.length - 1) return item;
return {
...item,
status: 'finish',
responseData
};
})
);
try {
const { responseData } = await onStartChat({
messages: [],
controller: chatController.current,
generatingMessage,
variables: e
});

setHistories((state) =>
state.map((item, index) => {
if (index !== state.length - 1) return item;
return {
...item,
status: 'finish',
responseData
};
})
);
} catch (err: any) {
toast({ title: err.message, status: 'error' });
setHistories((state) =>
state.map((item, index) => {
if (index !== state.length - 1) return item;
return {
...item,
status: 'finish'
};
})
);
}
});

const contextValue: PluginRunContextType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const ChatTest = ({
</Flex>
)}

<Box flex={'1 0 0'}>
<Box flex={'1 0 0'} overflow={'auto'}>
<ChatContainer />
</Box>
</Flex>
Expand Down

0 comments on commit 5f35f73

Please sign in to comment.