mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-23 04:46:07 +00:00
feat: add error handling and alert display for model testing in EmbeddingForm and LLMForm
This commit is contained in:
@@ -40,6 +40,8 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { extractI18nObject } from '@/i18n/I18nProvider';
|
import { extractI18nObject } from '@/i18n/I18nProvider';
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||||
|
import { AlertCircle } from 'lucide-react';
|
||||||
|
|
||||||
const getExtraArgSchema = (t: (key: string) => string) =>
|
const getExtraArgSchema = (t: (key: string) => string) =>
|
||||||
z
|
z
|
||||||
@@ -119,6 +121,7 @@ export default function EmbeddingForm({
|
|||||||
string[]
|
string[]
|
||||||
>([]);
|
>([]);
|
||||||
const [modelTesting, setModelTesting] = useState(false);
|
const [modelTesting, setModelTesting] = useState(false);
|
||||||
|
const [testErrorMessage, setTestErrorMessage] = useState<string | null>(null);
|
||||||
const [currentModelProvider, setCurrentModelProvider] = useState('');
|
const [currentModelProvider, setCurrentModelProvider] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -301,6 +304,7 @@ export default function EmbeddingForm({
|
|||||||
|
|
||||||
function testEmbeddingModelInForm() {
|
function testEmbeddingModelInForm() {
|
||||||
setModelTesting(true);
|
setModelTesting(true);
|
||||||
|
setTestErrorMessage(null);
|
||||||
const extraArgsObj: Record<string, string | number | boolean> = {};
|
const extraArgsObj: Record<string, string | number | boolean> = {};
|
||||||
form
|
form
|
||||||
.getValues('extra_args')
|
.getValues('extra_args')
|
||||||
@@ -329,9 +333,10 @@ export default function EmbeddingForm({
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success(t('models.testSuccess'));
|
toast.success(t('models.testSuccess'));
|
||||||
|
setTestErrorMessage(null);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err: { message?: string }) => {
|
||||||
toast.error(t('models.testError'));
|
setTestErrorMessage(err?.message || t('models.testError'));
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setModelTesting(false);
|
setModelTesting(false);
|
||||||
@@ -598,6 +603,15 @@ export default function EmbeddingForm({
|
|||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</div>
|
</div>
|
||||||
|
{testErrorMessage && (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>{t('models.testError')}</AlertTitle>
|
||||||
|
<AlertDescription className="break-all">
|
||||||
|
{testErrorMessage}
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
{editMode && (
|
{editMode && (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ import {
|
|||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { extractI18nObject } from '@/i18n/I18nProvider';
|
import { extractI18nObject } from '@/i18n/I18nProvider';
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
|
||||||
|
import { AlertCircle } from 'lucide-react';
|
||||||
|
|
||||||
const getExtraArgSchema = (t: (key: string) => string) =>
|
const getExtraArgSchema = (t: (key: string) => string) =>
|
||||||
z
|
z
|
||||||
@@ -132,6 +134,7 @@ export default function LLMForm({
|
|||||||
string[]
|
string[]
|
||||||
>([]);
|
>([]);
|
||||||
const [modelTesting, setModelTesting] = useState(false);
|
const [modelTesting, setModelTesting] = useState(false);
|
||||||
|
const [testErrorMessage, setTestErrorMessage] = useState<string | null>(null);
|
||||||
const [currentModelProvider, setCurrentModelProvider] = useState('');
|
const [currentModelProvider, setCurrentModelProvider] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -314,6 +317,7 @@ export default function LLMForm({
|
|||||||
|
|
||||||
function testLLMModelInForm() {
|
function testLLMModelInForm() {
|
||||||
setModelTesting(true);
|
setModelTesting(true);
|
||||||
|
setTestErrorMessage(null);
|
||||||
const extraArgsObj: Record<string, string | number | boolean> = {};
|
const extraArgsObj: Record<string, string | number | boolean> = {};
|
||||||
form
|
form
|
||||||
.getValues('extra_args')
|
.getValues('extra_args')
|
||||||
@@ -343,9 +347,10 @@ export default function LLMForm({
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success(t('models.testSuccess'));
|
toast.success(t('models.testSuccess'));
|
||||||
|
setTestErrorMessage(null);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((err: { message?: string }) => {
|
||||||
toast.error(t('models.testError'));
|
setTestErrorMessage(err?.message || t('models.testError'));
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setModelTesting(false);
|
setModelTesting(false);
|
||||||
@@ -645,6 +650,15 @@ export default function LLMForm({
|
|||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</div>
|
</div>
|
||||||
|
{testErrorMessage && (
|
||||||
|
<Alert variant="destructive">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<AlertTitle>{t('models.testError')}</AlertTitle>
|
||||||
|
<AlertDescription className="break-all">
|
||||||
|
{testErrorMessage}
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
{editMode && (
|
{editMode && (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ export abstract class BaseHttpClient {
|
|||||||
// 统一错误处理
|
// 统一错误处理
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status, data } = error.response;
|
const { status, data } = error.response;
|
||||||
const errMessage = data?.message || error.message;
|
// Backend uses 'msg' field, also check 'message' for compatibility
|
||||||
|
const errMessage =
|
||||||
|
(data as { msg?: string })?.msg || data?.message || error.message;
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 401:
|
case 401:
|
||||||
|
|||||||
Reference in New Issue
Block a user