Skip to content

Commit 3797613

Browse files
authored
feat: Support converting text prompts (#2702)
1 parent 7145f30 commit 3797613

File tree

6 files changed

+133
-9
lines changed

6 files changed

+133
-9
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

+2
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ const uploadRecording = async (audioBlob: Blob) => {
529529
530530
const formData = new FormData()
531531
formData.append('file', audioBlob, 'recording.mp3')
532+
bus.emit('on:transcribing', true)
532533
applicationApi
533534
.postSpeechToText(props.applicationDetails.id as string, formData, localLoading)
534535
.then((response) => {
@@ -548,6 +549,7 @@ const uploadRecording = async (audioBlob: Blob) => {
548549
recorderLoading.value = false
549550
console.error(`${t('chat.uploadFile.errorMessage')}:`, error)
550551
})
552+
.finally(() => bus.emit('on:transcribing', false))
551553
} catch (error) {
552554
recorderLoading.value = false
553555
console.error(`${t('chat.uploadFile.errorMessage')}:`, error)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<template>
2+
<!-- 问题内容 -->
3+
<div class="question-content item-content mb-16 lighter">
4+
<div class="content p-12-16 border-r-8">
5+
<span> {{ text }}</span
6+
><span class="dotting"></span>
7+
</div>
8+
<div class="avatar ml-8" v-if="application.show_user_avatar">
9+
<el-image
10+
v-if="application.user_avatar"
11+
:src="application.user_avatar"
12+
alt=""
13+
fit="cover"
14+
style="width: 28px; height: 28px; display: block"
15+
/>
16+
<AppAvatar v-else>
17+
<img src="@/assets/user-icon.svg" style="width: 50%" alt="" />
18+
</AppAvatar>
19+
</div>
20+
</div>
21+
</template>
22+
<script setup lang="ts">
23+
defineProps<{
24+
text: string
25+
application: any
26+
type: 'log' | 'ai-chat' | 'debug-ai-chat'
27+
}>()
28+
</script>
29+
<style lang="scss" scoped>
30+
.question-content {
31+
display: flex;
32+
justify-content: flex-end;
33+
padding-left: var(--padding-left);
34+
width: 100%;
35+
box-sizing: border-box;
36+
37+
.content {
38+
background: #d6e2ff;
39+
padding-left: 16px;
40+
padding-right: 16px;
41+
}
42+
43+
.download-file {
44+
height: 43px;
45+
46+
&:hover {
47+
color: var(--el-color-primary);
48+
border: 1px solid var(--el-color-primary);
49+
50+
.download-button {
51+
display: block;
52+
text-align: center;
53+
line-height: 26px;
54+
}
55+
56+
.show {
57+
display: none;
58+
}
59+
}
60+
61+
.download-button {
62+
display: none;
63+
}
64+
}
65+
.media-file-width {
66+
:deep(.el-space__item) {
67+
min-width: 40% !important;
68+
flex-grow: 1;
69+
}
70+
}
71+
.media_2 {
72+
flex: 1;
73+
}
74+
.media_0 {
75+
flex: inherit;
76+
}
77+
.media_1 {
78+
width: 50%;
79+
}
80+
}
81+
@media only screen and (max-width: 768px) {
82+
.question-content {
83+
.media-file-width {
84+
:deep(.el-space__item) {
85+
min-width: 100% !important;
86+
}
87+
}
88+
.media_1 {
89+
width: 100%;
90+
}
91+
}
92+
}
93+
.debug-ai-chat {
94+
.question-content {
95+
.media-file-width {
96+
:deep(.el-space__item) {
97+
min-width: 100% !important;
98+
}
99+
}
100+
.media_1 {
101+
width: 100%;
102+
}
103+
}
104+
}
105+
</style>

ui/src/components/ai-chat/index.vue

+13-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
:chat-management="ChatManagement"
4848
></AnswerContent>
4949
</template>
50+
<TransitionContent
51+
v-if="transcribing"
52+
:text="t('chat.transcribing')"
53+
:type="type"
54+
:application="applicationDetails"
55+
></TransitionContent>
5056
</div>
5157
</el-scrollbar>
5258

@@ -94,14 +100,17 @@ import { ChatManagement, type chatType } from '@/api/type/application'
94100
import { randomId } from '@/utils/utils'
95101
import useStore from '@/stores'
96102
import { isWorkFlow } from '@/utils/application'
97-
import { debounce, first } from 'lodash'
103+
import { debounce } from 'lodash'
98104
import AnswerContent from '@/components/ai-chat/component/answer-content/index.vue'
99105
import QuestionContent from '@/components/ai-chat/component/question-content/index.vue'
106+
import TransitionContent from '@/components/ai-chat/component/transition-content/index.vue'
100107
import ChatInputOperate from '@/components/ai-chat/component/chat-input-operate/index.vue'
101108
import PrologueContent from '@/components/ai-chat/component/prologue-content/index.vue'
102109
import UserForm from '@/components/ai-chat/component/user-form/index.vue'
103110
import Control from '@/components/ai-chat/component/control/index.vue'
104111
import { t } from '@/locales'
112+
import bus from '@/bus'
113+
const transcribing = ref<boolean>(false)
105114
defineOptions({ name: 'AiChat' })
106115
const route = useRoute()
107116
const {
@@ -498,6 +507,9 @@ const handleScroll = () => {
498507
onMounted(() => {
499508
window.speechSynthesis.cancel()
500509
window.sendMessage = sendMessage
510+
bus.on('on:transcribing', (status: boolean) => {
511+
transcribing.value = status
512+
})
501513
})
502514
503515
onBeforeUnmount(() => {

ui/src/locales/lang/en-US/ai-chat.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
userInput: 'User Input',
1010
quote: 'Quote',
1111
download: 'Click to Download',
12+
transcribing: 'Transcribing',
1213
passwordValidator: {
1314
title: 'Enter Password to Access',
1415
errorMessage1: 'Password cannot be empty',
@@ -24,13 +25,15 @@ export default {
2425
cancelOppose: 'Undo Dislike',
2526
continue: 'Continue',
2627
stopChat: 'Stop Response',
27-
startChat: 'Start Chat',
28+
startChat: 'Start Chat'
2829
},
2930
tip: {
3031
error500Message: 'Sorry, the service is currently under maintenance. Please try again later!',
3132
errorIdentifyMessage: 'Unable to verify user identity',
32-
errorLimitMessage: 'Sorry, you have reached the maximum number of questions. Please try again tomorrow!',
33-
answerMessage: 'Sorry, no relevant content found. Please rephrase your question or provide more details.',
33+
errorLimitMessage:
34+
'Sorry, you have reached the maximum number of questions. Please try again tomorrow!',
35+
answerMessage:
36+
'Sorry, no relevant content found. Please rephrase your question or provide more details.',
3437
stopAnswer: 'Response Stopped',
3538
answerLoading: 'Generating Response...',
3639
recorderTip: `<p>This feature requires microphone access. Browsers block recording on insecure pages. Solutions:<br/>
@@ -92,5 +95,5 @@ export default {
9295
question: 'User Question',
9396
optimizationQuestion: 'Optimized Question'
9497
},
95-
editTitle: 'Edit Title',
98+
editTitle: 'Edit Title'
9699
}

ui/src/locales/lang/zh-CN/ai-chat.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
userInput: '用户输入',
1010
quote: '引用',
1111
download: '点击下载文件',
12+
transcribing: '转文字中',
1213
passwordValidator: {
1314
title: '请输入密码打开链接',
1415
errorMessage1: '密码不能为空',
@@ -24,7 +25,7 @@ export default {
2425
cancelOppose: '取消反对',
2526
continue: '继续',
2627
stopChat: '停止回答',
27-
startChat: '开始对话',
28+
startChat: '开始对话'
2829
},
2930
tip: {
3031
error500Message: '抱歉,当前正在维护,无法提供服务,请稍后再试!',
@@ -92,5 +93,5 @@ export default {
9293
question: '用户问题',
9394
optimizationQuestion: '优化后问题'
9495
},
95-
editTitle: '编辑标题',
96+
editTitle: '编辑标题'
9697
}

ui/src/locales/lang/zh-Hant/ai-chat.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
userInput: '用戶輸入',
1010
quote: '引用',
1111
download: '點擊下載文件',
12+
transcribing: '轉文字中',
1213
passwordValidator: {
1314
title: '請輸入密碼打開連結',
1415
errorMessage1: '密碼不能為空',
@@ -24,7 +25,7 @@ export default {
2425
cancelOppose: '取消反對',
2526
continue: '繼續',
2627
stopChat: '停止回答',
27-
startChat: '開始對話',
28+
startChat: '開始對話'
2829
},
2930
tip: {
3031
error500Message: '抱歉,當前正在維護,無法提供服務,請稍後再試!',
@@ -92,5 +93,5 @@ export default {
9293
question: '用戶問題',
9394
optimizationQuestion: '優化後問題'
9495
},
95-
editTitle: '編輯標題',
96+
editTitle: '編輯標題'
9697
}

0 commit comments

Comments
 (0)