Skip to content

Commit

Permalink
Feat/0.2.3.1 (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgqgit authored Mar 14, 2024
2 parents d06ce50 + 628c6ae commit 2579ffb
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 74 deletions.
3 changes: 2 additions & 1 deletion src/backend/bisheng/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from importlib import metadata

from bisheng.cache import cache_manager # noqa: E402
from bisheng.interface.custom.custom_component import CustomComponent
from bisheng.processing.process import load_flow_from_json # noqa: E402

try:
Expand All @@ -11,4 +12,4 @@
del metadata # optional, avoids polluting the results of dir(__package__)


__all__ = ['load_flow_from_json', 'cache_manager']
__all__ = ['load_flow_from_json', 'cache_manager', 'CustomComponent']
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from bisheng.interface.custom import CustomComponent
from bisheng import CustomComponent
from bisheng.field_typing import Data


class Component(CustomComponent):
documentation: str = "http://docs.langflow.org/components/custom"
documentation: str = 'http://docs.bisheng.org/components/custom'

def build_config(self):
return {"param": {"display_name": "Parameter"}}
return {'param': {'display_name': 'Parameter'}}

def build(self, param: Data) -> Data:
return param
2 changes: 1 addition & 1 deletion src/backend/bisheng/graph/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def update_template(template, g_nodes):
node_index = next((i for i, n in enumerate(g_nodes) if n['id'] == id_), -1)
if node_index != -1:
display_name = None
show = g_nodes[node_index]['data']['node']['template'][field]['show']
show = g_nodes[node_index]['data']['node']['template'][field].get('show', False)
advanced = g_nodes[node_index]['data']['node']['template'][field]['advanced']
if 'display_name' in g_nodes[node_index]['data']['node']['template'][field]:
display_name = g_nodes[node_index]['data']['node']['template'][field][
Expand Down
2 changes: 1 addition & 1 deletion src/backend/bisheng/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _build_params(self):
elif isinstance(val, dict):
params[key] = val
elif isinstance(val, str):
params[key] = json.loads(val)
params[key] = json.loads(val) if val else {}
elif value.get('type') == 'int' and val is not None:
try:
params[key] = int(val)
Expand Down
6 changes: 6 additions & 0 deletions src/backend/bisheng/interface/importing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def import_by_type(_type: str, name: str) -> Any:
'retrievers': import_retriever,
'autogen_roles': import_autogenRoles,
'input_output': import_inputoutput,
'custom_components': import_custom_component,
}
if _type == 'llms':
key = 'contribute' if name in chat_models.__all__ else 'chat' if 'chat' in name.lower(
Expand All @@ -66,6 +67,11 @@ def import_by_type(_type: str, name: str) -> Any:
return loaded_func(name)


def import_custom_component(custom_component: str) -> CustomComponent:
"""Import custom component from custom component name"""
return import_class('bisheng.interface.custom.custom_component.CustomComponent')


def import_inputoutput(input_output: str) -> Any:
"""Import output parser from output parser name"""
return import_module(f'from bisheng_langchain.input_output import {input_output}')
Expand Down
3 changes: 2 additions & 1 deletion src/backend/bisheng/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@


def handle_http_exception(req: Request, exc: HTTPException) -> ORJSONResponse:
msg = {'status_code': exc.status_code, 'status_message': exc.detail}
msg = {'status_code': exc.status_code,
'status_message': exc.detail['error'] if isinstance(exc.detail, dict) else exc.detail}
logger.error(f'{req.method} {req.url} {exc.status_code} {exc.detail}')
return ORJSONResponse(content=msg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from bisheng.template.frontend_node.base import FrontendNode
from bisheng.template.template.base import Template

DEFAULT_CUSTOM_COMPONENT_CODE = """from bisheng.interface.custom import CustomComponent
DEFAULT_CUSTOM_COMPONENT_CODE = """from bisheng import CustomComponent
from typing import Optional, List, Dict, Union
from bisheng.field_typing import (
AgentExecutor,
Expand Down
3 changes: 2 additions & 1 deletion src/backend/bisheng/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def get_base_classes(cls):
"""Get the base classes of a class.
These are used to determine the output of the nodes.
"""
if bases := cls.__bases__:
if hasattr(cls, '__bases__') and cls.__bases__:
bases = cls.__bases__
result = []
for base in bases:
if any(type in base.__module__ for type in ['pydantic', 'abc']):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .host_llm import CustomLLMChat, HostBaichuanChat, HostChatGLM, HostLlama2Chat, HostQwenChat, HostYuanChat, HostYiChat
from .host_llm import CustomLLMChat, HostBaichuanChat, HostChatGLM, HostLlama2Chat, HostQwenChat, HostQwen1_5Chat, HostYuanChat, HostYiChat
from .minimax import ChatMinimaxAI
from .proxy_llm import ProxyChatLLM
from .qwen import ChatQWen
Expand All @@ -10,5 +10,5 @@
__all__ = [
'ProxyChatLLM', 'ChatMinimaxAI', 'ChatWenxin', 'ChatZhipuAI', 'ChatXunfeiAI', 'HostChatGLM',
'HostBaichuanChat', 'HostLlama2Chat', 'HostQwenChat', 'CustomLLMChat', 'ChatQWen', 'SenseChat',
'HostYuanChat', 'HostYiChat'
'HostYuanChat', 'HostYiChat', 'HostQwen1_5Chat'
]
13 changes: 13 additions & 0 deletions src/bisheng-langchain/bisheng_langchain/chat_models/host_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,19 @@ def _llm_type(self) -> str:
return 'qwen_chat'


class HostQwen1_5Chat(BaseHostChatLLM):
# Qwen-7B-Chat
model_name: str = Field('Qwen1.5-14B-Chat', alias='model')

temperature: float = 0
top_p: float = 1
max_tokens: int = 4096

@property
def _llm_type(self) -> str:
"""Return type of chat model."""
return 'qwen_chat'

class HostLlama2Chat(BaseHostChatLLM):
# Llama-2-7b-chat-hf, Llama-2-13b-chat-hf, Llama-2-70b-chat-hf
model_name: str = Field('Llama-2-7b-chat-hf', alias='model')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function ParameterComponent({
required = false,
optionalHandle = null,
info = "",
isGroup = false,
onChange
}: ParameterComponentType) {
// console.log('data, id :>> ', name, optionalHandle);
Expand Down Expand Up @@ -332,6 +333,7 @@ export default function ParameterComponent({
{data.node.template[name].list ? (
// input list
<InputListComponent
isGroup={isGroup}
disabled={disabled}
value={
!data.node.template[name].value ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function L2ParameterComponent({
value={data.node.template[name].value ?? ""}
onChange={handleOnNewValue}
/>
) : ['index_name', 'collection_name'].includes(name) ? (
) : ['index_name', 'collection_name'].some(key => name.indexOf(key) === 0) ? (
// 知识库选择
<CollectionNameComponent
setNodeClass={(nodeClass) => {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default function GenericNode({ data, xPos, yPos, selected }: {
!data.node.template[t].advanced ? (
<ParameterComponent
data={data}
isGroup={isGroup}
color={
nodeColors[types[data.node.template[t].type]] ??
nodeColors[data.node.template[t].type] ??
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/src/alerts/confirm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import i18next from "i18next";
import { useRef, useState } from "react";
import ReactDOM from "react-dom";
import { Button } from "../../components/ui/button";
import { X } from "lucide-react";

interface ConfirmParams {
title?: string
desc: string | React.ReactNode
canelTxt?: string
okTxt?: string
showClose?: boolean
onClose?: () => void
onCancel?: () => void
onOk?: (next) => void
Expand Down Expand Up @@ -41,10 +43,11 @@ function ConfirmWrapper() {
}

if (!paramRef.current) return null
const { title, desc, okTxt, canelTxt } = paramRef.current
const { title, desc, okTxt, canelTxt, showClose = false } = paramRef.current

return <dialog className={`modal ${open && 'modal-open'}`}>
<form method="dialog" className="modal-box w-[360px] bg-[#fff] shadow-lg dark:bg-background">
<form method="dialog" className="modal-box w-[360px] bg-[#fff] shadow-lg dark:bg-background relative">
{showClose && <X size={20} onClick={close} className="absolute right-4 cursor-pointer text-gray-400 hover:text-gray-600"></X>}
<h3 className="font-bold text-lg">{title}</h3>
<p className="py-4">{desc}</p>
<div className="modal-action">
Expand Down
7 changes: 4 additions & 3 deletions src/frontend/src/components/inputListComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function InputListComponent({
value,
onChange,
disabled,
isGroup = false,
editNode = false
}: InputListComponentType) {
const [inputList, setInputList] = useState(value ?? [""]);
Expand Down Expand Up @@ -38,9 +39,9 @@ export default function InputListComponent({
return (
<div
ref={scrollBodyRef}
className={
(disabled ? "pointer-events-none cursor-not-allowed" : "") +
"flex flex-col gap-3 template-scrollbar"
className={`${disabled ? "pointer-events-none cursor-not-allowed" : ""}
flex flex-col gap-3 template-scrollbar
${isGroup && "max-h-[170px]"}`
}
>
{inputList.map((i, idx) => {
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/modals/formModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default function FormModal({
files?: Array<any>;
}) {
setChatHistory((old) => {
if (!old.length) return old // 拒绝 chatHistory无数据时接收数据
let newChat = [...old];
let prevChat = newChat[newChat.length - 2]
// let lastChat = newChat[newChat.length - 1]
Expand Down Expand Up @@ -175,7 +176,7 @@ export default function FormModal({

function handleOnClose(event: CloseEvent) {
if (isOpen.current) {
setErrorData({ title: event.reason });
setErrorData({ title: 'ws is close;' + event.reason });
setTimeout(() => {
connectWS();
setLockChat(false);
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/pages/ChatAppPage/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const ChatMessage = ({ chat, userName, disabledReSend, showSearch, onSour
remarkPlugins={[remarkGfm, remarkMath]}
rehypePlugins={[rehypeMathjax]}
linkTarget="_blank"
className="markdown prose inline-block break-words text-primary dark:prose-invert max-w-full text-sm"
className="markdown prose inline-block break-all text-primary dark:prose-invert max-w-full text-sm"
components={{
code: ({ node, inline, className, children, ...props }) => {
if (children.length) {
Expand Down Expand Up @@ -125,7 +125,7 @@ export const ChatMessage = ({ chat, userName, disabledReSend, showSearch, onSour
() => (
chat.thought && <ReactMarkdown
linkTarget="_blank"
className="markdown prose text-gray-600 inline-block break-words max-w-full text-sm"
className="markdown text-gray-600 inline-block break-all max-w-full text-sm"
>
{chat.thought.toString()}
</ReactMarkdown>
Expand Down
64 changes: 36 additions & 28 deletions src/frontend/src/pages/ChatAppPage/components/ChatPanne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default forwardRef(function ChatPanne({ chatId, flow, queryString, versio
// build
const build = useBuild(flow, chatId)
// 消息列表
const { messages, messagesRef, loadHistory, setChatHistory, changeHistoryByScroll } = useMessages(chatId, flow)
const { messages, messagesRef, loadHistory, setChatHistory, initGuide, changeHistoryByScroll } = useMessages(chatId, flow)
// ws通信
const { stop, connectWS, begin: chating, checkReLinkWs, sendAll } = useWebsocket(chatId, flow, setChatHistory, queryString, version)
// 停止状态
Expand All @@ -50,7 +50,7 @@ export default forwardRef(function ChatPanne({ chatId, flow, queryString, versio
const initChat = async () => {
await checkPrompt(flow)
await build()
const historyData = version === 'v1' ? await loadHistory() : []
const historyData = version === 'v1' ? await loadHistory() : (initGuide(), [])
await connectWS({ setInputState, setIsStop, changeHistoryByScroll })
setInputState({ lock: false, errorMsg: '' });
// 第一条消息,用来初始化会话
Expand Down Expand Up @@ -384,33 +384,11 @@ const useMessages = (chatId, flow) => {
if (lastId) {
historyData = [...hisData.reverse(), ...chatHistory]
} else if (loadIdRef.current === chatId) { // 保证同一会话
historyData = !hisData.length && flow.guide_word ? [{
"category": "system",
"chat_id": chatId,
"end": true,
"create_time": "",
"extra": "{}",
"files": [],
"flow_id": flow.id,
"id": 9999,
"thought": flow.guide_word,
"is_bot": true,
"liked": 0,
"message": '',
"receiver": null,
"remark": null,
"sender": "",
"solved": 0,
isSend: false,
"source": 0,
"type": "end",
"update_time": "",
noAccess: true,
"user_id": 0
}] : hisData.reverse()
historyData = hisData.reverse()
}

setChatHistory(historyData)
const pageSize = historyData.length < 30 ? 30 : 10 // 先偷懒
if (hisData.length < pageSize) initGuide()
return historyData
}

Expand All @@ -430,6 +408,36 @@ const useMessages = (chatId, flow) => {
}, 500);
}

const initGuide = () => {
const guideMsg = {
"category": "system",
"chat_id": chatId,
"end": true,
"create_time": "",
"extra": "{}",
"files": [],
"flow_id": flow.id,
"id": 9999,
"thought": flow.guide_word,
"is_bot": true,
"liked": 0,
"message": '',
"receiver": null,
"remark": null,
"sender": "",
"solved": 0,
isSend: false,
"source": 0,
"type": "end",
"update_time": "",
noAccess: true,
"user_id": 0
}
flow.guide_word && setChatHistory((chatHistory) =>
chatHistory[0]?.id === 9999 ? chatHistory : [guideMsg, ...chatHistory]
)
}

// 消息滚动
const messagesRef = useRef(null);
useEffect(() => {
Expand All @@ -451,7 +459,7 @@ const useMessages = (chatId, flow) => {
}, [messagesRef.current, chatHistory, chatId]);

return {
messages: chatHistory, messagesRef, loadHistory, setChatHistory, changeHistoryByScroll
messages: chatHistory, messagesRef, loadHistory, setChatHistory, initGuide, changeHistoryByScroll
}
}

Expand Down
Loading

0 comments on commit 2579ffb

Please sign in to comment.