Skip to content

Commit dfa0f92

Browse files
author
jiangpeiling
committed
🐛 modify the prompt generate display.
1 parent a1bfe80 commit dfa0f92

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

backend/services/prompt_service.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
from utils.auth_utils import get_current_user_info
1616
from fastapi import Header, Request
1717

18-
1918
# Configure logging
2019
logger = logging.getLogger("prompt_service")
2120

2221

23-
def call_llm_for_system_prompt(user_prompt: str, system_prompt: str, callback=None, tenant_id:str = None) -> str:
22+
def call_llm_for_system_prompt(user_prompt: str, system_prompt: str, callback=None, tenant_id: str = None) -> str:
2423
"""
2524
Call LLM to generate system prompt
2625
@@ -64,11 +63,8 @@ def call_llm_for_system_prompt(user_prompt: str, system_prompt: str, callback=No
6463
raise e
6564

6665

67-
68-
69-
70-
def generate_and_save_system_prompt_impl(agent_id: int, task_description: str, authorization: str = Header(None),
71-
request: Request = None):
66+
def generate_and_save_system_prompt_impl(agent_id: int, task_description: str, authorization: str = Header(None),
67+
request: Request = None):
7268
user_id, tenant_id, language = get_current_user_info(authorization, request)
7369

7470
# Get description of tool and agent
@@ -81,7 +77,8 @@ def generate_and_save_system_prompt_impl(agent_id: int, task_description: str, a
8177

8278
# 1. Real-time streaming push
8379
final_results = {"duty": "", "constraint": "", "few_shots": ""}
84-
for result_data in generate_system_prompt(sub_agent_info_list, task_description, tool_info_list, tenant_id, language):
80+
for result_data in generate_system_prompt(sub_agent_info_list, task_description, tool_info_list, tenant_id,
81+
language):
8582
# Update final results
8683
final_results[result_data["type"]] = result_data["content"]
8784
yield result_data
@@ -118,6 +115,7 @@ def callback_fn(current_text):
118115
latest[tag] = current_text
119116
# Notify main thread that new content is available
120117
produce_queue.put(tag)
118+
121119
return callback_fn
122120

123121
def run_and_flag(tag, sys_prompt):
@@ -150,7 +148,7 @@ def run_and_flag(tag, sys_prompt):
150148
produce_queue.get(timeout=0.5)
151149
except queue.Empty:
152150
continue
153-
151+
154152
# Check if there is new content
155153
for tag in ["duty", "constraint", "few_shots"]:
156154
if latest[tag] != last_results[tag]:
@@ -230,7 +228,7 @@ def fine_tune_prompt(system_prompt: str, command: str, tenant_id: str, language:
230228

231229
try:
232230
fine_tune_config_path = 'backend/prompts/utils/prompt_fine_tune_en.yaml' if language == 'en' else 'backend/prompts/utils/prompt_fine_tune.yaml'
233-
231+
234232
with open(fine_tune_config_path, "r", encoding="utf-8") as f:
235233
prompt_for_fine_tune = yaml.safe_load(f)
236234

frontend/app/[locale]/setup/agentSetup/components/SystemPromptDisplay.tsx

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

3-
import { Modal, message, Badge } from 'antd'
4-
import { ExpandAltOutlined } from '@ant-design/icons'
3+
import { Modal, message, Badge, Button } from 'antd'
4+
import { ExpandAltOutlined, SaveOutlined, BugOutlined } from '@ant-design/icons'
55
import { useState, useRef, useEffect, useCallback } from 'react'
66
import AdditionalRequestInput from './AdditionalRequestInput'
77
import { fineTunePrompt, savePrompt } from '@/services/promptService'
@@ -160,14 +160,14 @@ const PromptCard = ({ title, content, index, onChange, onExpand }: {
160160
return (
161161
<div className="h-full flex flex-col rounded-lg border border-gray-200 bg-white shadow-sm hover:shadow-md transition-all duration-200">
162162
{/* Card header */}
163-
<div className="bg-gray-50 text-gray-700 px-4 py-3 rounded-t-lg border-b border-gray-200 flex-shrink-0">
163+
<div className="bg-gray-50 text-gray-700 px-4 py-2 rounded-t-lg border-b border-gray-200 flex-shrink-0">
164164
<div className="flex items-center justify-between">
165165
<div className="flex items-center">
166166
<Badge
167167
{...getBadgeProps(index)}
168168
className="mr-3"
169169
/>
170-
<h3 className="text-lg font-medium">{title}</h3>
170+
<h3 className="text-base font-medium">{title}</h3>
171171
</div>
172172
<button
173173
onClick={() => onExpand?.(title, content, index)}
@@ -240,6 +240,23 @@ export default function SystemPromptDisplay({
240240

241241
const { t } = useTranslation('common')
242242

243+
// Calculate dynamic modal height based on content
244+
const calculateModalHeight = (content: string) => {
245+
const lineCount = content.split('\n').length;
246+
const contentLength = content.length;
247+
248+
// 基于行数和内容长度的高度计算,范围 25vh - 85vh
249+
const minHeight = 25;
250+
const maxHeight = 85;
251+
252+
// 结合行数和内容长度来计算高度
253+
const heightByLines = minHeight + Math.floor(lineCount / 8) * 5;
254+
const heightByContent = minHeight + Math.floor(contentLength / 200) * 3;
255+
256+
const calculatedHeight = Math.max(heightByLines, heightByContent);
257+
return Math.max(minHeight, Math.min(maxHeight, calculatedHeight));
258+
};
259+
243260
// Handle expand card content
244261
const handleExpandCard = (title: string, content: string, index: number) => {
245262
setExpandTitle(title)
@@ -439,28 +456,35 @@ export default function SystemPromptDisplay({
439456

440457
return (
441458
<div className="flex flex-col h-full">
442-
<div className="flex justify-between items-center mb-3 flex-shrink-0 px-2">
443-
<div className="flex flex-col">
444-
<h2 className="text-lg font-medium text-gray-700 mt-1.5">{t('agent.title')}</h2>
459+
<div className="flex justify-between items-center mb-2 flex-shrink-0 px-2">
460+
<div className="flex items-center">
461+
<h2 className="text-lg font-medium">{t('agent.title')}</h2>
445462
</div>
446-
<div className="flex gap-2">
447-
<button
463+
<div className="flex gap-1">
464+
<Button
465+
type="text"
466+
size="small"
467+
icon={<SaveOutlined />}
448468
onClick={handleSavePrompt}
449469
disabled={!agentId}
450-
className="px-4 py-1.5 rounded-md flex items-center text-sm bg-green-500 text-white hover:bg-green-600 disabled:opacity-50 disabled:cursor-not-allowed"
451-
style={{ border: "none" }}
470+
className="text-green-500 hover:text-green-600 hover:bg-green-50"
471+
title={t('systemPrompt.button.save')}
452472
>
453473
{t('systemPrompt.button.save')}
454-
</button>
455-
<button
474+
</Button>
475+
<Button
476+
type="text"
477+
size="small"
478+
icon={<BugOutlined />}
456479
onClick={onDebug}
457-
className="px-4 py-1.5 rounded-md flex items-center text-sm bg-gray-100 text-gray-700 hover:bg-gray-200"
458-
style={{ border: "none" }}
480+
className="text-blue-500 hover:text-blue-600 hover:bg-blue-50"
481+
title={t('systemPrompt.button.debug')}
459482
>
460483
{t('systemPrompt.button.debug')}
461-
</button>
484+
</Button>
462485
</div>
463486
</div>
487+
<div className="border-t border-gray-200 mx-2 mb-2"></div>
464488
<div
465489
className="flex-1 overflow-y-auto px-2"
466490
style={{
@@ -504,13 +528,16 @@ export default function SystemPromptDisplay({
504528
</MilkdownProvider>
505529
</div>
506530
<div className="mt-4 flex justify-end">
507-
<button
531+
<Button
532+
type="text"
533+
size="small"
534+
icon={<SaveOutlined />}
508535
onClick={handleSaveTunedPrompt}
509-
className="px-4 py-1.5 rounded-md flex items-center text-sm bg-blue-500 text-white hover:bg-blue-600"
510-
style={{ border: "none" }}
536+
className="text-blue-500 hover:text-blue-600 hover:bg-blue-50"
537+
title={t('systemPrompt.modal.button.save')}
511538
>
512539
{t('systemPrompt.modal.button.save')}
513-
</button>
540+
</Button>
514541
</div>
515542
</div>
516543
)}
@@ -520,7 +547,7 @@ export default function SystemPromptDisplay({
520547
{/* Expand Card Content Modal */}
521548
<Modal
522549
title={
523-
<div className="flex justify-end items-center pr-4">
550+
<div className="flex justify-end items-center pr-4 -mb-2">
524551
<button
525552
onClick={handleCloseExpandedModal}
526553
className="px-4 py-1.5 rounded-md flex items-center text-sm bg-gray-100 text-gray-700 hover:bg-gray-200"
@@ -540,7 +567,10 @@ export default function SystemPromptDisplay({
540567
content: { top: 20 }
541568
}}
542569
>
543-
<div className="flex flex-col h-[80vh]">
570+
<div
571+
className="flex flex-col"
572+
style={{ height: `${calculateModalHeight(expandContent)}vh` }}
573+
>
544574
<div className="flex-1 border border-gray-200 rounded-md overflow-y-auto">
545575
<MilkdownProvider>
546576
<PromptEditor

0 commit comments

Comments
 (0)