Xin Zhang commited on
Commit
d35a0ba
·
1 Parent(s): 8ead306

[feature]: update prompt config.

Browse files
frontend/src/stores/config.ts CHANGED
@@ -10,8 +10,6 @@ export const useSettingsStore = defineStore({
10
  language: 'zh',
11
  sider_open: true,
12
  echoCancel: true,
13
- prompt_en: 'You are a helpful assistant.',
14
- prompt_zh: '你是一个乐于助人的助手。',
15
  }
16
  },
17
  actions: {
 
10
  language: 'zh',
11
  sider_open: true,
12
  echoCancel: true,
 
 
13
  }
14
  },
15
  actions: {
frontend/src/views/Welcome/Components/PromptText.vue ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script setup lang="ts">
2
+ import { ref, watch } from "vue";
3
+ import { Modal } from 'ant-design-vue';
4
+ import axios from "axios";
5
+
6
+ const base_url = axios.defaults.baseURL;
7
+
8
+ // Props
9
+ const props = defineProps({
10
+ open: {
11
+ type: Boolean,
12
+ default: false
13
+ }
14
+ });
15
+
16
+ // Emits
17
+ const emit = defineEmits(['update:open']);
18
+
19
+ // 默认提示词
20
+ const default_prompt_en = ref<string>('');
21
+ const default_prompt_zh = ref<string>('');
22
+
23
+ // 响应式数据
24
+ const current_prompt_en = ref<string>('');
25
+ const current_prompt_zh = ref<string>('');
26
+
27
+ const modalLoading = ref<boolean>(false);
28
+ const languageSegment = ref<string>('zh');
29
+
30
+ const fetchDefaultPrompt = async () => {
31
+ try {
32
+ const response = await fetch(`${base_url}/settings/settings/prompts/default`);
33
+ const data = await response.json();
34
+
35
+ if (data) {
36
+ // @ts-ignore
37
+ default_prompt_en.value = data.english_prompt;
38
+ default_prompt_zh.value = data.chinese_prompt;
39
+ }
40
+ } catch (error) {
41
+ console.error('Error fetching default prompt:', error);
42
+ }
43
+ };
44
+
45
+ const fetchCurrentPrompt = async () => {
46
+ try {
47
+ const response = await fetch(`${base_url}/settings/settings/prompts`);
48
+ const data = await response.json();
49
+
50
+ if (data) {
51
+ // @ts-ignore
52
+ current_prompt_en.value = data.english_prompt;
53
+ current_prompt_zh.value = data.chinese_prompt;
54
+ }
55
+ } catch (error) {
56
+ console.error('Error fetching current prompt:', error);
57
+ }
58
+ };
59
+
60
+ const updateCurrentPrompt = async () => {
61
+ try {
62
+ modalLoading.value = true;
63
+ const response = await fetch(`${base_url}/settings/settings/prompts`, {
64
+ method: 'POST',
65
+ headers: {
66
+ 'Content-Type': 'application/json',
67
+ },
68
+ body: JSON.stringify({
69
+ chinese_prompt: current_prompt_zh.value,
70
+ english_prompt: current_prompt_en.value
71
+ })
72
+ });
73
+ if (!response.ok) {
74
+ throw new Error(`HTTP error! status: ${response.status}`);
75
+ }
76
+ const data = await response.json();
77
+ console.log('Current prompt updated successfully:', data);
78
+ } catch (error) {
79
+ console.error('Error updating current prompt:', error);
80
+ } finally {
81
+ modalLoading.value = false;
82
+ }
83
+ };
84
+
85
+ const resetDefaultPrompt = async () => {
86
+ try {
87
+ modalLoading.value = true;
88
+ const response = await fetch(`${base_url}/settings/settings/prompts`, {
89
+ method: 'DELETE',
90
+ });
91
+ if (!response.ok) {
92
+ throw new Error(`HTTP error! status: ${response.status}`);
93
+ }
94
+ const data = await response.json();
95
+ console.log('Default prompt reset successfully:', data);
96
+ current_prompt_en.value = default_prompt_en.value;
97
+ current_prompt_zh.value = default_prompt_zh.value;
98
+ } catch (error) {
99
+ console.error('Error resetting default prompt:', error);
100
+ } finally {
101
+ modalLoading.value = false;
102
+ }
103
+ };
104
+
105
+
106
+ // 方法
107
+ const handleCancel = async () => {
108
+ await fetchCurrentPrompt();
109
+ emit('update:open', false);
110
+ };
111
+
112
+ const handleSubmit = async () => {
113
+ await updateCurrentPrompt();
114
+ await fetchCurrentPrompt();
115
+ emit('update:open', false);
116
+ };
117
+
118
+ const handleResetPrompt = async (language: string) => {
119
+ await fetchDefaultPrompt();
120
+ if (language == 'en') {
121
+ current_prompt_en.value = default_prompt_en.value;
122
+ } else {
123
+ current_prompt_zh.value = default_prompt_zh.value;
124
+ }
125
+ };
126
+
127
+ // 监听open变化,初始化prompt值
128
+ watch(() => props.open, (newOpen) => {
129
+ if (newOpen) {
130
+ fetchCurrentPrompt();
131
+ fetchDefaultPrompt();
132
+ }
133
+ });
134
+
135
+ </script>
136
+
137
+ <template>
138
+ <a-modal
139
+ key="prompt-text-modal"
140
+ v-model:open="props.open"
141
+ :title="null"
142
+ :mask-closable="false"
143
+ centered
144
+ @update:open="(val: boolean) => emit('update:open', val)"
145
+ >
146
+ <template #footer>
147
+ <div class="btn-groups">
148
+ <div class="btn-group">
149
+ <a-button key="back" @click="handleCancel">Cancel</a-button>
150
+ <a-button key="submit" type="primary" :loading="modalLoading" @click="handleSubmit">Submit</a-button>
151
+ </div>
152
+ </div>
153
+ </template>
154
+
155
+ <div class="prompt-content">
156
+ <div class="prompt-title">
157
+ <p>Prompt Debug</p>
158
+ </div>
159
+ <a-radio-group button-style="solid" size="medium" v-model:value="languageSegment" class="language-segment">
160
+ <a-radio-button value="zh">Chinese</a-radio-button>
161
+ <a-radio-button value="en">English</a-radio-button>
162
+ </a-radio-group>
163
+ <div v-if="languageSegment == 'en'" class="prompt-item">
164
+ <a-textarea
165
+ v-model:value="current_prompt_en"
166
+ :placeholder="default_prompt_en"
167
+ :auto-size="{ minRows: 10, maxRows: 20 }"
168
+ show-count
169
+ :maxlength="2000"
170
+ allow-clear
171
+ class="prompt-textarea"
172
+ />
173
+ <a-button key="back" @click="handleResetPrompt('en')" style="margin-top: 16px;">Reset</a-button>
174
+ </div>
175
+ <div v-if="languageSegment == 'zh'" class="prompt-item">
176
+ <a-textarea
177
+ v-model:value="current_prompt_zh"
178
+ :placeholder="default_prompt_zh"
179
+ :auto-size="{ minRows: 10, maxRows: 20 }"
180
+ show-count
181
+ :maxlength="2000"
182
+ allow-clear
183
+ class="prompt-textarea"
184
+ />
185
+ <a-button key="back" @click="handleResetPrompt('zh')" style="margin-top: 16px;">Reset</a-button>
186
+ </div>
187
+ </div>
188
+ </a-modal>
189
+ </template>
190
+
191
+ <style lang="scss" scoped>
192
+ .btn-groups {
193
+ margin-top: 36px;
194
+ display: flex;
195
+ justify-content: flex-end;
196
+ align-items: center;
197
+ }
198
+
199
+ .prompt-title {
200
+ p {
201
+ margin: 0;
202
+ font-size: 16px;
203
+ font-weight: 500;
204
+ }
205
+ }
206
+
207
+ .prompt-content {
208
+ margin-top: 2px;
209
+
210
+ .prompt-title {
211
+ margin-bottom: 24px;
212
+ font-size: 22px;
213
+ font-weight: 500;
214
+ text-align: center;
215
+ }
216
+
217
+ .language-segment {
218
+ display: flex;
219
+ justify-content: center;
220
+ margin-bottom: 16px;
221
+ }
222
+
223
+ .prompt-item {
224
+ margin-top: 16px;
225
+ }
226
+ }
227
+ </style>
frontend/src/views/Welcome/index.vue CHANGED
@@ -4,8 +4,9 @@ import router from "@/router.ts";
4
  import { useSettingsStore } from "@/stores/config.ts";
5
  import { onMounted, ref, reactive, computed, h } from "vue";
6
  import { Modal } from 'ant-design-vue';
7
- import { SettingTwoTone } from "@ant-design/icons-vue";
8
  import axios from "axios";
 
9
 
10
  const base_url = axios.defaults.baseURL
11
 
@@ -79,26 +80,6 @@ const handleVoiceModalSubmit = async () => {
79
  await pushConfig(settingsStore.$state.role);
80
  };
81
 
82
- const promptModelOpen = ref<boolean>(false);
83
- const default_prompt_en = "You are a helpful assistant.";
84
- const default_prompt_zh = "你是一个乐于助人的助手。";
85
- const current_prompt = ref<string>(settingsStore.$state.language == 'zh' ? default_prompt_zh : default_prompt_en);
86
-
87
- const handlePromptModalCancel = () => {
88
- current_prompt.value = settingsStore.$state.language == 'zh' ? settingsStore.$state.prompt_zh : settingsStore.$state.prompt_en;
89
- promptModelOpen.value = false;
90
- };
91
-
92
- const handlePromptModalSubmit = async () => {
93
- console.log('Prompt:', current_prompt.value);
94
- if (settingsStore.$state.language == 'zh') {
95
- settingsStore.$state.prompt_zh = current_prompt.value;
96
- } else {
97
- settingsStore.$state.prompt_en = current_prompt.value;
98
- }
99
- promptModelOpen.value = false;
100
- };
101
-
102
  const pushConfig = async (model_id: string) => {
103
  try {
104
  modalLoading.value = true;
@@ -161,9 +142,10 @@ const echoCancel = ref<boolean>(settingsStore.$state.echoCancel ?? true);
161
 
162
  const radioStyle = reactive({
163
  display: 'flex',
164
- height: '36px',
165
- lineHeight: '36px',
166
- fontSize: '15px',
 
167
  });
168
 
169
  const filteredRoles = computed(() => {
@@ -217,11 +199,14 @@ const togglePopover = (item: string) => {
217
  }
218
  };
219
 
220
- const handleResetPrompt = () => {
221
- current_prompt.value = settingsStore.$state.language == 'zh' ? default_prompt_zh : default_prompt_en;
 
 
 
 
222
  };
223
 
224
- const popoverVisible = ref<boolean>(false);
225
 
226
  </script>
227
 
@@ -294,35 +279,20 @@ const popoverVisible = ref<boolean>(false);
294
  <p>Select voice Role:</p>
295
  <a-radio-group size="large" v-model:value="role">
296
  <a-radio v-for="r in filteredRoles" :style="radioStyle" :value="r['id']" :key="r['id']">
297
- {{ r['character_name'] }}
 
 
 
 
 
 
298
  </a-radio>
299
  </a-radio-group>
300
  </div>
301
  </div>
302
  </a-modal>
303
 
304
- <a-modal v-model:open="promptModelOpen" :title="null" :mask-closable="false" centered>
305
- <template #footer>
306
- <div class="btn-groups">
307
- <a-button key="back" @click="handleResetPrompt">Reset</a-button>
308
- <div class="btn-group">
309
- <a-button key="back" @click="handlePromptModalCancel">Cancel</a-button>
310
- <a-button key="submit" type="primary" :loading="modalLoading" @click="handlePromptModalSubmit">Submit</a-button>
311
- </div>
312
- </div>
313
- </template>
314
- <template #title>
315
- <div class="prompt-title">
316
- <p>Prompt 调试</p>
317
- </div>
318
- </template>
319
- <div class="prompt-content">
320
- <div class="prompt-item">
321
- <p>Prompt:</p>
322
- <a-textarea v-model:value="current_prompt" :placeholder="settingsStore.$state.language == 'zh' ? default_prompt_zh : default_prompt_en" :auto-size="{ minRows: 6, maxRows: 20 }" show-count :maxlength="2000" allow-clear />
323
- </div>
324
- </div>
325
- </a-modal>
326
  </div>
327
  </template>
328
 
 
4
  import { useSettingsStore } from "@/stores/config.ts";
5
  import { onMounted, ref, reactive, computed, h } from "vue";
6
  import { Modal } from 'ant-design-vue';
7
+ import { SoundTwoTone } from "@ant-design/icons-vue";
8
  import axios from "axios";
9
+ import PromptText from "./Components/PromptText.vue";
10
 
11
  const base_url = axios.defaults.baseURL
12
 
 
80
  await pushConfig(settingsStore.$state.role);
81
  };
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  const pushConfig = async (model_id: string) => {
84
  try {
85
  modalLoading.value = true;
 
142
 
143
  const radioStyle = reactive({
144
  display: 'flex',
145
+ height: '40px',
146
+ lineHeight: '40px',
147
+ fontSize: '16px',
148
+ marginBottom: '8px',
149
  });
150
 
151
  const filteredRoles = computed(() => {
 
199
  }
200
  };
201
 
202
+ const popoverVisible = ref<boolean>(false);
203
+ const promptModelOpen = ref<boolean>(false);
204
+
205
+ const playRefAudio = (id: string) => {
206
+ console.log('Playing reference audio for role:', id);
207
+ // TODO: Implement audio playback logic
208
  };
209
 
 
210
 
211
  </script>
212
 
 
279
  <p>Select voice Role:</p>
280
  <a-radio-group size="large" v-model:value="role">
281
  <a-radio v-for="r in filteredRoles" :style="radioStyle" :value="r['id']" :key="r['id']">
282
+ <div style="display: flex; justify-content: space-between; align-items: center; width:450px;">
283
+ {{ r['character_name'] }}
284
+ <a-button :key="r['id']" type="text" @click="playRefAudio(r['id'])">
285
+ <SoundTwoTone style="font-size: 22px;"/>
286
+ </a-button>
287
+ </div>
288
+
289
  </a-radio>
290
  </a-radio-group>
291
  </div>
292
  </div>
293
  </a-modal>
294
 
295
+ <PromptText v-model:open="promptModelOpen" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  </div>
297
  </template>
298