1
This commit is contained in:
@@ -14,12 +14,14 @@ use std::convert::Infallible;
|
||||
|
||||
use crate::{
|
||||
http_error::AppError,
|
||||
request_context::RequestContext,
|
||||
runtime_chat_prompt::{
|
||||
prompt::runtime_chat::{
|
||||
NPC_CHAT_TURN_REPLY_SYSTEM_PROMPT, NPC_CHAT_TURN_SUGGESTION_SYSTEM_PROMPT,
|
||||
NpcChatTurnPromptInput, build_npc_chat_turn_reply_prompt,
|
||||
NpcChatTurnPromptInput, build_deterministic_chat_suggestions,
|
||||
build_deterministic_npc_reply, build_fallback_function_suggestions,
|
||||
build_fallback_npc_chat_suggestions, build_npc_chat_turn_reply_prompt,
|
||||
build_npc_chat_turn_suggestion_prompt,
|
||||
},
|
||||
request_context::RequestContext,
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
@@ -256,66 +258,6 @@ where
|
||||
Some((npc_reply, suggestions, function_suggestions, force_exit))
|
||||
}
|
||||
|
||||
fn build_deterministic_npc_reply(
|
||||
npc_name: &str,
|
||||
player_message: &str,
|
||||
npc_initiates_conversation: bool,
|
||||
) -> String {
|
||||
// Rust API 尚未迁入旧 Node 的完整 LLM NPC 聊天编排前,先由后端提供稳定兜底,保证相遇与选项聊天链路不断。
|
||||
if npc_initiates_conversation {
|
||||
return format!("{npc_name}看向你,先开口说道:“你来了。先别急着走,我正有话想和你说。”");
|
||||
}
|
||||
format!("{npc_name}听完你的话,回应道:“{player_message}。我明白你的意思,我们继续说。”")
|
||||
}
|
||||
|
||||
fn build_deterministic_chat_suggestions(npc_name: &str, player_message: &str) -> Vec<String> {
|
||||
// 建议只承载玩家可点选的行动意图,不在 UI 里额外塞说明文案。
|
||||
vec![
|
||||
format!("{npc_name},我想先听你说"),
|
||||
"这件事哪里不对劲".to_string(),
|
||||
if player_message.contains('帮') || player_message.contains('忙') {
|
||||
"先别绕,说清代价".to_string()
|
||||
} else {
|
||||
"你是不是还瞒着我".to_string()
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn build_fallback_npc_chat_suggestions(player_message: &str) -> Vec<String> {
|
||||
let topic = player_message.trim().chars().take(8).collect::<String>();
|
||||
let topic = if topic.is_empty() {
|
||||
"刚才那句".to_string()
|
||||
} else {
|
||||
topic
|
||||
};
|
||||
|
||||
vec![
|
||||
"我愿意先听你说完".to_string(),
|
||||
format!("这事和{topic}有关吗"),
|
||||
"你别再避重就轻".to_string(),
|
||||
]
|
||||
}
|
||||
|
||||
fn build_fallback_function_suggestions(chat_directive: Option<&Value>) -> Vec<Value> {
|
||||
read_function_options(chat_directive)
|
||||
.into_iter()
|
||||
.filter(|option| {
|
||||
read_string_field(option, "functionId")
|
||||
.as_deref()
|
||||
.is_some_and(|function_id| function_id != "npc_chat")
|
||||
})
|
||||
.take(2)
|
||||
.filter_map(|option| {
|
||||
let function_id = read_string_field(option, "functionId")?;
|
||||
let action_text = read_string_field(option, "actionText")?;
|
||||
Some(json!({
|
||||
"functionId": function_id,
|
||||
"actionText": action_text,
|
||||
}))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn build_completion_directive(chat_directive: Option<&Value>, force_exit: bool) -> Value {
|
||||
let Some(directive) = chat_directive else {
|
||||
return Value::Null;
|
||||
|
||||
Reference in New Issue
Block a user