Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过llm组件按钮控制是否流式输出,技能控制流式而非配置控制流式 #355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/backend/bisheng/chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from bisheng.database.base import session_getter
from bisheng.database.models.model_deploy import ModelDeploy
from bisheng.database.models.recall_chunk import RecallChunk
from bisheng.interface.utils import try_setting_streaming_options
from bisheng.processing.base import get_result_and_steps
from bisheng.utils.logger import logger
from bisheng_langchain.chat_models import HostQwenChat
Expand All @@ -21,7 +20,6 @@ async def process_graph(langchain_object,
websocket: WebSocket,
flow_id: str = None,
chat_id: str = None):
langchain_object = try_setting_streaming_options(langchain_object, websocket)
logger.debug('Loaded langchain object')

if langchain_object is None:
Expand Down
14 changes: 2 additions & 12 deletions src/backend/bisheng/interface/initialize/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any, Callable, Dict, Sequence, Type

from bisheng.cache.utils import file_download
from bisheng.chat.config import ChatConfig
from bisheng.interface.agents.base import agent_creator
from bisheng.interface.chains.base import chain_creator
from bisheng.interface.custom_lists import CUSTOM_NODES
Expand All @@ -24,7 +23,6 @@
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_toolkits.base import BaseToolkit
from langchain.agents.tools import BaseTool
from langchain.base_language import BaseLanguageModel
from langchain.chains.base import Chain
from langchain.document_loaders.base import BaseLoader
from langchain.vectorstores.base import VectorStore
Expand Down Expand Up @@ -214,18 +212,10 @@ def instantiate_llm(node_type, class_object, params: Dict):
params['max_tokens'] = int(params['max_tokens'])
elif not isinstance(params.get('max_tokens'), int):
params.pop('max_tokens', None)
# 支持stream
llm = class_object(**params)
llm_config = settings.get_from_db('llm_request')
if isinstance(llm, BaseLanguageModel):
if hasattr(llm, 'streaming') and isinstance(llm.streaming, bool):
llm.streaming = llm_config.get(
'stream') if 'stream' in llm_config else ChatConfig.streaming
elif hasattr(llm, 'stream') and isinstance(llm.stream, bool):
llm.stream = llm_config.get(
'stream') if 'stream' in llm_config else ChatConfig.streaming

# 支持request_timeout & max_retries
llm = class_object(**params)
llm_config = settings.get_from_db('llm_request')
if hasattr(llm, 'request_timeout') and 'request_timeout' in llm_config:
if isinstance(llm_config.get('request_timeout'), str):
llm.request_timeout = eval(llm_config.get('request_timeout'))
Expand Down
25 changes: 0 additions & 25 deletions src/backend/bisheng/interface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from io import BytesIO

import yaml
from bisheng.chat.config import ChatConfig
from bisheng.settings import settings
from bisheng.utils.logger import logger
from langchain.base_language import BaseLanguageModel
from PIL.Image import Image


Expand All @@ -35,28 +32,6 @@ def pil_to_base64(image: Image) -> str:
return img_str.decode('utf-8')


def try_setting_streaming_options(langchain_object, websocket):
# If the LLM type is OpenAI or ChatOpenAI,
# set streaming to True
# First we need to find the LLM
llm = None
if hasattr(langchain_object, 'llm'):
llm = langchain_object.llm
elif hasattr(langchain_object, 'llm_chain') and hasattr(langchain_object.llm_chain, 'llm'):
llm = langchain_object.llm_chain.llm

if isinstance(llm, BaseLanguageModel):
if hasattr(llm, 'streaming') and isinstance(llm.streaming, bool):
llm.streaming = settings.get_from_db('llm_request').get(
'stream') if 'stream' in settings.get_from_db(
'llm_request') else ChatConfig.streaming
elif hasattr(llm, 'stream') and isinstance(llm.stream, bool):
llm.stream = settings.get_from_db('llm_request').get(
'stream') if 'stream' in settings.get_from_db(
'llm_request') else ChatConfig.streaming
return langchain_object


def extract_input_variables_from_prompt(prompt: str) -> list[str]:
"""Extract input variables from prompt."""
return re.findall(r'{(.*?)}', prompt)
Expand Down
2 changes: 0 additions & 2 deletions src/backend/bisheng/services/chat/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from bisheng.api.v1.schemas import ChatMessage
from bisheng.interface.utils import try_setting_streaming_options
from bisheng.processing.base import get_result_and_steps
from loguru import logger

Expand All @@ -10,7 +9,6 @@ async def process_graph(
client_id: str,
session_id: str,
):
langchain_object = try_setting_streaming_options(langchain_object)
logger.debug('Loaded langchain object')

if langchain_object is None:
Expand Down
1 change: 1 addition & 0 deletions src/backend/bisheng/template/frontend_node/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def format_contribute_field(field: TemplateField):
'top_p',
'top_k',
'max_tokens',
'streaming'
]
if field.name in show_fields:
field.show = True
Expand Down