Skip to content

Commit 7f5ce52

Browse files
committed
feat: workflow application debug chat
1 parent c7e30bb commit 7f5ce52

File tree

10 files changed

+145
-118
lines changed

10 files changed

+145
-118
lines changed

apps/application/flow/i_step_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def handler(self, workflow):
8282
index=0)
8383

8484
self.chat_info.append_chat_record(chat_record)
85-
self.chat_info.set_cahce()
85+
self.chat_info.set_cache()
8686
if [ChatUserType.ANONYMOUS_USER.value, ChatUserType.CHAT_USER.value].__contains__(
8787
workflow_body.get('chat_user_type')):
8888
application_public_access_client = (QuerySet(ApplicationChatUserStats)

apps/chat/serializers/chat.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,17 @@ def chat_work_flow(self, chat_info: ChatInfo, instance: dict, base_to_response):
219219
other_list = instance.get('other_list')
220220
workspace_id = chat_info.application.workspace_id
221221
chat_record_id = instance.get('chat_record_id')
222+
debug = self.data.get('debug', False)
222223
chat_record = None
223224
history_chat_record = chat_info.chat_record_list
224225
if chat_record_id is not None:
225226
chat_record = self.get_chat_record(chat_info, chat_record_id)
226227
history_chat_record = [r for r in chat_info.chat_record_list if str(r.id) != chat_record_id]
227-
work_flow_manage = WorkflowManage(Flow.new_instance(chat_info.work_flow_version.work_flow),
228+
if not debug:
229+
work_flow = chat_info.work_flow_version.work_flow
230+
else:
231+
work_flow = chat_info.application.work_flow
232+
work_flow_manage = WorkflowManage(Flow.new_instance(work_flow),
228233
{'history_chat_record': history_chat_record, 'question': message,
229234
'chat_id': chat_info.chat_id, 'chat_record_id': str(
230235
uuid.uuid1()) if chat_record is None else chat_record.id,
@@ -233,7 +238,7 @@ def chat_work_flow(self, chat_info: ChatInfo, instance: dict, base_to_response):
233238
'chat_user_id': chat_user_id,
234239
'chat_user_type': chat_user_type,
235240
'workspace_id': workspace_id,
236-
'debug': self.data.get('debug', False)},
241+
'debug': debug},
237242
WorkFlowPostHandler(chat_info),
238243
base_to_response, form_data, image_list, document_list, audio_list,
239244
other_list,
@@ -339,12 +344,14 @@ def open_work_flow(self, application):
339344
chat_user_type = self.data.get("chat_user_type")
340345
debug = self.data.get("debug")
341346
chat_id = str(uuid.uuid7())
342-
work_flow_version = QuerySet(WorkFlowVersion).filter(application_id=application_id).order_by(
343-
'-create_time')[0:1].first()
344-
if work_flow_version is None:
345-
raise AppApiException(500,
346-
gettext(
347-
"The application has not been published. Please use it after publishing."))
347+
work_flow_version = None
348+
if not debug:
349+
work_flow_version = QuerySet(WorkFlowVersion).filter(application_id=application_id).order_by(
350+
'-create_time')[0:1].first()
351+
if work_flow_version is None:
352+
raise AppApiException(500,
353+
gettext(
354+
"The application has not been published. Please use it after publishing."))
348355
ChatInfo(chat_id, chat_user_id, chat_user_type, [],
349356
[],
350357
application_id,

ui/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"@codemirror/lang-json": "^6.0.1",
1818
"@codemirror/lang-python": "^6.2.1",
1919
"@codemirror/theme-one-dark": "^6.1.2",
20-
"@logicflow/core": "^2.0.15",
21-
"@logicflow/extension": "^2.0.20",
20+
"@logicflow/core": "^1.2.27",
21+
"@logicflow/extension": "^1.2.27",
2222
"@vavt/cm-extension": "^1.9.1",
2323
"@vueuse/core": "^13.3.0",
2424
"@wecom/jssdk": "^2.3.1",

ui/src/api/model/model.ts

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,55 @@ const getModel: (
2222
return get(`${prefix}/model`, data, loading)
2323
}
2424
/**
25-
* 获取当前用户可使用的模型列表
26-
* @param application_id
27-
* @param loading
28-
* @query { query_text: string, top_number: number, similarity: number }
29-
* @returns
25+
* 获取工作空间下重排模型列表
26+
* @param loading 加载器
27+
* @returns 重排模型列表
3028
*/
31-
const getApplicationRerankerModel: (
32-
application_id: string,
33-
loading?: Ref<boolean>,
34-
) => Promise<Result<Array<any>>> = (application_id, loading) => {
29+
const getRerankerModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
3530
return get(`${prefix}/model`, { model_type: 'RERANKER' }, loading)
3631
}
3732

3833
/**
39-
* 获取当前用户可使用的模型列表
40-
* @param application_id
34+
* 获取语音转文本模型列表
4135
* @param loading
42-
* @query { query_text: string, top_number: number, similarity: number }
43-
* @returns
36+
* @returns 语音转文本模型列表
4437
*/
45-
const getApplicationSTTModel: (
46-
application_id: string,
47-
loading?: Ref<boolean>,
48-
) => Promise<Result<Array<any>>> = (application_id, loading) => {
38+
const getSTTModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
4939
return get(`${prefix}/model`, { model_type: 'STT' }, loading)
5040
}
5141

5242
/**
53-
* 获取当前用户可使用的模型列表
54-
* @param application_id
43+
* 获取文本转语音模型列表
5544
* @param loading
56-
* @query { query_text: string, top_number: number, similarity: number }
5745
* @returns
5846
*/
59-
const getApplicationTTSModel: (
60-
application_id: string,
61-
loading?: Ref<boolean>,
62-
) => Promise<Result<Array<any>>> = (application_id, loading) => {
47+
const getTTSModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
6348
return get(`${prefix}/model`, { model_type: 'TTS' }, loading)
6449
}
65-
66-
const getApplicationImageModel: (
67-
application_id: string,
68-
loading?: Ref<boolean>,
69-
) => Promise<Result<Array<any>>> = (application_id, loading) => {
50+
/**
51+
* 获取图片理解模型列表
52+
* @param loading
53+
* @returns 图片理解模型列表
54+
*/
55+
const getImageModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
7056
return get(`${prefix}/model`, { model_type: 'IMAGE' }, loading)
7157
}
72-
73-
const getApplicationTTIModel: (
74-
application_id: string,
75-
loading?: Ref<boolean>,
76-
) => Promise<Result<Array<any>>> = (application_id, loading) => {
58+
/**
59+
* 获取图片生成模型列表
60+
* @param loading
61+
* @returns 图片生成模型列表
62+
*/
63+
const getTTIModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
7764
return get(`${prefix}/model`, { model_type: 'TTI' }, loading)
7865
}
66+
/**
67+
* 获取大语言模型列表
68+
* @param loading
69+
* @returns 大语言模型列表
70+
*/
71+
const getLLMModel: (loading?: Ref<boolean>) => Promise<Result<Array<any>>> = (loading) => {
72+
return get(`${prefix}/model`, { model_type: 'LLM' }, loading)
73+
}
7974
/**
8075
* 获取模型参数表单
8176
* @param model_id 模型id
@@ -182,9 +177,10 @@ export default {
182177
pauseDownload,
183178
getModelParamsForm,
184179
updateModelParamsForm,
185-
getApplicationRerankerModel,
186-
getApplicationSTTModel,
187-
getApplicationTTSModel,
188-
getApplicationImageModel,
189-
getApplicationTTIModel,
180+
getRerankerModel,
181+
getSTTModel,
182+
getTTSModel,
183+
getImageModel,
184+
getTTIModel,
185+
getLLMModel,
190186
}

ui/src/directives/resize.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { App } from 'vue'
2+
export default {
3+
install: (app: App) => {
4+
app.directive('resize', {
5+
created(el: any, binding: any) {
6+
// 记录长宽
7+
let width = ''
8+
let height = ''
9+
function getSize() {
10+
const style = (document.defaultView as any).getComputedStyle(el)
11+
// 如果当前长宽和历史长宽不同
12+
if (width !== style.width || height !== style.height) {
13+
// binding.value在这里就是下面的resizeChart函数
14+
15+
binding.value({
16+
width: parseFloat(style.width),
17+
height: parseFloat(style.height)
18+
})
19+
}
20+
width = style.width
21+
height = style.height
22+
}
23+
24+
;(el as any).__vueDomResize__ = setInterval(getSize, 500)
25+
},
26+
unmounted(el: any, binding: any) {
27+
clearInterval((el as any).__vueDomResize__)
28+
}
29+
})
30+
}
31+
}

ui/src/views/application/ApplicationSetting.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ function getKnowledge() {
673673
function getModel() {
674674
loading.value = true
675675
modelAPI
676-
.getModel({})
676+
.getLLMModel()
677677
.then((res: any) => {
678678
modelOptions.value = groupBy(res?.data, 'provider')
679679
loading.value = false
@@ -686,7 +686,7 @@ function getModel() {
686686
function getSTTModel() {
687687
loading.value = true
688688
modelAPI
689-
.getApplicationSTTModel(id)
689+
.getSTTModel()
690690
.then((res: any) => {
691691
sttModelOptions.value = groupBy(res?.data, 'provider')
692692
loading.value = false
@@ -699,7 +699,7 @@ function getSTTModel() {
699699
function getTTSModel() {
700700
loading.value = true
701701
modelAPI
702-
.getApplicationTTSModel(id)
702+
.getTTSModel()
703703
.then((res: any) => {
704704
ttsModelOptions.value = groupBy(res?.data, 'provider')
705705
loading.value = false

ui/src/workflow/common/NodeContainer.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
{
145145
required: true,
146146
message: $t('common.inputPlaceholder'),
147-
trigger: 'blur'
148-
}
147+
trigger: 'blur',
148+
},
149149
]"
150150
>
151151
<el-input v-model="form.title" @blur="form.title = form.title.trim()" />
@@ -176,7 +176,7 @@ import { MsgError, MsgConfirm } from '@/utils/message'
176176
import type { FormInstance } from 'element-plus'
177177
import { t } from '@/locales'
178178
const {
179-
params: { id }
179+
params: { id },
180180
} = app.config.globalProperties.$route as any
181181
182182
const height = ref<{
@@ -186,14 +186,14 @@ const height = ref<{
186186
}>({
187187
stepContainerHeight: 0,
188188
inputContainerHeight: 0,
189-
outputContainerHeight: 0
189+
outputContainerHeight: 0,
190190
})
191191
const showAnchor = ref<boolean>(false)
192192
const anchorData = ref<any>()
193193
const titleFormRef = ref()
194194
const nodeNameDialogVisible = ref<boolean>(false)
195195
const form = ref<any>({
196-
title: ''
196+
title: '',
197197
})
198198
199199
const condition = computed({
@@ -206,7 +206,7 @@ const condition = computed({
206206
}
207207
set(props.nodeModel.properties, 'condition', 'AND')
208208
return true
209-
}
209+
},
210210
})
211211
const showNode = computed({
212212
set: (v) => {
@@ -218,7 +218,7 @@ const showNode = computed({
218218
}
219219
set(props.nodeModel.properties, 'showNode', true)
220220
return true
221-
}
221+
},
222222
})
223223
224224
const handleWheel = (event: any) => {
@@ -244,7 +244,7 @@ const editName = async (formEl: FormInstance | undefined) => {
244244
if (valid) {
245245
if (
246246
!props.nodeModel.graphModel.nodes?.some(
247-
(node: any) => node.properties.stepName === form.value.title
247+
(node: any) => node.properties.stepName === form.value.title,
248248
)
249249
) {
250250
set(props.nodeModel.properties, 'stepName', form.value.title)
@@ -274,7 +274,7 @@ const copyNode = () => {
274274
const deleteNode = () => {
275275
MsgConfirm(t('common.tip'), t('views.applicationWorkflow.delete.confirmTitle'), {
276276
confirmButtonText: t('common.confirm'),
277-
confirmButtonClass: 'danger'
277+
confirmButtonClass: 'danger',
278278
}).then(() => {
279279
props.nodeModel.graphModel.deleteNode(props.nodeModel.id)
280280
})
@@ -295,13 +295,13 @@ function clickNodes(item: any) {
295295
type: item.type,
296296
properties: item.properties,
297297
x: anchorData.value?.x + width / 2 + 200,
298-
y: anchorData.value?.y - item.height
298+
y: anchorData.value?.y - item.height,
299299
})
300300
props.nodeModel.graphModel.addEdge({
301301
type: 'app-edge',
302302
sourceNodeId: props.nodeModel.id,
303303
sourceAnchorId: anchorData.value?.id,
304-
targetNodeId: nodeModel.id
304+
targetNodeId: nodeModel.id,
305305
})
306306
307307
closeNodeMenu()
@@ -317,7 +317,7 @@ const nodeFields = computed(() => {
317317
label: field.label,
318318
value: field.value,
319319
globeLabel: `{{${props.nodeModel.properties.stepName}.${field.value}}}`,
320-
globeValue: `{{context['${props.nodeModel.id}'].${field.value}}}`
320+
globeValue: `{{context['${props.nodeModel.id}'].${field.value}}}`,
321321
}
322322
})
323323
return fields
@@ -364,4 +364,9 @@ onMounted(() => {
364364
:deep(.el-card) {
365365
overflow: visible;
366366
}
367+
.app-card {
368+
background: #fff;
369+
border-radius: 8px;
370+
box-shadow: 0px 2px 4px 0px rgba(31, 35, 41, 0.12);
371+
}
367372
</style>

0 commit comments

Comments
 (0)