Skip to content

Commit

Permalink
Feat/0.3.7rc (#959)
Browse files Browse the repository at this point in the history
修复bug
  • Loading branch information
yaojin3616 authored Nov 20, 2024
2 parents 64ef893 + ea20909 commit 9fd7efe
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 67 deletions.
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: release
version: v0.3.7
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-backend
docker_user:
Expand Down Expand Up @@ -114,7 +114,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行
https_proxy:
from_secret: PROXY
no_proxy: 192.168.106.8
version: release
version: v0.3.7
docker_registry: http://192.168.106.8:6082
docker_repo: 192.168.106.8:6082/dataelement/bisheng-frontend
docker_user:
Expand Down Expand Up @@ -176,7 +176,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行
trigger:
branch:
- release
# - feat/*
- feat/0.3.7rc
event:
- push

Expand Down
70 changes: 38 additions & 32 deletions src/backend/bisheng/api/services/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@


class OpenApiSchema:

def __init__(self, contents: dict):
self.contents = contents
self.version = contents['openapi']
self.info = contents['info']
self.title = self.info['title']
self.description = self.info.get('description', '')

self.default_server = ""
self.default_server = ''
self.apis = []

def parse_server(self) -> str:
Expand All @@ -34,56 +35,61 @@ def parse_paths(self) -> list[dict]:
for path, path_info in paths.items():
for method, method_info in path_info.items():
one_api_info = {
"path": path,
"method": method,
"description": method_info.get('description', '') or method_info.get('summary', ''),
"operationId": method_info['operationId'],
"parameters": [],
'path': path,
'method': method,
'description': method_info.get('description', '')
or method_info.get('summary', ''),
'operationId': method_info['operationId'],
'parameters': [],
}
if method not in ['get', 'post', 'put', 'delete']:
continue

if "requestBody" in method_info:
for _, content in method_info["requestBody"]["content"].items():
if "$ref" in content["schema"]:
schema_ref = content["schema"]["$ref"]
schema_name = schema_ref.split("/")[-1]
schema = self.contents["components"]["schemas"][schema_name]
if 'requestBody' in method_info:
for _, content in method_info['requestBody']['content'].items():
if '$ref' in content['schema']:
schema_ref = content['schema']['$ref']
schema_name = schema_ref.split('/')[-1]
schema = self.contents['components']['schemas'][schema_name]
else:
schema = content["schema"]
schema = content['schema']

if "properties" in schema:
for param_name, param_info in schema["properties"].items():
if 'properties' in schema:
for param_name, param_info in schema['properties'].items():
param = {
"name": param_name,
"in": "body",
"required": param_name in schema.get("required", []),
"schema": {
"type": param_info.get("type", "string"),
"title": param_info.get("title", param_name),
'name': param_name,
'description': param_name,
'in': 'body',
'required': param_name in schema.get('required', []),
'schema': {
'type': param_info.get('type', 'string'),
'title': param_info.get('title', param_name),
}
}
one_api_info["parameters"].append(param)
one_api_info['parameters'].append(param)

one_api_info["parameters"].extend(method_info.get('parameters', []))
one_api_info['parameters'].extend(method_info.get('parameters', []))
self.apis.append(one_api_info)
return self.apis

@staticmethod
def parse_openapi_tool_params(name: str, description: str, extra: str, server_host: str,
auth_method: int, auth_type: str = None, api_key: str = None):
def parse_openapi_tool_params(name: str,
description: str,
extra: str,
server_host: str,
auth_method: int,
auth_type: str = None,
api_key: str = None):
# 拼接请求头
headers = {}
if auth_method == AuthMethod.API_KEY.value:
headers = {
"Authorization": f"{auth_type} {api_key}"
}
headers = {'Authorization': f'{auth_type} {api_key}'}

# 返回初始化 openapi所需的入参
params = {
"params": json.loads(extra),
"headers": headers,
"url": server_host,
"description": name + description if description else name
'params': json.loads(extra),
'headers': headers,
'url': server_host,
'description': name + description if description else name
}
return params
32 changes: 17 additions & 15 deletions src/backend/bisheng/api/v1/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,25 @@ def get_app_chat_list(*,



# if keyword:
# flows = FlowDao.get_flow_list_by_name(name=keyword)
# assistants, _ = AssistantDao.get_all_assistants(name=keyword, page=0, limit=0)
# users = UserDao.search_user_by_name(user_name=keyword)
# if flows:
# flow_ids = [flow.id for flow in flows]
# if assistants:
# flow_ids = flow_ids.extend([assistant.id for assistant in assistants])
# if user_ids:
# user_ids = [user.user_id for user in users]
# # 检索内容为空
# if not flow_ids and not user_ids:
# return resp_200(PageList(list=[], total=0))
if keyword:
flows = FlowDao.get_flow_list_by_name(name=keyword)
assistants, _ = AssistantDao.get_all_assistants(name=keyword, page=0, limit=0)
users = UserDao.search_user_by_name(user_name=keyword)
if flows:
flow_ids = [flow.id for flow in flows]
if assistants:
flow_ids = flow_ids.extend([assistant.id for assistant in assistants])
if user_ids:
user_ids = [user.user_id for user in users]
# 检索内容为空
if not flow_ids and not user_ids:
return resp_200(PageList(list=[], total=0))


if group_flow_ids:
if flow_ids:
flow_ids = list(set(flow_ids) & set(group_flow_ids))
if flow_ids and keyword:
#flow_ids = list(set(flow_ids) & set(group_flow_ids))
flow_ids = flow_ids
else:
flow_ids = group_flow_ids

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bisheng",
"version": "0.3.7dev",
"version": "0.3.7rc",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/public/locales/en/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
"contactAdmin": "Please contact the administrator's online assistant",
"deleteSure": "Are you sure you want to delete this tool?",
"modelRequired": "Model is empty",
"avatar": "Avatar"
"avatar": "Avatar",
"switchTo": "Switch to"
},
"chat": {
"newChat": "New Chat",
Expand Down Expand Up @@ -451,7 +452,7 @@
"openingIntroduction": "Opening Introduction",
"openingStatement": "Opening Statement",
"assistantMessageFormat": "The assistant will send this message at the beginning of each conversation, supports Markdown format",
"maximumPromptLength": "The prompt can be up to 1000 characters",
"maximumPromptLength": "The remarks can be up to 1000 characters",
"recommendQuestionsForUsers": "Provide recommended questions for users to guide them to ask. When there are more than 3, 3 will be randomly selected.",
"maxCharacters50": "Up to 50 characters",
"enterGuidingQuestions": "Please enter guiding questions",
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/public/locales/zh/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"contactAdmin": "请联系管理员上线助手",
"deleteSure": "确认删除该工具?",
"modelRequired": "模型为空",
"avatar": "技能头像"
"avatar": "技能头像",
"switchTo": "切换到"
},
"chat": {
"newChat": "新建会话",
Expand Down Expand Up @@ -447,7 +448,7 @@
"openingIntroduction": "开场引导",
"openingStatement": "开场白",
"assistantMessageFormat": "助手将在每次对话开始时发送此信息,支持 Markdown 格式",
"maximumPromptLength": "提示词最多为1000个字符",
"maximumPromptLength": "开场白最多为1000个字符",
"recommendQuestionsForUsers": "为用户提供推荐问题,引导用户提问,超过3个时将随机选取3个",
"maxCharacters50": "最多50个字符",
"enterGuidingQuestions": "请输入引导问题",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export default function LabelSelect({ labels, all, children, resource, onUpdate

useEffect(() => {
const newData = all.map(d => {
if (dataRef.current.length) {
// change name
const oldItem = dataRef.current.find(l => l.value === d.value)
return { ...oldItem, label: d?.label }
}
const res = labels.find(l => l.value === d.value)
return res ? { ...d, selected: true } : d
})
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/controllers/API/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getLogsApi({ page, pageSize, userIds, groupId = '', start,
// 系统模块
export async function getModulesApi(): Promise<{ data: any[] }> {
return {
data: [{ name: '会话', value: 'chat' }, { name: '构建', value: 'build' }, { name: '知识库', value: 'knowledge' }, { name: '系统', value: 'system' }]
data: [{ name: 'log.chat', value: 'chat' }, { name: 'log.build', value: 'build' }, { name: 'log.knowledge', value: 'knowledge' }, { name: 'log.system', value: 'system' }]
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { LoadingIcon } from "@/components/bs-icons/loading"
import { Button } from "@/components/bs-ui/button"
import { generateUUID } from "@/components/bs-ui/utils"
import { uploadFileWithProgress } from "@/modals/UploadModal/upload"
import Word from "@/pages/Report/components/Word"
import { ChevronDown } from "lucide-react"
import { useRef, useState } from "react"
import { useTranslation } from "react-i18next"
import SelectVar from "./SelectVar"
// save(fe) -> office(onlyofc) -> upload(be)
export default function ReportWordEdit({ nodeId }) {
const { t } = useTranslation()

const { docx, loading, createDocx, importDocx } = useReport()

// inset var
const iframeRef = useRef(null)
const handleInset = (value) => {
if (!iframeRef.current) return
const iframeDom = iframeRef.current.querySelector('iframe')
if (!iframeDom) return
iframeDom.contentWindow.postMessage(JSON.stringify({
type: "onExternalPluginMessage",
action: 'insetMarker',
data: value
}), '*');
}

// new
if (!docx.path) return <div className="flex size-full">
<div className="bg-accent size-full flex justify-center items-center">
<div className="border rounded-md p-8 py-10 w-1/2 bg-card">
<p className="text-xl">{t('report.reportTemplate')}</p>
<p className="text-sm mt-2">{t('report.reportDescription')}</p>
<div className="flex gap-2 mt-4">
<Button size="sm" className="w-full" onClick={createDocx}>{t('report.newButton')}</Button>
<Button variant="secondary" disabled={loading} size="sm" className="w-full border-gray-200" onClick={importDocx}>
{loading && <span className="loading loading-spinner loading-sm pointer-events-none h-8 pl-3"></span>}
{t('report.importButton')}
</Button>
</div>
</div>
</div>
</div>

return <div className="relative size-full">
{loading && <div className="absolute w-full h-full top-0 left-0 flex justify-center items-center z-10 bg-primary/20">
<LoadingIcon />
</div>}
<div className="flex h-full">
<div ref={iframeRef} className="relative flex-1 border bg-accent">
<div className="absolute right-10 top-2 z-10">
<SelectVar nodeId={nodeId} itemKey={''} onSelect={(E, v) => handleInset(`${E.id}.${v.value}`)}>
<Button variant="black" className="h-8">插入变量 <ChevronDown size={14} /></Button>
</SelectVar>
</div>
<Word data={docx}></Word>
{/* <LabelPanne onInset={handleInset}></LabelPanne> */}
</div>
</div>
</div >
};


const useReport = (onChange) => {
const [loading, setLoading] = useState(false)

const [docx, setDocx] = useState({
key: '',
path: ''
})

const handleCreate = () => {
const newData = {
key: generateUUID(32),
path: res.file_path
}
setDocx({
key: '',
path: 'http://192.168.106.120:3002/empty.docx'
// path: location.origin + __APP_ENV__.BASE_URL + '/empty.docx' // 文档服务能访问到的文件地址
})
}

const handleImport = () => {
// 上传
// Create a file input element
const input = document.createElement("input");
input.type = "file";
input.accept = ".doc, .docx";
input.style.display = "none"; // Hidden from view
input.multiple = false; // Allow only one file selection

input.onchange = (e: Event) => {
setLoading(true);

// Get the selected file
const file = (e.target as HTMLInputElement).files?.[0];
uploadFileWithProgress(file, (progress) => { }).then(res => {
setLoading(false);
const newData = {
key: generateUUID(32),
path: res.file_path
}
setDocx(newData)
onChange(newData)
})
};

input.click();
}

return {
loading,
docx,
createDocx: handleCreate,
importDocx: handleImport
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ const ResultPanne = ({ chatId, words, data, onClose, onAdd, children, fullScreen
setTimeout(() => document.getElementById('taginput')?.focus(), 0);
}

return <div className="flex gap-4" style={{ height: fullScreen ? '100vh' : !isMobile ? 'calc(100vh - 10rem)' : 'calc(100vh - 4rem)' }}>
return <div className="flex gap-4 relative" style={{ height: fullScreen ? '100vh' : !isMobile ? 'calc(100vh - 10rem)' : 'calc(100vh - 4rem)' }}>
{
isMobile && <div className="absolute top-2 left-4 z-10 bg-gray-100 dark:bg-gray-950 py-1 px-2 pb-2 rounded-md">
isMobile && <div className="absolute top-0 left-4 z-50 bg-gray-100 dark:bg-gray-950 py-1 px-2 pb-2 rounded-md">
{!collapse && <span onClick={() => { setCollapse(true) }} className="">收起</span>}
{collapse && <span onClick={() => { setCollapse(false) }} className="">展开</span>}
</div>
}
{
isMobile && <div className="absolute top-2 right-4 z-10 bg-gray-100 dark:bg-gray-950 py-1 px-2 pb-2 rounded-md">
isMobile && <div className="absolute top-0 right-4 z-10 bg-gray-100 dark:bg-gray-950 py-1 px-2 pb-2 rounded-md">
<span onClick={closeDialog} >关闭</span>
</div>
}
Expand Down Expand Up @@ -169,7 +169,7 @@ const ResultPanne = ({ chatId, words, data, onClose, onAdd, children, fullScreen
<p className="text-sm break-all">{_file.fileName}</p>
<div className="absolute right-1 top-1 gap-2 hidden group-hover:flex">
{
_file.fileUrl && <div className="tooltip" data-tip={t('chat.downloadPDFTooltip')}>
_file.fileUrl && <div className="tooltip tooltip-left" data-tip={t('chat.downloadPDFTooltip')}>
<a href="javascript:;" onClick={(event) => { downloadFile(checkSassUrl(_file.fileUrl), _file.fileName.replace(/\.[\w\d]+$/, '.pdf')); event.stopPropagation() }} >
<Import color="rgba(53,126,249,1)" size={22} strokeWidth={1.5}></Import>
</a>
Expand Down
Loading

0 comments on commit 9fd7efe

Please sign in to comment.