Skip to content

Commit 653c14b

Browse files
authored
Merge pull request #43 from Geniusay/master
生成提示词功能
2 parents 2d68315 + 61831fe commit 653c14b

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

prompto-lab-app/src/main/java/io/github/timemachinelab/controller/UserInteractionController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.timemachinelab.controller;
22

33
import com.alibaba.fastjson2.JSON;
4+
import io.github.timemachinelab.core.constant.AllPrompt;
45
import io.github.timemachinelab.core.session.application.MessageProcessingService;
56
import io.github.timemachinelab.core.session.application.SessionManagementService;
67
import io.github.timemachinelab.core.session.application.SseNotificationService;
@@ -294,7 +295,7 @@ public ResponseEntity<String> processAnswer(@Validated @RequestBody UnifiedAnswe
294295
@PostMapping("/gen-prompt")
295296
public ResponseEntity<String> genPrompt(@RequestBody GenPromptRequest request) {
296297
GenPromptOperation.GpResponse gpResponse = new GenPromptOperation.GpResponse();
297-
gpResponse.setGenPrompt("This is a test response for gen-prompt endpoint.");
298+
gpResponse.setGenPrompt(AllPrompt.GEN_PROMPT_AGENT_PROMPT);
298299
sseNotificationService.sendWelcomeMessage(request.getSessionId(), JSON.toJSONString(gpResponse));
299300
return ResponseEntity.ok("生成提示词");
300301
}

prompto-lab-ui/src/components/Chat/AIChatPage.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ const initializeSession = async () => {
225225
226226
// 处理SSE消息
227227
const handleSSEMessage = (response: any) => {
228-
// console.log('收到SSE消息:', response)
228+
console.log('收到SSE消息:', response)
229229
230230
// 更新活跃时间
231231
updateActivity()
@@ -306,10 +306,15 @@ const handleConnectionMessage = (response: any): boolean => {
306306
// 处理生成提示词消息
307307
const handleGenPromptMessage = (response: any): boolean => {
308308
if (response.genPrompt) {
309+
console.log('收到genPrompt数据:', response.genPrompt)
310+
console.log('questionRendererRef.value:', questionRendererRef.value)
311+
309312
try {
310313
// 通过ref调用子组件的setPromptResult方法显示提示词结果
311314
if (questionRendererRef.value && questionRendererRef.value.setPromptResult) {
315+
console.log('调用子组件setPromptResult方法')
312316
questionRendererRef.value.setPromptResult(response.genPrompt)
317+
console.log('setPromptResult调用完成')
313318
314319
toast.success({
315320
title: '提示词生成成功',
@@ -318,6 +323,9 @@ const handleGenPromptMessage = (response: any): boolean => {
318323
})
319324
} else {
320325
console.warn('QuestionRenderer组件引用不可用,无法显示提示词结果')
326+
console.log('questionRendererRef.value存在:', !!questionRendererRef.value)
327+
console.log('setPromptResult方法存在:', questionRendererRef.value && !!questionRendererRef.value.setPromptResult)
328+
321329
toast.error({
322330
title: '显示失败',
323331
message: '无法显示提示词结果,请重试',

prompto-lab-ui/src/components/Chat/QuestionRenderer.vue

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,20 @@
219219

220220
<!-- 提示词结果展示 -->
221221
<div v-if="promptResult" class="prompt-result">
222+
<!-- 调试信息 -->
223+
<div style="display: none;">{{ console.log('模板中promptResult值:', promptResult) }}</div>
222224
<div class="prompt-result-container">
223225
<div class="prompt-result-header">
224226
<h3 class="result-title">生成的提示词</h3>
225-
<button @click="copyPrompt" class="copy-btn" :class="{ copied: copySuccess }">
226-
<span class="btn-icon">{{ copySuccess ? '✅' : '📋' }}</span>
227-
<span class="btn-text">{{ copySuccess ? '已复制' : '复制' }}</span>
228-
</button>
227+
<div class="header-actions">
228+
<button @click="copyPrompt" class="copy-btn" :class="{ copied: copySuccess }">
229+
<span class="btn-icon">{{ copySuccess ? '✅' : '📋' }}</span>
230+
<span class="btn-text">{{ copySuccess ? '已复制' : '复制' }}</span>
231+
</button>
232+
<button @click="closePromptResult" class="close-btn" title="关闭">
233+
<span class="btn-icon">✕</span>
234+
</button>
235+
</div>
229236
</div>
230237

231238
<div class="prompt-content">
@@ -394,6 +401,12 @@ watch(() => props.currentQuestion, (newQuestion, oldQuestion) => {
394401
}
395402
}, { deep: true })
396403
404+
// 监听promptResult变化
405+
watch(() => promptResult.value, (newValue, oldValue) => {
406+
console.log('promptResult变化:', { oldValue, newValue })
407+
console.log('promptResult是否为真值:', !!newValue)
408+
}, { immediate: true })
409+
397410
// 方法
398411
const resetAnswers = () => {
399412
answers.input = ''
@@ -632,9 +645,24 @@ const copyPrompt = async () => {
632645
}
633646
}
634647
648+
// 关闭提示词结果
649+
const closePromptResult = () => {
650+
promptResult.value = ''
651+
copySuccess.value = false
652+
}
653+
635654
// 暴露设置提示词结果的方法
636655
const setPromptResult = (result: string) => {
656+
console.log('子组件setPromptResult被调用,参数:', result)
657+
console.log('设置前promptResult.value:', promptResult.value)
637658
promptResult.value = result
659+
console.log('设置后promptResult.value:', promptResult.value)
660+
661+
// 使用nextTick确保DOM更新
662+
nextTick(() => {
663+
console.log('nextTick后promptResult.value:', promptResult.value)
664+
console.log('DOM中是否存在.prompt-result元素:', !!document.querySelector('.prompt-result'))
665+
})
638666
}
639667
640668
// 暴露方法给父组件
@@ -1810,6 +1838,41 @@ defineExpose({
18101838
gap: 16px;
18111839
}
18121840
1841+
.header-actions {
1842+
display: flex;
1843+
align-items: center;
1844+
gap: 12px;
1845+
}
1846+
1847+
.close-btn {
1848+
display: flex;
1849+
align-items: center;
1850+
justify-content: center;
1851+
width: 40px;
1852+
height: 40px;
1853+
background: rgba(15, 15, 15, 0.8);
1854+
border: 1px solid rgba(212, 175, 55, 0.2);
1855+
border-radius: 50%;
1856+
color: #e8e8e8;
1857+
font-size: 16px;
1858+
font-weight: 600;
1859+
cursor: pointer;
1860+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
1861+
backdrop-filter: blur(10px);
1862+
}
1863+
1864+
.close-btn:hover {
1865+
border-color: rgba(239, 68, 68, 0.4);
1866+
background: rgba(239, 68, 68, 0.1);
1867+
color: #ef4444;
1868+
transform: scale(1.05);
1869+
}
1870+
1871+
.close-btn .btn-icon {
1872+
font-size: 18px;
1873+
line-height: 1;
1874+
}
1875+
18131876
.result-title {
18141877
margin: 0;
18151878
font-size: 24px;

0 commit comments

Comments
 (0)