迁移自动项目命名提示词

将自动项目命名提示词迁移到 prompts 目录并由 Rust 编译期引入
说明取名附件采用独立窄 DTO 的输入边界原因
增加提示词关键约束回归测试
This commit is contained in:
2026-09-03 11:09:09 +08:00
parent dc5be4aedd
commit f16ce4997d
3 changed files with 16 additions and 8 deletions
@@ -0,0 +1 @@
你是项目命名助手。只根据用户输入提炼一个原创、简短、中文的项目名称;不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释。输出必须有且只有一行纯文本,长度为 2 到 16 个字符。信息不足时输出:未命名游戏原型
@@ -17,8 +17,10 @@ const AUTOMATIC_PROJECT_NAME_MAX_PROMPT_CHARS: usize = 8_000;
const AUTOMATIC_PROJECT_NAME_MAX_ATTACHMENTS: usize = 20;
const AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS: u32 = 64;
const AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT: &str =
"你是项目命名助手。只根据用户输入提炼一个原创、简短、中文的项目名称;不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释。输出必须有且只有一行纯文本,长度为 2 到 16 个字符。信息不足时输出:未命名游戏原型";
include_str!("../prompts/automatic-project-name.md");
// 自动命名只需要附件名称和媒体类型提示。保持独立的窄 DTO 并拒绝未知字段,
// 避免把 Direct 回合附件中的本地路径、导入状态和文件大小引入无项目命名边界。
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub(crate) struct AutomaticProjectNameAttachment {
@@ -95,7 +97,7 @@ async fn request_automatic_project_name(
let app_config = load_game_creator_app_config()?;
if app_config.agent_mode == GAME_CREATOR_AGENT_MODE_CODEX_APP_SERVER {
let reply = crate::agent::direct_game_creator_home_codex_chat(
AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.to_string(),
AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.trim().to_string(),
user_prompt,
)
.await?;
@@ -104,12 +106,13 @@ async fn request_automatic_project_name(
let mut llm = app_config.llm.clone();
llm.max_retries = 0;
let client = build_game_creator_llm_client_from_llm_config(&llm, "llm")?;
let request = LlmRunRequest::single_turn(AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT, user_prompt)
.with_api_kind(parse_game_creator_llm_api_kind(&llm.api_kind)?)
.with_model(llm.model.clone())
.with_request_timeout_ms(llm.request_timeout_ms)
.with_max_output_tokens(AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS)
.with_web_search(false);
let request =
LlmRunRequest::single_turn(AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.trim(), user_prompt)
.with_api_kind(parse_game_creator_llm_api_kind(&llm.api_kind)?)
.with_model(llm.model.clone())
.with_request_timeout_ms(llm.request_timeout_ms)
.with_max_output_tokens(AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS)
.with_web_search(false);
let response = client
.run(request)
.await
@@ -1650,6 +1650,10 @@ fn automatic_project_name_suggestions_are_normalized_fail_closed() {
#[test]
fn automatic_project_name_prompt_is_bounded_and_uses_attachment_metadata_only() {
let system_prompt = include_str!("../../prompts/automatic-project-name.md");
assert!(system_prompt.contains("长度为 2 到 16 个字符"));
assert!(system_prompt.contains("不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释"));
let prompt = build_automatic_project_name_prompt(
"做一个在月球邮局送信的解谜游戏",
&[