From 3f065c75da22edea7e6197045d7c2789d5740607 Mon Sep 17 00:00:00 2001 From: JobSmithManipulation <143315462+JobSmithManipulation@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:45:48 +0800 Subject: [PATCH] support chat model in huggingface (#2802) ### What problem does this PR solve? #2794 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- rag/llm/__init__.py | 1 + rag/llm/chat_model.py | 8 +++++++- .../user-setting/setting-model/ollama-modal/index.tsx | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rag/llm/__init__.py b/rag/llm/__init__.py index c7a820d2f..8ad059fb0 100644 --- a/rag/llm/__init__.py +++ b/rag/llm/__init__.py @@ -107,6 +107,7 @@ ChatModel = { "BaiduYiyan": BaiduYiyanChat, "Anthropic": AnthropicChat, "Google Cloud": GoogleChat, + "HuggingFace": HuggingFaceChat, } RerankModel = { diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index d18fc02e9..bf91dbf0f 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -104,7 +104,13 @@ class XinferenceChat(Base): if base_url.split("/")[-1] != "v1": base_url = os.path.join(base_url, "v1") super().__init__(key, model_name, base_url) - +class HuggingFaceChat(Base): + def __init__(self, key=None, model_name="", base_url=""): + if not base_url: + raise ValueError("Local llm url cannot be None") + if base_url.split("/")[-1] != "v1": + base_url = os.path.join(base_url, "v1") + super().__init__(key, model_name, base_url) class DeepSeekChat(Base): def __init__(self, key, model_name="deepseek-chat", base_url="https://api.deepseek.com/v1"): diff --git a/web/src/pages/user-setting/setting-model/ollama-modal/index.tsx b/web/src/pages/user-setting/setting-model/ollama-modal/index.tsx index c372b2f3f..18bcdb6c5 100644 --- a/web/src/pages/user-setting/setting-model/ollama-modal/index.tsx +++ b/web/src/pages/user-setting/setting-model/ollama-modal/index.tsx @@ -54,7 +54,10 @@ const OllamaModal = ({ llmFactoryToUrlMap[llmFactory as LlmFactory] || 'https://github.com/infiniflow/ragflow/blob/main/docs/guides/deploy_local_llm.mdx'; const optionsMap = { - HuggingFace: [{ value: 'embedding', label: 'embedding' }], + HuggingFace: [ + { value: 'embedding', label: 'embedding' }, + { value: 'chat', label: 'chat' }, + ], Xinference: [ { value: 'chat', label: 'chat' }, { value: 'embedding', label: 'embedding' },