chore: completions error handler
This commit is contained in:
@@ -37,7 +37,7 @@ type ParamsSettingsProps = {
|
|||||||
globalParams?: Record<string, any>;
|
globalParams?: Record<string, any>;
|
||||||
paramsConfig?: ParamsSchema[];
|
paramsConfig?: ParamsSchema[];
|
||||||
initialValues?: Record<string, any>;
|
initialValues?: Record<string, any>;
|
||||||
extra?: React.ReactNode[];
|
extra?: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
const ParamsSettings: React.FC<ParamsSettingsProps> = forwardRef(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import AlertInfo from '@/components/alert-info';
|
|||||||
import ScatterChart from '@/components/echarts/scatter';
|
import ScatterChart from '@/components/echarts/scatter';
|
||||||
import HighlightCode from '@/components/highlight-code';
|
import HighlightCode from '@/components/highlight-code';
|
||||||
import IconFont from '@/components/icon-font';
|
import IconFont from '@/components/icon-font';
|
||||||
|
import SealInputNumber from '@/components/seal-form/input-number';
|
||||||
import HotKeys, { KeyMap } from '@/config/hotkeys';
|
import HotKeys, { KeyMap } from '@/config/hotkeys';
|
||||||
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
||||||
import useRequestToken from '@/hooks/use-request-token';
|
import useRequestToken from '@/hooks/use-request-token';
|
||||||
@@ -13,7 +14,7 @@ import {
|
|||||||
SendOutlined
|
SendOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { useIntl, useSearchParams } from '@umijs/max';
|
import { useIntl, useSearchParams } from '@umijs/max';
|
||||||
import { Button, Checkbox, Segmented, Spin, Tabs, Tooltip } from 'antd';
|
import { Button, Checkbox, Form, Segmented, Spin, Tabs, Tooltip } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { PCA } from 'ml-pca';
|
import { PCA } from 'ml-pca';
|
||||||
@@ -86,6 +87,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const [lessTwoInput, setLessTwoInput] = useState<boolean>(false);
|
const [lessTwoInput, setLessTwoInput] = useState<boolean>(false);
|
||||||
const multiplePasteEnable = useRef<boolean>(true);
|
const multiplePasteEnable = useRef<boolean>(true);
|
||||||
const selectionTextRef = useRef<any>(null);
|
const selectionTextRef = useRef<any>(null);
|
||||||
|
const [metaData, setMetaData] = useState<Record<string, any>>({});
|
||||||
|
|
||||||
const [textList, setTextList] = useState<
|
const [textList, setTextList] = useState<
|
||||||
{ text: string; uid: number | string; name: string }[]
|
{ text: string; uid: number | string; name: string }[]
|
||||||
@@ -376,6 +378,14 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setOutputType(value);
|
setOutputType(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleModelChange = (value: string) => {
|
||||||
|
const model = modelList.find((item) => item.value === value);
|
||||||
|
if (model) {
|
||||||
|
console.log('model:', model);
|
||||||
|
setMetaData(model.meta || {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const outputItems = useMemo(() => {
|
const outputItems = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -696,12 +706,25 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
<div className="box">
|
<div className="box">
|
||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={formRef}
|
ref={formRef}
|
||||||
|
onModelChange={handleModelChange}
|
||||||
setParams={setParams}
|
setParams={setParams}
|
||||||
paramsConfig={paramsConfig}
|
paramsConfig={paramsConfig}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
params={parameters}
|
params={parameters}
|
||||||
selectedModel={selectModel}
|
selectedModel={selectModel}
|
||||||
modelList={modelList}
|
modelList={modelList}
|
||||||
|
extra={
|
||||||
|
metaData?.n_ctx &&
|
||||||
|
metaData?.n_slot && (
|
||||||
|
<Form.Item>
|
||||||
|
<SealInputNumber
|
||||||
|
disabled
|
||||||
|
label="Max Tokens"
|
||||||
|
value={_.divide(metaData?.n_ctx, metaData?.n_slot)}
|
||||||
|
></SealInputNumber>
|
||||||
|
</Form.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -164,7 +164,6 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
url: CHAT_API,
|
url: CHAT_API,
|
||||||
signal
|
signal
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result?.error) {
|
if (result?.error) {
|
||||||
setTokenResult({
|
setTokenResult({
|
||||||
error: true,
|
error: true,
|
||||||
@@ -186,7 +185,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
joinMessage(chunk);
|
joinMessage(chunk);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log('error:', error);
|
console.log('error:', error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AlertInfo from '@/components/alert-info';
|
import AlertInfo from '@/components/alert-info';
|
||||||
|
import SealInputNumber from '@/components/seal-form/input-number';
|
||||||
import HotKeys, { KeyMap } from '@/config/hotkeys';
|
import HotKeys, { KeyMap } from '@/config/hotkeys';
|
||||||
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
||||||
import useRequestToken from '@/hooks/use-request-token';
|
import useRequestToken from '@/hooks/use-request-token';
|
||||||
@@ -9,7 +10,7 @@ import {
|
|||||||
SendOutlined
|
SendOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { useIntl, useSearchParams } from '@umijs/max';
|
import { useIntl, useSearchParams } from '@umijs/max';
|
||||||
import { Button, Checkbox, Input, Spin, Tag, Tooltip } from 'antd';
|
import { Button, Checkbox, Form, Input, Spin, Tag, Tooltip } from 'antd';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import 'overlayscrollbars/overlayscrollbars.css';
|
import 'overlayscrollbars/overlayscrollbars.css';
|
||||||
@@ -125,6 +126,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const [sortIndexMap, setSortIndexMap] = useState<number[]>([]);
|
const [sortIndexMap, setSortIndexMap] = useState<number[]>([]);
|
||||||
const [queryValue, setQueryValue] = useState<string>('');
|
const [queryValue, setQueryValue] = useState<string>('');
|
||||||
const selectionTextRef = useRef<any>(null);
|
const selectionTextRef = useRef<any>(null);
|
||||||
|
const [metaData, setMetaData] = useState<any>({});
|
||||||
|
|
||||||
const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } =
|
const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } =
|
||||||
useOverlayScroller();
|
useOverlayScroller();
|
||||||
@@ -426,6 +428,13 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleModelChange = (value: string) => {
|
||||||
|
const model = modelList.find((item) => item.value === value);
|
||||||
|
if (model) {
|
||||||
|
setMetaData(model.meta || {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleClearDocuments = () => {
|
const handleClearDocuments = () => {
|
||||||
setTextList([
|
setTextList([
|
||||||
{
|
{
|
||||||
@@ -623,10 +632,23 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
ref={formRef}
|
ref={formRef}
|
||||||
setParams={setParams}
|
setParams={setParams}
|
||||||
params={parameters}
|
params={parameters}
|
||||||
|
onModelChange={handleModelChange}
|
||||||
paramsConfig={paramsConfig}
|
paramsConfig={paramsConfig}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
selectedModel={selectModel}
|
selectedModel={selectModel}
|
||||||
modelList={modelList}
|
modelList={modelList}
|
||||||
|
extra={
|
||||||
|
metaData?.n_ctx &&
|
||||||
|
metaData?.n_slot && (
|
||||||
|
<Form.Item>
|
||||||
|
<SealInputNumber
|
||||||
|
disabled
|
||||||
|
label="Max Tokens"
|
||||||
|
value={_.divide(metaData?.n_ctx, metaData?.n_slot)}
|
||||||
|
></SealInputNumber>
|
||||||
|
</Form.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ const PlaygroundEmbedding: React.FC = () => {
|
|||||||
const list = _.map(res.data || [], (item: any) => {
|
const list = _.map(res.data || [], (item: any) => {
|
||||||
return {
|
return {
|
||||||
value: item.id,
|
value: item.id,
|
||||||
label: item.id
|
label: item.id,
|
||||||
|
meta: item.meta
|
||||||
};
|
};
|
||||||
}) as Global.BaseOption<string>[];
|
}) as Global.BaseOption<string>[];
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ const PlaygroundRerank: React.FC = () => {
|
|||||||
const list = _.map(res.data || [], (item: any) => {
|
const list = _.map(res.data || [], (item: any) => {
|
||||||
return {
|
return {
|
||||||
value: item.id,
|
value: item.id,
|
||||||
label: item.id
|
label: item.id,
|
||||||
|
meta: item.meta
|
||||||
};
|
};
|
||||||
}) as Global.BaseOption<string>[];
|
}) as Global.BaseOption<string>[];
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const requestConfig: RequestConfig = {
|
|||||||
errorHandler: (error: any, opts: any) => {
|
errorHandler: (error: any, opts: any) => {
|
||||||
const { message: errorMessage, response } = error;
|
const { message: errorMessage, response } = error;
|
||||||
const errMsg = response?.data?.message || errorMessage;
|
const errMsg = response?.data?.message || errorMessage;
|
||||||
|
|
||||||
if (!opts?.skipErrorHandler && response?.status) {
|
if (!opts?.skipErrorHandler && response?.status) {
|
||||||
message.error(errMsg);
|
message.error(errMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,21 @@ const extractJSON = (dataStr: string) => {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const errorHandler = async (res: any) => {
|
||||||
|
try {
|
||||||
|
const data = await res.json();
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
data: data
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: res.statusText
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param params data: for post request, params: for get request
|
* @param params data: for post request, params: for get request
|
||||||
@@ -51,11 +66,11 @@ export const fetchChunkedData = async (params: {
|
|||||||
...params.headers
|
...params.headers
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('response====', response);
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
data: await response.json()
|
data: await errorHandler(response)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const reader = response?.body?.getReader();
|
const reader = response?.body?.getReader();
|
||||||
@@ -107,7 +122,7 @@ export const fetchChunkedDataPostFormData = async (params: {
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
data: await response.json()
|
data: await errorHandler(response)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const reader = response?.body?.getReader();
|
const reader = response?.body?.getReader();
|
||||||
|
|||||||
Reference in New Issue
Block a user