From f12b9fdcd45a6c82b83d845ec5c6148f1a57a9e1 Mon Sep 17 00:00:00 2001 From: TensorNull <129579691+TensorNull@users.noreply.github.com> Date: Thu, 18 Sep 2025 09:51:29 +0800 Subject: [PATCH] Feat: add CometAPI to LLMFactory and update related mappings (#10119) ### Related issues #10078 ### What problem does this PR solve? Integrate CometAPI provider. ### Type of change - [x] New Feature (non-breaking change which adds functionality) - [x] Documentation Update --- conf/llm_factories.json | 271 ++++++++++++++++++++++++++- docs/references/supported_models.mdx | 1 + rag/llm/chat_model.py | 9 + rag/llm/embedding_model.py | 9 + rag/llm/sequence2txt_model.py | 10 + rag/llm/tts_model.py | 8 + web/src/assets/svg/llm/cometapi.svg | 6 + web/src/constants/llm.ts | 2 + web/src/utils/common-util.ts | 1 + 9 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 web/src/assets/svg/llm/cometapi.svg diff --git a/conf/llm_factories.json b/conf/llm_factories.json index b649530fc..686e97373 100644 --- a/conf/llm_factories.json +++ b/conf/llm_factories.json @@ -689,7 +689,7 @@ }, { "llm_name": "glm-4", - "tags":"LLM,CHAT,128K", + "tags": "LLM,CHAT,128K", "max_tokens": 128000, "model_type": "chat", "is_tools": true @@ -4541,6 +4541,273 @@ } ] }, + { + "name": "CometAPI", + "logo": "", + "tags": "LLM,TEXT EMBEDDING,IMAGE2TEXT", + "status": "1", + "llm": [ + { + "llm_name": "gpt-5-chat-latest", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "chatgpt-4o-latest", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-mini", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5-nano", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-5", + "tags": "LLM,CHAT,400k", + "max_tokens": 400000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-mini", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1-nano", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4.1", + "tags": "LLM,CHAT,1M", + "max_tokens": 1047576, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gpt-4o-mini", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o4-mini-2025-04-16", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "o3-pro-2025-06-10", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-opus-4-1-20250805-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-sonnet-4-20250514-thinking", + "tags": "LLM,CHAT,200k,IMAGE2TEXT", + "max_tokens": 200000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "claude-3-7-sonnet-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "claude-3-5-haiku-latest", + "tags": "LLM,CHAT,200k", + "max_tokens": 200000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-pro", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.5-flash-lite", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "gemini-2.0-flash", + "tags": "LLM,CHAT,1M,IMAGE2TEXT", + "max_tokens": 1000000, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "grok-4-0709", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-3-mini", + "tags": "LLM,CHAT,131k", + "max_tokens": 131072, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "grok-2-image-1212", + "tags": "LLM,CHAT,32k,IMAGE2TEXT", + "max_tokens": 32768, + "model_type": "image2text", + "is_tools": true + }, + { + "llm_name": "deepseek-v3.1", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-v3", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-r1-0528", + "tags": "LLM,CHAT,164k", + "max_tokens": 164000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-chat", + "tags": "LLM,CHAT,32k", + "max_tokens": 32000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "deepseek-reasoner", + "tags": "LLM,CHAT,64k", + "max_tokens": 64000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-30b-a3b", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "qwen3-coder-plus-2025-07-22", + "tags": "LLM,CHAT,128k", + "max_tokens": 128000, + "model_type": "chat", + "is_tools": true + }, + { + "llm_name": "text-embedding-ada-002", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-small", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "text-embedding-3-large", + "tags": "TEXT EMBEDDING,8K", + "max_tokens": 8191, + "model_type": "embedding", + "is_tools": false + }, + { + "llm_name": "whisper-1", + "tags": "SPEECH2TEXT", + "max_tokens": 26214400, + "model_type": "speech2text", + "is_tools": false + }, + { + "llm_name": "tts-1", + "tags": "TTS", + "max_tokens": 2048, + "model_type": "tts", + "is_tools": false + } + ] + }, { "name": "Meituan", "logo": "", @@ -4557,4 +4824,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/docs/references/supported_models.mdx b/docs/references/supported_models.mdx index f106ef850..8302bd308 100644 --- a/docs/references/supported_models.mdx +++ b/docs/references/supported_models.mdx @@ -65,6 +65,7 @@ A complete list of models supported by RAGFlow, which will continue to expand. | 01.AI | :heavy_check_mark: | | | | | | | DeepInfra | :heavy_check_mark: | :heavy_check_mark: | | | :heavy_check_mark: | :heavy_check_mark: | | 302.AI | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | +| CometAPI | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | ```mdx-code-block diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index 5ea610a8b..a2631920b 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -1356,6 +1356,15 @@ class Ai302Chat(Base): super().__init__(key, model_name, base_url, **kwargs) +class CometChat(Base): + _FACTORY_NAME = "CometAPI" + + def __init__(self, key, model_name, base_url="https://api.cometapi.com/v1", **kwargs): + if not base_url: + base_url = "https://api.cometapi.com/v1" + super().__init__(key, model_name, base_url, **kwargs) + + class TokenPonyChat(Base): _FACTORY_NAME = "TokenPony" diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.py index 3b147885b..904a45d9d 100644 --- a/rag/llm/embedding_model.py +++ b/rag/llm/embedding_model.py @@ -958,3 +958,12 @@ class Ai302Embed(Base): if not base_url: base_url = "https://api.302.ai/v1/embeddings" super().__init__(key, model_name, base_url) + + +class CometEmbed(Base): + _FACTORY_NAME = "CometAPI" + + def __init__(self, key, model_name, base_url="https://api.cometapi.com/v1/embeddings"): + if not base_url: + base_url = "https://api.cometapi.com/v1/embeddings" + super().__init__(key, model_name, base_url) diff --git a/rag/llm/sequence2txt_model.py b/rag/llm/sequence2txt_model.py index 66c3bbf10..b2d1a5aaa 100644 --- a/rag/llm/sequence2txt_model.py +++ b/rag/llm/sequence2txt_model.py @@ -234,3 +234,13 @@ class DeepInfraSeq2txt(Base): self.client = OpenAI(api_key=key, base_url=base_url) self.model_name = model_name + + +class CometSeq2txt(Base): + _FACTORY_NAME = "CometAPI" + + def __init__(self, key, model_name="whisper-1", base_url="https://api.cometapi.com/v1", **kwargs): + if not base_url: + base_url = "https://api.cometapi.com/v1" + self.client = OpenAI(api_key=key, base_url=base_url) + self.model_name = model_name diff --git a/rag/llm/tts_model.py b/rag/llm/tts_model.py index 9520cbbbf..e55d11141 100644 --- a/rag/llm/tts_model.py +++ b/rag/llm/tts_model.py @@ -394,3 +394,11 @@ class DeepInfraTTS(OpenAITTS): if not base_url: base_url = "https://api.deepinfra.com/v1/openai" super().__init__(key, model_name, base_url, **kwargs) + +class CometAPITTS(OpenAITTS): + _FACTORY_NAME = "CometAPI" + + def __init__(self, key, model_name, base_url="https://api.cometapi.com/v1", **kwargs): + if not base_url: + base_url = "https://api.cometapi.com/v1" + super().__init__(key, model_name, base_url, **kwargs) diff --git a/web/src/assets/svg/llm/cometapi.svg b/web/src/assets/svg/llm/cometapi.svg new file mode 100644 index 000000000..8d9811864 --- /dev/null +++ b/web/src/assets/svg/llm/cometapi.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/web/src/constants/llm.ts b/web/src/constants/llm.ts index 241afcb4a..a3909611a 100644 --- a/web/src/constants/llm.ts +++ b/web/src/constants/llm.ts @@ -56,6 +56,7 @@ export enum LLMFactory { XAI = 'xAI', TokenPony = 'TokenPony', Meituan = 'Meituan', + CometAPI = 'CometAPI', } // Please lowercase the file name @@ -117,4 +118,5 @@ export const IconMap = { [LLMFactory.XAI]: 'xai', [LLMFactory.TokenPony]: 'token-pony', [LLMFactory.Meituan]: 'longcat', + [LLMFactory.CometAPI]: 'cometapi', }; diff --git a/web/src/utils/common-util.ts b/web/src/utils/common-util.ts index 5e770eff0..5e17b15ec 100644 --- a/web/src/utils/common-util.ts +++ b/web/src/utils/common-util.ts @@ -44,6 +44,7 @@ const orderFactoryList = [ LLMFactory.Ollama, LLMFactory.Xinference, LLMFactory.Ai302, + LLMFactory.CometAPI, ]; export const sortLLmFactoryListBySpecifiedOrder = (list: IFactory[]) => {