From 1a3d4b65d1f7a0c0f005ea8bb6cbcdb5d31a1298 Mon Sep 17 00:00:00 2001 From: panyy Date: Thu, 2 Jul 2026 16:43:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=9F=A5=E8=AF=86=E5=BA=93=E6=A3=80?= =?UTF-8?q?=E7=B4=A2=E5=B7=B2=E7=BB=8F=E5=91=BD=E4=B8=AD=E4=BA=86=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=20vLLM=20=E6=B5=81=E5=BC=8F=E5=9B=9E=E7=AD=94?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=AD=A3=E5=B8=B8=E5=90=90=E6=AD=A3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/vllm_model_provider/model/llm.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/models_provider/impl/vllm_model_provider/model/llm.py b/apps/models_provider/impl/vllm_model_provider/model/llm.py index 6304c9150..8d9905c36 100644 --- a/apps/models_provider/impl/vllm_model_provider/model/llm.py +++ b/apps/models_provider/impl/vllm_model_provider/model/llm.py @@ -3,7 +3,7 @@ from typing import Dict, List from urllib.parse import urlparse, ParseResult -from langchain_core.messages import BaseMessage, get_buffer_string +from langchain_core.messages import BaseMessage, get_buffer_string, AIMessageChunk from common.config.tokenizer_manage_config import TokenizerManage from models_provider.base_model_provider import MaxKBBaseModel @@ -48,3 +48,18 @@ class VllmChatModel(MaxKBBaseModel, BaseChatOpenAI): tokenizer = TokenizerManage.get_tokenizer() return len(tokenizer.encode(text)) return self.get_last_generation_info().get('output_tokens', 0) + + def stream(self, input, config=None, *, stop=None, **kwargs): + has_content = False + for chunk in super().stream(input, config=config, stop=stop, **kwargs): + content = getattr(chunk, 'content', '') or '' + reasoning_content = (getattr(chunk, 'additional_kwargs', {}) or {}).get('reasoning_content', '') + if content or reasoning_content: + has_content = True + yield chunk + if not has_content: + result = self.invoke(input, config=config, stop=stop, **kwargs) + yield AIMessageChunk( + content=getattr(result, 'content', '') or '', + additional_kwargs=getattr(result, 'additional_kwargs', {}) or {} + )