@@ -6,9 +6,7 @@ use crate::cli;
66use crate :: config:: { self , Config } ;
77
88use crate :: constants:: BRANCH_NAME_PROMPT ;
9- use crate :: constants:: {
10- DEFAULT_MAX_TOKENS , DEFAULT_OPENAI_MODEL , DEFAULT_PROMPT_TEMPLATE , STOP_WORDS ,
11- } ;
9+ use crate :: constants:: { DEFAULT_MAX_TOKENS , DEFAULT_OPENAI_MODEL , DEFAULT_PROMPT_TEMPLATE } ;
1210use crate :: template_engine:: { render_template, TemplateContext } ;
1311
1412async fn generate_commit_message (
@@ -59,7 +57,7 @@ async fn generate_commit_message(
5957 top_p : None ,
6058 n : None ,
6159 stream : Some ( false ) ,
62- stop : Some ( STOP_WORDS . to_owned ( ) ) ,
60+ stop : None , // 移除 stop words 以避免思考过程中的干扰
6361 max_tokens : Some ( DEFAULT_MAX_TOKENS as i32 ) ,
6462 presence_penalty : None ,
6563 frequency_penalty : None ,
@@ -103,25 +101,32 @@ fn delete_thinking_contents(orig: &str) -> String {
103101}
104102
105103fn extract_aicommit_message ( response : & str ) -> anyhow:: Result < String > {
106- let start_tag = "<aicommit>" ;
107- let end_tag = "</aicommit>" ;
108-
109104 let response = delete_thinking_contents ( response) ;
110105
111- let start_idx = response
112- . find ( start_tag)
113- . ok_or ( anyhow:: anyhow!( "Start tag <aicommit> not found" ) ) ?
114- + start_tag. len ( ) ;
115- let end_idx = response. find ( end_tag) . unwrap_or_else ( || response. len ( ) ) ;
106+ // 查找所有 <aicommit>...</aicommit> 块
107+ let mut matches = Vec :: new ( ) ;
108+ let mut pos = 0 ;
109+
110+ while let Some ( start_idx) = response[ pos..] . find ( "<aicommit>" ) {
111+ let absolute_start = pos + start_idx;
112+ let content_start = absolute_start + "<aicommit>" . len ( ) ;
116113
117- if start_idx >= end_idx {
118- return Err ( anyhow:: anyhow!(
119- "End tag </aicommit> not found or misplaced"
120- ) ) ;
114+ if let Some ( end_idx) = response[ content_start..] . find ( "</aicommit>" ) {
115+ let absolute_end = content_start + end_idx;
116+ let content = & response[ content_start..absolute_end] ;
117+ matches. push ( content. trim ( ) ) ;
118+ pos = absolute_end + "</aicommit>" . len ( ) ;
119+ } else {
120+ break ;
121+ }
121122 }
122123
123- let commit_message = response[ start_idx..end_idx] . trim ( ) . to_string ( ) ;
124- Ok ( commit_message)
124+ // 返回第一个匹配的内容
125+ matches
126+ . into_iter ( )
127+ . next ( )
128+ . map ( |s| s. to_string ( ) )
129+ . ok_or ( anyhow:: anyhow!( "Start tag <aicommit> not found" ) )
125130}
126131
127132fn get_diff ( diff_file : Option < & str > , range : Option < & str > ) -> anyhow:: Result < String > {
@@ -186,7 +191,7 @@ async fn generate_branch_name_with_ai(
186191 top_p : None ,
187192 n : None ,
188193 stream : Some ( false ) ,
189- stop : Some ( STOP_WORDS . to_owned ( ) ) ,
194+ stop : None , // 移除 stop words 以避免思考过程中的干扰
190195 max_tokens : Some ( DEFAULT_MAX_TOKENS as i32 ) ,
191196 presence_penalty : None ,
192197 frequency_penalty : None ,
0 commit comments