|
@@ -144,28 +144,28 @@ const AiChatModalSubstance = (): JSX.Element => {
|
|
|
|
|
|
|
|
const chunk = decoder.decode(value);
|
|
const chunk = decoder.decode(value);
|
|
|
|
|
|
|
|
- if (chunk.startsWith('error:')) {
|
|
|
|
|
- const error = JSON.parse(chunk.replace('error: ', ''));
|
|
|
|
|
- logger.error(error.errorMessage);
|
|
|
|
|
- form.setError('input', { type: 'manual', message: error.message });
|
|
|
|
|
- if (error.code === StreamErrorCode.RATE_LIMIT_EXCEEDED) {
|
|
|
|
|
-
|
|
|
|
|
- const toastErrorMessage = growiCloudUri != null
|
|
|
|
|
- ? 'modal_aichat.rate_limit_exceeded_for_growi_cloud'
|
|
|
|
|
- : 'modal_aichat.rate_limit_exceeded';
|
|
|
|
|
-
|
|
|
|
|
- toastError(t(toastErrorMessage));
|
|
|
|
|
|
|
+ const textValues: string[] = [];
|
|
|
|
|
+ const lines = chunk.split('\n\n');
|
|
|
|
|
+ lines.forEach((line) => {
|
|
|
|
|
+ const trimedLine = line.trim();
|
|
|
|
|
+ if (trimedLine.startsWith('data:')) {
|
|
|
|
|
+ const data = JSON.parse(line.replace('data: ', ''));
|
|
|
|
|
+ textValues.push(data.content[0].text.value);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ else if (trimedLine.startsWith('error:')) {
|
|
|
|
|
+ const error = JSON.parse(line.replace('error: ', ''));
|
|
|
|
|
+ logger.error(error.errorMessage);
|
|
|
|
|
+ form.setError('input', { type: 'manual', message: error.message });
|
|
|
|
|
+
|
|
|
|
|
+ if (error.code === StreamErrorCode.RATE_LIMIT_EXCEEDED) {
|
|
|
|
|
+ const toastErrorMessage = growiCloudUri != null
|
|
|
|
|
+ ? 'modal_aichat.rate_limit_exceeded_for_growi_cloud'
|
|
|
|
|
+ : 'modal_aichat.rate_limit_exceeded';
|
|
|
|
|
+ toastError(t(toastErrorMessage));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // Extract text values from the chunk
|
|
|
|
|
- const textValues = chunk
|
|
|
|
|
- .split('\n\n')
|
|
|
|
|
- .filter(line => line.trim().startsWith('data:'))
|
|
|
|
|
- .map((line) => {
|
|
|
|
|
- const data = JSON.parse(line.replace('data: ', ''));
|
|
|
|
|
- return data.content[0].text.value;
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
// append text values to the assistant message
|
|
// append text values to the assistant message
|
|
|
setGeneratingAnswerMessage((prevMessage) => {
|
|
setGeneratingAnswerMessage((prevMessage) => {
|
|
@@ -185,7 +185,7 @@ const AiChatModalSubstance = (): JSX.Element => {
|
|
|
form.setError('input', { type: 'manual', message: err.toString() });
|
|
form.setError('input', { type: 'manual', message: err.toString() });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- }, [form, isGenerating, messageLogs, t, threadId]);
|
|
|
|
|
|
|
+ }, [form, growiCloudUri, isGenerating, messageLogs, t, threadId]);
|
|
|
|
|
|
|
|
const keyDownHandler = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
const keyDownHandler = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|