Skip to content

Commit 5f8ae64

Browse files
committed
fixed
1 parent de25fec commit 5f8ae64

24 files changed

Lines changed: 47 additions & 22 deletions

react/src/components/Chat/ChatCard.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import { extractReasoningMiddleware, streamText, wrapLanguageModel } from 'ai';
1919
import { Alert, App, Card, CardProps } from 'antd';
2020
import { createStyles } from 'antd-style';
2121
import graphql from 'babel-plugin-relay/macro';
22-
import { includes, isEmpty, map } from 'lodash';
22+
import _ from 'lodash';
2323
import React, {
2424
startTransition,
2525
useEffect,
2626
useMemo,
2727
useRef,
2828
useState,
29+
useTransition,
2930
} from 'react';
3031
import { useFragment } from 'react-relay';
3132

@@ -143,15 +144,15 @@ function useModels(
143144
},
144145
});
145146

146-
const models = map(modelsResult?.data, (m) => ({
147+
const models = _.map(modelsResult?.data || [], (m) => ({
147148
id: m.id,
148149
name: m.id,
149150
})) as BAIModel[];
150151

151152
const selectedModelId = useMemo(
152153
() =>
153154
provider.modelId &&
154-
includes(map(modelsResult?.data, 'id'), provider.modelId)
155+
_.includes(_.map(modelsResult?.data || [], 'id'), provider.modelId)
155156
? provider.modelId
156157
: (modelsResult?.data?.[0]?.id ?? 'custom'),
157158
[modelsResult?.data, provider.modelId],
@@ -208,6 +209,8 @@ const ChatCard: React.FC<ChatCardProps> = ({
208209
const {
209210
styles: { chatCard: chatCardStyle, alert: alertStyle, ...chatCardStyles },
210211
} = useStyles();
212+
const [isPendingUpdate, startUpdateTransition] = useTransition();
213+
211214
const dropContainerRef = useRef<HTMLDivElement>(null);
212215
const [fetchKey, updateFetchKey] = useUpdatableState('first');
213216
const [startTime, setStartTime] = useState<number | null>(null);
@@ -308,19 +311,22 @@ const ChatCard: React.FC<ChatCardProps> = ({
308311
}
309312
ref={dropContainerRef}
310313
>
311-
{isEmpty(models) && (
314+
{_.isEmpty(models) && (
312315
<CustomModelForm
313316
baseURL={baseURL}
314317
token={token}
315318
endpointId={endpoint?.endpoint_id}
319+
loading={isPendingUpdate}
316320
onSubmit={(data) => {
317-
updateFetchKey();
318-
setBaseURL(data.baseURL);
319-
setToken(data.token);
321+
startUpdateTransition(() => {
322+
updateFetchKey();
323+
setBaseURL(data.baseURL);
324+
setToken(data.token);
325+
});
320326
}}
321327
/>
322328
)}
323-
{!isEmpty(error?.message) ? (
329+
{!_.isEmpty(error?.message) ? (
324330
<Alert
325331
message={error?.message}
326332
type="error"

react/src/components/Chat/CustomModelForm.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import EndpointTokenSelect from './EndpointTokenSelect';
33
import { ReloadOutlined } from '@ant-design/icons';
44
import { Alert, Button, Form, Input, theme } from 'antd';
55
import type { FormInstance } from 'antd';
6-
import { useRef, useTransition } from 'react';
6+
import { useRef } from 'react';
77
import { useTranslation } from 'react-i18next';
88

99
export type CustomModelFormValues = {
@@ -15,6 +15,7 @@ type CustomModelFormProps = {
1515
baseURL?: string;
1616
token?: string;
1717
endpointId?: string | null;
18+
loading: boolean;
1819
onSubmit?: (formData: CustomModelFormValues) => void;
1920
};
2021

@@ -30,13 +31,13 @@ const CustomModelForm: React.FC<CustomModelFormProps> = ({
3031
baseURL,
3132
token,
3233
endpointId,
34+
loading,
3335
onSubmit,
3436
}) => {
3537
const { t } = useTranslation();
3638
const { token: themeToken } = theme.useToken();
3739
const formRef = useRef<FormInstance>(null);
3840

39-
const [isPendingSubmit, startSubmitTransition] = useTransition();
4041
const { origin, pathname: basePath } = parseBaseURL(baseURL);
4142

4243
return (
@@ -76,21 +77,18 @@ const CustomModelForm: React.FC<CustomModelFormProps> = ({
7677
/>
7778
</Form.Item>
7879
<Form.Item label={t('modelService.Token')} name="token">
79-
<EndpointTokenSelect
80-
loading={isPendingSubmit}
81-
endpointId={endpointId}
82-
/>
80+
<EndpointTokenSelect loading={loading} endpointId={endpointId} />
8381
</Form.Item>
8482
<Button
8583
icon={<ReloadOutlined />}
86-
loading={isPendingSubmit}
84+
loading={loading}
8785
onClick={() => {
88-
startSubmitTransition(() => {
89-
const basePath = formRef.current?.getFieldValue('basePath') ?? '';
90-
onSubmit?.({
91-
baseURL: new URL(basePath, origin).toString(),
92-
token: formRef.current?.getFieldValue('token'),
93-
});
86+
onSubmit?.({
87+
baseURL: new URL(
88+
formRef.current?.getFieldValue('basePath') ?? '',
89+
origin,
90+
).toString(),
91+
token: formRef.current?.getFieldValue('token'),
9492
});
9593
}}
9694
>

react/src/components/Chat/EndpointTokenSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const EndpointTokenSelect: React.FC<EndpointTokenSelectProps> = ({
7272
<Input onChange={(e) => setControllableValue(e.target.value)} />
7373
) : (
7474
<Select
75-
placeholder={t('chatui.SelectEndpoint')}
75+
placeholder={t('chatui.SelectToken')}
7676
style={{
7777
fontWeight: 'normal',
7878
width: '200px',

resources/i18n/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"NewChat": "Neuer Chat",
107107
"SelectEndpoint": "Wählen Sie Endpunkt aus",
108108
"SelectModel": "Wählen Sie Modell aus",
109+
"SelectToken": "Token auswählen",
109110
"SyncInput": "Synchronisiert",
110111
"Thinking": "Denken",
111112
"UploadFiles": "Dateien hochladen",

resources/i18n/el.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"NewChat": "Νέα συνομιλία",
107107
"SelectEndpoint": "Επιλέξτε Τελικό σημείο",
108108
"SelectModel": "Επιλέξτε Μοντέλο",
109+
"SelectToken": "Επιλέξτε Token",
109110
"SyncInput": "Συγχρονισμένο",
110111
"Thinking": "Σκέψη",
111112
"UploadFiles": "Μεταφόρτωση αρχείων",

resources/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"NewChat": "New Chat",
109109
"SelectEndpoint": "Select Endpoint",
110110
"SelectModel": "Select Model",
111+
"SelectToken": "Select Token",
111112
"SyncInput": "Synced",
112113
"Thinking": "Thinking",
113114
"UploadFiles": "Upload files",

resources/i18n/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"NewChat": "Nueva conversación",
107107
"SelectEndpoint": "Seleccionar punto final",
108108
"SelectModel": "Seleccionar modelo",
109+
"SelectToken": "Seleccionar ficha",
109110
"SyncInput": "Sincronizado",
110111
"Thinking": "Pensamiento",
111112
"UploadFiles": "Subir archivos",

resources/i18n/fi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"DropFileHere": "Pudota tiedosto tähän",
106106
"SelectEndpoint": "Valitse Päätepiste",
107107
"SelectModel": "Valitse Malli",
108+
"SelectToken": "Valitse Token",
108109
"SyncInput": "Synkronoitu",
109110
"Thinking": "Ajattelu",
110111
"UploadFiles": "Lataa tiedostoja",

resources/i18n/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"NewChat": "Nouvelle discussion",
107107
"SelectEndpoint": "Sélectionnez le point de terminaison",
108108
"SelectModel": "Sélectionnez le modèle",
109+
"SelectToken": "Sélectionner le jeton",
109110
"SyncInput": "Synchronisé",
110111
"Thinking": "Pensée",
111112
"UploadFiles": "Télécharger des fichiers",

resources/i18n/id.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"NewChat": "Obrolan Baru",
106106
"SelectEndpoint": "Pilih Titik Akhir",
107107
"SelectModel": "Pilih Model",
108+
"SelectToken": "Pilih Token",
108109
"SyncInput": "Disinkronkan",
109110
"Thinking": "Pemikiran",
110111
"UploadFiles": "Unggah file",

0 commit comments

Comments
 (0)