From 22f90a505c41ac1608c4ffea3be4dc49824e24a2 Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 20 Nov 2024 17:50:26 +0800 Subject: [PATCH] chore: hf api use proxy --- src/locales/en-US/models.ts | 2 +- src/locales/zh-CN/models.ts | 2 +- src/pages/llmodels/apis/index.ts | 23 +++----- .../llmodels/components/advance-config.tsx | 10 ++++ src/pages/llmodels/components/model-card.tsx | 52 +++++++++++-------- src/pages/llmodels/components/table-list.tsx | 5 +- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/locales/en-US/models.ts b/src/locales/en-US/models.ts index b8167091..d9b97daf 100644 --- a/src/locales/en-US/models.ts +++ b/src/locales/en-US/models.ts @@ -70,5 +70,5 @@ export default { 'models.logs.pagination.prev': 'Previous {lines} Lines', 'models.logs.pagination.next': 'Next {lines} Lines', 'models.form.localPath': 'Local Path', - 'models.form.filePath': 'File Path' + 'models.form.filePath': 'Model Path' }; diff --git a/src/locales/zh-CN/models.ts b/src/locales/zh-CN/models.ts index 8dbd1f50..ffeb3ff6 100644 --- a/src/locales/zh-CN/models.ts +++ b/src/locales/zh-CN/models.ts @@ -68,5 +68,5 @@ export default { 'models.logs.pagination.prev': '上一 {lines} 行', 'models.logs.pagination.next': '下一 {lines} 行', 'models.form.localPath': '本地路径', - 'models.form.filePath': '文件路径' + 'models.form.filePath': '模型路径' }; diff --git a/src/pages/llmodels/apis/index.ts b/src/pages/llmodels/apis/index.ts index bee050c4..10d4753d 100644 --- a/src/pages/llmodels/apis/index.ts +++ b/src/pages/llmodels/apis/index.ts @@ -113,19 +113,7 @@ export async function queryModelInstanceLogs(id: number) { // ===================== call huggingface quicksearch api ===================== -export async function callHuggingfaceQuickSearch(params: any) { - return request<{ - models: Array<{ - id: string; - _id: string; - }>; - }>(`https://huggingface.co/api/quicksearch`, { - method: 'GET', - params - }); -} - -const HUGGINGFACE_API = 'https://huggingface.co/api/models'; +const HUGGINGFACE_API = '/proxy?url=https://huggingface.co/api/models'; const MODEL_SCOPE_LIST_MODEL_API = '/proxy?url=https://www.modelscope.cn/api/v1/dolphin/models'; @@ -221,6 +209,7 @@ export async function queryModelScopeModelFiles( return res.json(); } +// list models from huggingface export async function queryHuggingfaceModels( params: { search: { @@ -238,7 +227,8 @@ export async function queryHuggingfaceModels( ...options, limit: 100, additionalFields: ['sha', 'tags'], - fetch(url: string, config: any) { + fetch(_url: string, config: any) { + const url = `/proxy?url=${_url}`; try { const newUrl = params.search.sort ? `${url}&sort=${params.search.sort}` @@ -258,6 +248,7 @@ export async function queryHuggingfaceModels( return result; } +// list files from huggingface export async function queryHuggingfaceModelFiles( params: { repo: string }, options?: any @@ -268,7 +259,7 @@ export async function queryHuggingfaceModelFiles( recursive: true, fetch(url: string, config: any) { try { - return fetch(url, { + return fetch(`/proxy?url=${url}`, { ...config, signal: options?.signal }); @@ -295,7 +286,7 @@ export async function downloadModelFile( revision: revision, path: path, fetch(url: string, config: any) { - return fetch(url, { + return fetch(`/proxy?url=${url}`, { ...config, signal: options?.signal }); diff --git a/src/pages/llmodels/components/advance-config.tsx b/src/pages/llmodels/components/advance-config.tsx index 41233497..3f9afdc8 100644 --- a/src/pages/llmodels/components/advance-config.tsx +++ b/src/pages/llmodels/components/advance-config.tsx @@ -131,6 +131,15 @@ const AdvanceConfig: React.FC = (props) => { form.setFieldValue('backend_parameters', list); }, []); + const handleBackendChange = useCallback((val: string) => { + if (val === backendOptionsMap.llamaBox) { + form.setFieldsValue({ + distributed_inference_across_workers: true, + cpu_offloading: true + }); + } + }, []); + const collapseItems = useMemo(() => { const children = ( <> @@ -239,6 +248,7 @@ const AdvanceConfig: React.FC = (props) => { )} ) : ( - + <> + {!loading && ( + + )} + )} - {!isGGUFModel && readmeText && ( -
- -
README.md
-
-
- - - + {!isGGUFModel && ( + +
+ {readmeText && ( + <> + +
README.md
+
+
+ +
+ + )}
-
+ )} ); diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index ff8e6cb1..ff7ea077 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -461,10 +461,7 @@ const Models: React.FC = ({ return `${modelSourceMap.huggingface}/${record.huggingface_repo_id}`; } if (record.source === modelSourceMap.local_path_value) { - const localPath = _.startsWith(record.local_path, '/') - ? record.local_path - : `/${record.local_path}`; - return `${modelSourceMap.local_path}${localPath}`; + return `${record.local_path}`; } if (record.source === modelSourceMap.ollama_library_value) { return `${modelSourceMap.ollama_library}/${record.ollama_library_model_name}`;