@@ -3,7 +3,6 @@ use std::{
33 fmt:: Display ,
44 fs,
55 ops:: Not ,
6- process:: Command ,
76} ;
87
98use anyhow:: bail;
@@ -144,75 +143,63 @@ impl SnmCli {
144143 SnmCommands :: SetUp => {
145144 setup_fig ( ) ?;
146145 setup_symlink ( ) ?;
147- }
148- SnmCommands :: AiCommit => {
149- let unified_diff = Command :: new ( "git" )
150- . args ( [ "diff" , "--staged" , "--unified=3" ] )
151- . output ( ) ?;
152-
153- let stat_diff = Command :: new ( "git" )
154- . args ( [ "diff" , "--staged" , "--stat" ] )
155- . output ( ) ?;
156-
157- let unified_content = String :: from_utf8_lossy ( & unified_diff. stdout ) ;
158- let stat_content = String :: from_utf8_lossy ( & stat_diff. stdout ) ;
159-
160- // println!("Unified diff:\n{}", unified_content);
161- // println!("Stat diff:\n\n{}", stat_content);
162-
163- let client = async_openai:: Client :: new ( ) ;
164-
165- let request = async_openai:: types:: CreateChatCompletionRequestArgs :: default ( )
166- // .max_tokens(512u32)
167- . model ( "gpt-4o" )
168- . messages ( [
169- async_openai:: types:: ChatCompletionRequestSystemMessageArgs :: default ( )
170- . content ( "你是一个资深程序员,擅长各种编程语言,特别是 javascript 、typescript、rust、java,并且你还精通 git 。" )
171- . build ( ) ?
172- . into ( ) ,
173- async_openai:: types:: ChatCompletionRequestUserMessageArgs :: default ( )
174- . content ( format ! ( r#"
175- 请针对我的 git diff 内容生成一份标准的 中文 commit msg 信息,满足以下条件
176- - 尽可能的推断出代码改动的意图
177- - 请不要回复多余的信息,直接回复 commit msg 的内容
178- - commit msg 遵循 angular commit message 格式
179- "# ) )
180- . build ( ) ?
181- . into ( ) ,
182- async_openai:: types:: ChatCompletionRequestUserMessageArgs :: default ( )
183- . content ( format ! ( r#"你可以从接下来的内容中获取 哪些文件被修改、每个文件增删了多少行"# ) )
184- . build ( ) ?
185- . into ( ) ,
186- async_openai:: types:: ChatCompletionRequestUserMessageArgs :: default ( )
187- . content ( stat_content. to_string ( ) )
188- . build ( ) ?
189- . into ( ) ,
190- async_openai:: types:: ChatCompletionRequestUserMessageArgs :: default ( )
191- . content ( format ! ( r#"你可以从接下来的内容中获取具体每一个文件的修改内容"# ) )
192- . build ( ) ?
193- . into ( ) ,
194- async_openai:: types:: ChatCompletionRequestUserMessageArgs :: default ( )
195- . content ( unified_content. to_string ( ) )
196- . build ( ) ?
197- . into ( ) ,
198- ] )
199- . build ( ) ?;
200-
201- // println!("{}", serde_json::to_string(&request).unwrap());
202-
203- let response = client. chat ( ) . create ( request) . await ?;
204-
205- // println!("\nResponse:\n");
206- for choice in response. choices {
207- // println!(
208- // "{}: Role: {}",
209- // choice.index, choice.message.role
210- // );
211- println ! ( "{}" , choice. message. content. unwrap( ) ) ;
212- }
213- }
146+ } // SnmCommands::AiCommit => {
147+ // let unified_diff = Command::new("git")
148+ // .args(["diff", "--staged", "--unified=3"])
149+ // .output()?;
150+
151+ // let stat_diff = Command::new("git")
152+ // .args(["diff", "--staged", "--stat"])
153+ // .output()?;
154+
155+ // let unified_content = String::from_utf8_lossy(&unified_diff.stdout);
156+ // let stat_content = String::from_utf8_lossy(&stat_diff.stdout);
157+
158+ // let client = async_openai::Client::new();
159+
160+ // let request = async_openai::types::CreateChatCompletionRequestArgs::default()
161+ // .model("gpt-4o")
162+ // .messages([
163+ // async_openai::types::ChatCompletionRequestSystemMessageArgs::default()
164+ // .content("你是一个资深程序员,擅长各种编程语言,特别是 javascript 、typescript、rust、java,并且你还精通 git 。")
165+ // .build()?
166+ // .into(),
167+ // async_openai::types::ChatCompletionRequestUserMessageArgs::default()
168+ // .content(format!(r#"
169+ // 请针对我的 git diff 内容生成一份标准的 中文 commit msg 信息,满足以下条件
170+ // - 尽可能的推断出代码改动的意图
171+ // - 请不要回复多余的信息,直接回复 commit msg 的内容
172+ // - commit msg 遵循 angular commit message 格式
173+ // "#))
174+ // .build()?
175+ // .into(),
176+ // async_openai::types::ChatCompletionRequestUserMessageArgs::default()
177+ // .content(format!(r#"你可以从接下来的内容中获取 哪些文件被修改、每个文件增删了多少行"#))
178+ // .build()?
179+ // .into(),
180+ // async_openai::types::ChatCompletionRequestUserMessageArgs::default()
181+ // .content(stat_content.to_string())
182+ // .build()?
183+ // .into(),
184+ // async_openai::types::ChatCompletionRequestUserMessageArgs::default()
185+ // .content(format!(r#"你可以从接下来的内容中获取具体每一个文件的修改内容"#))
186+ // .build()?
187+ // .into(),
188+ // async_openai::types::ChatCompletionRequestUserMessageArgs::default()
189+ // .content(unified_content.to_string())
190+ // .build()?
191+ // .into(),
192+ // ])
193+ // .build()?;
194+
195+ // let response = client.chat().create(request).await?;
196+
197+ // for choice in response.choices {
198+ // println!("{}", choice.message.content.unwrap());
199+ // }
200+ // }
201+ // }
214202 }
215-
216203 Ok ( ( ) )
217204 }
218205}
0 commit comments