fix: download file error

This commit is contained in:
jialin
2025-11-12 11:01:13 +08:00
parent 7eedea8035
commit 11a676be83
16 changed files with 77 additions and 50 deletions
+1
View File
@@ -384,6 +384,7 @@ export async function queryCatalogItemSpec(
export async function evaluationsModelSpec(
data: {
cluster_id: number;
model_specs: EvaluateSpec[];
},
options: { token: any }
@@ -191,25 +191,6 @@ const AddModal: React.FC<AddModalProps> = (props) => {
size: number;
quantization: string;
}) => {
// const spec = _.find(specListRef.current, (item: CatalogSpec) => {
// if (data.size && data.quantization) {
// return (
// item.size === data.size &&
// item.backend === data.backend &&
// item.quantization === data.quantization
// );
// }
// if (data.size) {
// return item.size === data.size && item.backend === data.backend;
// }
// if (data.quantization) {
// return (
// item.quantization === data.quantization &&
// item.backend === data.backend
// );
// }
// return item.backend === data.backend;
// });
const defaultSpec = _.find(
specListRef.current,
(item: CatalogSpec) => item.mode === data.mode
@@ -252,6 +252,7 @@ const SearchModel: React.FC<SearchInputProps> = (props) => {
checkTokenRef.current = createAxiosToken();
const evaluations = await evaluationsModelSpec(
{
cluster_id: clusterId!,
model_specs: repoList
},
{
@@ -170,6 +170,10 @@ export const setModelActionList = (record: any) => {
return record.replicas > 0;
}
if (action.key === 'proxy') {
return record.generic_proxy;
}
return true;
});
};
+1
View File
@@ -86,6 +86,7 @@ const DownloadModel: React.FC<AddModalProps> = (props) => {
const handleOnSelectModel = (item: any) => {
setSelectedModel(item);
setFileName('');
};
const handleOk = async (values: any) => {
+12
View File
@@ -41,6 +41,15 @@ const KVCacheForm = () => {
);
};
const handleRamRatioChange = (
value: number | null | string,
field: string
) => {
if (!value) {
form.setFieldValue(['extended_kv_cache', field], null);
}
};
const builtInBackend = useMemo(() => {
const currentBackend = backendOptions.find(
(item) => item.value === backend
@@ -75,6 +84,7 @@ const KVCacheForm = () => {
<>
<Form.Item<FormData> name={['extended_kv_cache', 'ram_ratio']}>
<SealInputNumber
onChange={(value) => handleRamRatioChange(value, 'ram_ratio')}
label={intl.formatMessage({ id: 'models.form.ramRatio' })}
description={intl.formatMessage({
id: 'models.form.ramRatio.tips'
@@ -86,6 +96,7 @@ const KVCacheForm = () => {
</Form.Item>
<Form.Item<FormData> name={['extended_kv_cache', 'ram_size']}>
<SealInputNumber
onChange={(value) => handleRamRatioChange(value, 'ram_size')}
label={intl.formatMessage({ id: 'models.form.ramSize' })}
description={intl.formatMessage(
{
@@ -100,6 +111,7 @@ const KVCacheForm = () => {
</Form.Item>
<Form.Item<FormData> name={['extended_kv_cache', 'chunk_size']}>
<SealInputNumber
onChange={(value) => handleRamRatioChange(value, 'chunk_size')}
label={intl.formatMessage({ id: 'models.form.chunkSize' })}
description={intl.formatMessage({
id: 'models.form.chunkSize.tips'
@@ -182,6 +182,7 @@ const SpeculativeDecode = () => {
label={intl.formatMessage({ id: 'models.form.numDraftTokens' })}
min={1}
step={1}
required
precision={0}
/>
</Form.Item>
+1
View File
@@ -180,6 +180,7 @@ export const useCheckCompatibility = () => {
});
const evalution = await evaluationsModelSpec(
{
cluster_id: data.cluster_id,
model_specs: [
{
..._.omit(data, ['scheduleType']),
+45 -18
View File
@@ -17,57 +17,72 @@ import { generateEmbeddingCurlCode } from '@/pages/playground/view-code/embeddin
import { generateImageCurlCode } from '@/pages/playground/view-code/image';
import { generateLLmCurlCode } from '@/pages/playground/view-code/llm';
import { generateRerankCurlCode } from '@/pages/playground/view-code/rerank';
import { formatCurlArgs } from '@/pages/playground/view-code/utils';
import { useIntl } from '@umijs/max';
import { useState } from 'react';
import { modelCategoriesMap } from '../config';
const API_MAP: Record<
string,
{ api: string; generateCurlCode: (args: any) => string }
{ api: string; parameters: any; generateCurlCode: (args: any) => string }
> = {
[modelCategoriesMap.embedding]: {
api: EMBEDDING_API,
parameters: {
query: 'What are the benefits of regular exercise?',
documents: [
'Regular physical activity helps improve cardiovascular health and mental well-being.',
'Eating too much sugar can lead to health issues.',
'Exercise is often done in gyms or outdoors.'
]
},
generateCurlCode: generateEmbeddingCurlCode
},
[modelCategoriesMap.llm]: {
api: CHAT_API,
parameters: {
messages: [
{
role: 'user',
content: 'Hello, introduce yourself'
}
]
},
generateCurlCode: generateLLmCurlCode
},
[modelCategoriesMap.image]: {
api: CREAT_IMAGE_API,
parameters: {},
generateCurlCode: generateImageCurlCode
},
[modelCategoriesMap.text_to_speech]: {
api: AUDIO_TEXT_TO_SPEECH_API,
parameters: {
response_format: 'mp3',
input: ''
},
generateCurlCode: generateTextToSpeechCurlCode
},
[modelCategoriesMap.speech_to_text]: {
api: AUDIO_SPEECH_TO_TEXT_API,
parameters: {},
generateCurlCode: generateSpeechToTextCurlCode
},
[modelCategoriesMap.reranker]: {
api: RERANKER_API,
parameters: {
messages: [
{
role: 'user',
content: 'Hello, introduce yourself'
}
]
},
generateCurlCode: generateRerankCurlCode
}
};
const langOptions = [{ label: 'Curl', value: 'bash' }];
const generateCode = ({ api: url, parameters }: Record<string, any>) => {
const host = window.location.origin;
const api = '/model/proxy/v1/';
// ========================= Curl =========================
const curlCode = `
curl ${host}${api} \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
${formatCurlArgs(parameters, false)}`.trim();
return curlCode;
};
const useGenericProxy = () => {
const intl = useIntl();
const [modalStatus, setModalStatus] = useState<{
@@ -88,6 +103,7 @@ const useGenericProxy = () => {
return {
category,
api: `${MODEL_PROXY}${config.api}`,
parameters: config.parameters,
generateCurlCode: config.generateCurlCode
};
}
@@ -95,12 +111,22 @@ const useGenericProxy = () => {
return {
category: modelCategoriesMap.llm,
api: CHAT_API,
parameters: {
messages: [
{
role: 'user',
content: 'Hello, introduce yourself'
}
]
},
generateCurlCode: generateLLmCurlCode
};
};
const openProxyModal = (data?: any) => {
const { api, generateCurlCode } = getModelCategory(data?.categories || []);
const { api, generateCurlCode, parameters } = getModelCategory(
data?.categories || []
);
setModalStatus({
open: true,
@@ -108,7 +134,8 @@ const useGenericProxy = () => {
api,
modelProxy: true,
parameters: {
model: data?.name || ''
model: data?.name || '',
...parameters
}
})
});
@@ -52,13 +52,13 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
handleAddNewMessage,
handleClear,
setMessageList,
formRef,
tokenResult,
messageList,
loading
} = useChatCompletion(scroller);
const {
handleOnValuesChange,
formRef,
paramsRef,
paramsConfig,
initialValues,
@@ -108,7 +108,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
return message;
};
const handleSendMessage = (message: Omit<MessageItem, 'uid'>) => {
const handleSendMessage = async (message: Omit<MessageItem, 'uid'>) => {
const currentMessage = generateValidMessage(message);
submitMessage({
system: systemMessage
@@ -23,6 +23,7 @@ export default function useChatCompletion(
const currentMessageRef = useRef<any>(null);
const messageListLengthCache = useRef<number>(0);
const reasonContentRef = useRef('');
const formRef = useRef<any>(null);
const setMessageId = () => {
messageId.current = messageId.current + 1;
@@ -43,7 +44,6 @@ export default function useChatCompletion(
};
const joinMessage = (chunk: any) => {
console.log('chunk:', chunk);
setTokenResult({
...(chunk?.usage ?? {})
});
@@ -217,6 +217,7 @@ export default function useChatCompletion(
loading,
tokenResult,
messageList,
formRef,
setMessageId,
setMessageList,
handleClear,
@@ -52,7 +52,6 @@ export const useInitLLmMeta = (
defaultValues = {},
defaultParamsConfig = []
} = options;
const formRef = useRef<any>(null);
const [searchParams] = useSearchParams();
const [modelMeta, setModelMeta] = useState<any>({});
const [initialValues, setInitialValues] = useState<any>({
@@ -76,8 +75,6 @@ export const useInitLLmMeta = (
return model;
}, [model, modelList, isChat]);
const getLLamaBoxMeta = (meta: any) => {};
const getMaxTokens = (meta: any) => {
const { max_model_len, n_ctx, n_slot, max_total_tokens } = meta || {};
@@ -197,7 +194,6 @@ export const useInitLLmMeta = (
setInitialValues,
setParams,
setParamsConfig,
formRef,
paramsConfig,
initialValues,
parameters,