Skip to content

Commit

Permalink
fix: 修复语音播放无id问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wangdan-fit2cloud committed Sep 20, 2024
1 parent 35f7572 commit 0327546
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 54 deletions.
7 changes: 3 additions & 4 deletions ui/src/components/ai-chat/LogOperationButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AppIcon iconName="app-video-play"></AppIcon>
</el-button>
<el-button v-else text @click="pausePlayAnswerText()">
<el-icon ><VideoPause /></el-icon>
<el-icon><VideoPause /></el-icon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
Expand Down Expand Up @@ -65,10 +65,9 @@ import { useRoute } from 'vue-router'
const route = useRoute()
const {
params: { id },
params: { id }
} = route as any
const props = defineProps({
data: {
type: Object,
Expand Down Expand Up @@ -118,7 +117,7 @@ const playAnswerText = (text: string) => {
return
}
applicationApi
.postTextToSpeech(id || props.applicationId as string, { text: text }, loading)
.postTextToSpeech(id || (props.applicationId as string), { text: text }, loading)
.then((res: any) => {
// 假设我们有一个 MP3 文件的字节数组
// 创建 Blob 对象
Expand Down
59 changes: 33 additions & 26 deletions ui/src/components/ai-chat/OperationButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
<!-- 语音播放 -->
<span v-if="tts">
<el-tooltip effect="dark" content="语音播放" placement="top">
<el-button v-if="!audioPlayerStatus" text :disabled="!data?.write_ed" @click="playAnswerText(data?.answer_text)">
<AppIcon iconName="app-video-play" ></AppIcon>
<el-button
v-if="!audioPlayerStatus"
text
:disabled="!data?.write_ed"
@click="playAnswerText(data?.answer_text)"
>
<AppIcon iconName="app-video-play"></AppIcon>
</el-button>
<el-button v-else text :disabled="!data?.write_ed" @click="pausePlayAnswerText()">
<el-icon ><VideoPause /></el-icon>
<el-icon><VideoPause /></el-icon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
Expand Down Expand Up @@ -78,14 +83,14 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { copyClick } from '@/utils/clipboard'
import applicationApi from '@/api/application'
import { datetimeFormat } from '@/utils/time'
import { useRoute } from 'vue-router'
const route = useRoute()
const {
params: { id },
params: { id }
} = route as any
const props = defineProps({
Expand Down Expand Up @@ -130,26 +135,28 @@ function voteHandle(val: string) {
}
function markdownToPlainText(md: string) {
return md
// 移除图片 ![alt](url)
.replace(/!\[.*?\]\(.*?\)/g, '')
// 移除链接 [text](url)
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
// 移除 Markdown 标题符号 (#, ##, ###)
.replace(/^#{1,6}\s+/gm, '')
// 移除加粗 **text** 或 __text__
.replace(/\*\*(.*?)\*\*/g, '$1')
.replace(/__(.*?)__/g, '$1')
// 移除斜体 *text* 或 _text_
.replace(/\*(.*?)\*/g, '$1')
.replace(/_(.*?)_/g, '$1')
// 移除行内代码 `code`
.replace(/`(.*?)`/g, '$1')
// 移除代码块 ```code```
.replace(/```[\s\S]*?```/g, '')
// 移除多余的换行符
.replace(/\n{2,}/g, '\n')
.trim();
return (
md
// 移除图片 ![alt](url)
.replace(/!\[.*?\]\(.*?\)/g, '')
// 移除链接 [text](url)
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
// 移除 Markdown 标题符号 (#, ##, ###)
.replace(/^#{1,6}\s+/gm, '')
// 移除加粗 **text** 或 __text__
.replace(/\*\*(.*?)\*\*/g, '$1')
.replace(/__(.*?)__/g, '$1')
// 移除斜体 *text* 或 _text_
.replace(/\*(.*?)\*/g, '$1')
.replace(/_(.*?)_/g, '$1')
// 移除行内代码 `code`
.replace(/`(.*?)`/g, '$1')
// 移除代码块 ```code```
.replace(/```[\s\S]*?```/g, '')
// 移除多余的换行符
.replace(/\n{2,}/g, '\n')
.trim()
)
}
const playAnswerText = (text: string) => {
Expand All @@ -169,7 +176,7 @@ const playAnswerText = (text: string) => {
return
}
applicationApi
.postTextToSpeech(id || props.applicationId as string, { text: text }, loading)
.postTextToSpeech((props.applicationId as string) || (id as string), { text: text }, loading)
.then((res: any) => {
// 假设我们有一个 MP3 文件的字节数组
// 创建 Blob 对象
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/ai-chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</div>
<div class="content">
<div class="flex" v-if="!item.answer_text">
<div v-if="!item.answer_text">
<el-card
v-if="item.write_ed === undefined || item.write_ed === true"
shadow="always"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<template #dropdown>
<el-dropdown-menu style="width: 100px">
<el-dropdown-item
:class="filterMethod['is_active'] ? '' : 'is-active'"
:class="filterMethod['is_active'] === '' ? 'is-active' : ''"
:command="beforeCommand('is_active', '')"
class="justify-center"
>全部</el-dropdown-item
Expand Down
8 changes: 4 additions & 4 deletions ui/src/views/paragraph/component/ParagraphDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
width="80%"
class="paragraph-dialog"
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-row v-loading="loading">
<el-col :span="18">
Expand All @@ -27,7 +29,7 @@
</el-button>
</div>
</el-col>
<el-col :span="6" class="border-l" style="width: 300px;">
<el-col :span="6" class="border-l" style="width: 300px">
<!-- 关联问题 -->
<ProblemComponent
:problemId="problemId"
Expand Down Expand Up @@ -149,6 +151,4 @@ const handleDebounceClick = debounce(() => {
defineExpose({ open })
</script>
<style lang="scss" scope>
</style>
<style lang="scss" scope></style>
12 changes: 3 additions & 9 deletions ui/src/views/template/component/CreateModelDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<el-form-item prop="name" :rules="base_form_data_rule.name">
<template #label>
<div class="flex align-center" style="display: inline-flex">
<div class="flex-between mr-4">
<div class="mr-4">
<span>模型名称 </span>
</div>
<el-tooltip effect="dark" placement="right">
Expand Down Expand Up @@ -103,16 +103,10 @@
<el-form-item prop="model_name" :rules="base_form_data_rule.model_name">
<template #label>
<div class="flex align-center" style="display: inline-flex">
<div class="flex-between mr-4">
<div class="mr-4">
<span>基础模型 </span>
<span class="danger">列表中没有列出的模型,直接输入模型名称,回车即可添加</span>
</div>
<el-tooltip effect="dark" placement="right">
<template #content>
<p>若下拉选项没有列出想要添加的LLM模型,自定义输入模型名称后回车即可</p>
<p>注意,基础模型需要与供应商的模型名称一致</p>
</template>
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
</el-tooltip>
</div>
</template>
<el-select
Expand Down
12 changes: 3 additions & 9 deletions ui/src/views/template/component/EditModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<el-form-item prop="name" :rules="base_form_data_rule.name">
<template #label>
<div class="flex align-center" style="display: inline-flex">
<div class="flex-between mr-4">
<div class="mr-4">
<span>模型名称 </span>
</div>
<el-tooltip effect="dark" placement="right">
Expand Down Expand Up @@ -96,16 +96,10 @@
<el-form-item prop="model_name" :rules="base_form_data_rule.model_name">
<template #label>
<div class="flex align-center" style="display: inline-flex">
<div class="flex-between mr-4">
<div class="mr-4">
<span>基础模型 </span>
<span class="danger">列表中没有列出的模型,直接输入模型名称,回车即可添加</span>
</div>
<el-tooltip effect="dark" placement="right">
<template #content>
<p>若下拉选项没有列出想要添加的LLM模型,自定义输入模型名称后回车即可</p>
<p>注意,基础模型需要与供应商的模型名称一致</p>
</template>
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
</el-tooltip>
</div>
</template>
<el-select
Expand Down

0 comments on commit 0327546

Please sign in to comment.