Skip to content

Commit 23f581e

Browse files
authored
Merge pull request #13 from MigoXLab/feat/20250808
feat:Support internationalization adaptation
2 parents d03a60c + cef7cca commit 23f581e

27 files changed

+2503
-666
lines changed

backend/model/analysis.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ class AnalysisRequest(BaseModel):
3333
3434
Attributes:
3535
task_id: The task ID to analyze.
36+
language: The language for analysis prompt (en/zh).
3637
"""
3738

3839
eval_prompt: Optional[str] = Field(None, description="Custom evaluation prompt")
40+
language: Optional[str] = Field(
41+
"en", description="Language for analysis prompt (en/zh)"
42+
)
3943

4044

4145
class AnalysisResponse(BaseModel):

backend/service/analysis_service.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ async def analyze_task_svc(
138138
ai_config.api_key,
139139
json.dumps(test_config, ensure_ascii=False, indent=2),
140140
json.dumps(key_metrics, ensure_ascii=False, indent=2),
141+
analysis_request.language or "en",
141142
)
142143

143144
# Check if analysis already exists for this task
@@ -197,7 +198,7 @@ async def analyze_task_svc(
197198
task_id=task_id,
198199
analysis_report="",
199200
status="failed",
200-
error_message="AI analysis failed. Please try again later.",
201+
error_message="AI analysis failed. Please check the AI service configuration and try again.",
201202
created_at="",
202203
)
203204

@@ -274,7 +275,12 @@ async def get_analysis_svc(request: Request, task_id: str) -> GetAnalysisRespons
274275

275276

276277
async def _call_ai_service(
277-
host: str, model: str, api_key: str, test_config: str, results: str
278+
host: str,
279+
model: str,
280+
api_key: str,
281+
test_config: str,
282+
results: str,
283+
language: str = "en",
278284
) -> str:
279285
"""
280286
Call AI service for analysis.
@@ -285,6 +291,7 @@ async def _call_ai_service(
285291
api_key: The API key for authentication.
286292
test_config: The test configuration data.
287293
results: The test results data.
294+
language: The language for analysis prompt (en/zh).
288295
289296
Returns:
290297
str: The analysis content.
@@ -298,9 +305,10 @@ async def _call_ai_service(
298305
"Authorization": f"Bearer {api_key}",
299306
}
300307

301-
from utils.prompt import ANALYSIS_PROMPT
308+
from utils.prompt import get_analysis_prompt
302309

303-
prompt = ANALYSIS_PROMPT.format(test_config=test_config, results=results)
310+
prompt_template = get_analysis_prompt(language)
311+
prompt = prompt_template.format(test_config=test_config, results=results)
304312

305313
data = {
306314
"model": model,

backend/utils/prompt.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
ANALYSIS_PROMPT = """
1+
ANALYSIS_PROMPT_EN = """
22
Analyze the LLM stress test configuration: {test_config} and performance results: {results}, then produce a concise, technical evaluation focused on the metrics below.
33
4-
Rules
4+
Rules:
55
- First_token_latency assessment: Good (<1.00s), Moderate (1.00–2.00s), Poor (>2.00s).
66
- Total_time assessment: Good (<60.00s), Moderate (60.00–180.00s), Poor (>180.00s).
77
- if Total_time is Poor, highlight how First_token_latency, Total_tps, and Avg_total_tokens influence Total_time.
88
- failure_request: If there is a failed request, please indicate it in the `Identified Issues` and direct the user to check the task log for the specific error information.
99
- If a metric is missing, display N/A (do not infer).
1010
- Keep output under 300 words, technical, and prioritize the most severe issues.
1111
12-
Required Output Format
12+
Required Output Format:
1313
### Performance Summary
1414
[1–3 sentence overall assessment, including UX judgment and the dominant bottleneck(s).]
1515
@@ -20,13 +20,62 @@
2020
| First_token_latency(s) | X.XX | Good (<1.00s), Moderate (1.00–2.00s), Poor (>2.00s) | Good/Moderate/Poor |
2121
| Total_time(s) | X.XX | Good (<60.00s), Moderate (60.00–180.00s), Poor (>180.00s) | Good/Moderate/Poor |
2222
| RPS(req/s) | X.XX | — | — |
23-
| Completion_tps(tokens/s) | X.XX | — | — |
24-
| Total_tps(tokens/s) | X.XX | — | — |
25-
| Avg_completion_tokens(tokens/req) | N | — | — |
26-
| Avg_total_tokens(tokens/req) | N | — | — |
23+
| Completion Tps(Tokens/s) | X.XX | — | — |
24+
| Total Tps(Tokens/s) | X.XX | — | — |
25+
| Avg_completion_tokens(Tokens/req) | N | — | — |
26+
| Avg_total_tokens(Tokens/req) | N | — | — |
2727
|Failure_request| N | — | — |
2828
2929
### Identified Issues
3030
1. [Most critical issue with metric value and impact, if any]
3131
2. [Highlight failure_request, if any]
3232
"""
33+
34+
ANALYSIS_PROMPT_CN = """
35+
请分析 LLM 压测配置:{test_config} 和性能结果:{results},然后针对以下指标和要求生成一份简明的技术评估报告。
36+
37+
规则:
38+
- First_token_latency 评估:良好(<1.00 秒),中等(1.00-2.00 秒),较差(>2.00 秒)。
39+
- Total_time 评估:良好(<60.00 秒),中等(60.00-180.00 秒),较差(>180.00 秒)。
40+
- 如果 Total_time 为“较差”,请重点说明和分析 First_token_latency、Total_tps 和 Avg_total_tokens 对 Total_time 的影响。
41+
- Failure_request:如果存在失败的请求,请在“已识别问题”中指出。
42+
- 如果缺少某个指标,则显示 N/A(不推断)。
43+
- 输出内容应控制在 300 字以内,技术性强,并优先处理最严重的问题。
44+
45+
输出格式要求:
46+
### 性能总结
47+
[1-3 句总体评估,包括用户体验判断和主要瓶颈。]
48+
49+
### 关键指标
50+
| 指标 | 值(平均值/最大值) | 阈值/目标 | 结论 |
51+
|---|---|---|---|
52+
| 并发用户数 | N | — | — |
53+
| 首Token时延 (s) | X.XX | 良好 (<1.00 秒)、中等 (1.00-2.00 秒)、较差 (>2.00 秒) | 良好/中等/较差 |
54+
| 总时间 (s) | X.XX | 良好 (<60.00 秒)、中等 (60.00-180.00 秒)、较差 (>180.00 秒) | 良好/中等/较差 |
55+
| RPS(请求/秒)| X.XX | — | — |
56+
| Completion Tokens 吞吐量(Tokens/秒)| X.XX | — | — |
57+
| Total Tokens 吞吐量(Tokens/秒)| X.XX | — | — |
58+
| 平均每请求输出Token数量(Tokens/请求)| N | — | — |
59+
| 平均每请求总Token数量(Tokens/请求)| N | — | — |
60+
| 失败请求| N | — | — |
61+
62+
### 已识别的问题
63+
1. [具有指标值和影响的最关键问题(如果有)]
64+
2. [重点说明是否存在失败请求,并指引用户查看任务日志以获取具体的错误信息(如果有)]
65+
"""
66+
67+
68+
def get_analysis_prompt(language: str = "en") -> str:
69+
"""
70+
根据语言获取相应的分析提示词
71+
72+
Args:
73+
language: 语言代码,支持 'en'(英文)和 'zh'(中文)
74+
75+
Returns:
76+
str: 相应语言的分析提示词
77+
"""
78+
if language == "zh":
79+
return ANALYSIS_PROMPT_CN
80+
else:
81+
return ANALYSIS_PROMPT_EN

frontend/docs/MARKDOWN_OPTIMIZATION.md

Whitespace-only changes.

0 commit comments

Comments
 (0)