Skip to content

Commit 0aeb3bc

Browse files
committed
feat: new example and second api is working
1 parent edf50cc commit 0aeb3bc

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

examples/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ fn is_email(input: String) -> bool {
77
}
88

99
fn main() {
10-
let result = is_email("bregy@minsky.cc".to_string());
10+
let result = is_email("bregyminsky.cc".to_string());
1111
println!("result: {}", result);
1212
}

examples/pi.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use auto_rust::auto_implement;
2+
3+
#[auto_implement]
4+
#[doc = "This function calculates pi with a robust and very fast algorithm."]
5+
fn calculate_pi_with_n_decimals(n: u32) -> f64 {
6+
todo!()
7+
}
8+
9+
fn main() {
10+
let result = calculate_pi_with_n_decimals(10);
11+
println!("pi: {}", result);
12+
}

src/generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use proc_macro::TokenStream;
44

55
use crate::api::open_ai_chat_completions;
66

7-
pub fn generate_body_function_from_head(head: TokenStream) -> Result<String, Box<dyn Error>> {
7+
pub fn generate_body_function_from_head(head: String) -> Result<String, Box<dyn Error>> {
88
let system_message = "You are an AI code assistant trained on the GPT-4 architecture. Your task is to generate Rust function body implementations based only on the provided function signatures. When the user provides a function signature using the command '/complete', your response must be the plain text function body, without any explanations, formatting, or code blocks. Do not include the function signature, function name, or any other information in your response. Triple backticks (```) and function signatures are strictly prohibited in your response. Responding with any prohibited content will result in a penalty.
99
example 1:
1010
INPUT: /complete fn my_ip() -> String

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn implement(_item: TokenStream) -> TokenStream {
1616
// TODO: Evaluate the use of dotenv in this crate
1717
dotenv().ok();
1818

19-
let implemented_fn = generate_body_function_from_head(_item).unwrap();
19+
let implemented_fn = generate_body_function_from_head(_item.to_string()).unwrap();
2020

2121
println!("{}", implemented_fn);
2222

@@ -31,7 +31,7 @@ pub fn auto_implement(args: TokenStream, input: TokenStream) -> TokenStream {
3131

3232
// Search for the information within the attributes.
3333

34-
let mut target_info = String::new();
34+
let mut prompt_input = String::new();
3535

3636
let fn_header = ast.sig.to_token_stream().to_string();
3737

@@ -48,11 +48,22 @@ pub fn auto_implement(args: TokenStream, input: TokenStream) -> TokenStream {
4848
// break;
4949
// // }
5050
// }
51-
println!("{}", data)
51+
println!("{}", data);
52+
53+
prompt_input.push_str(&data);
54+
prompt_input.push('\n');
5255
// }
5356
}
5457

55-
println!("Information extracted: {:?}", target_info);
58+
prompt_input.push_str(&fn_header);
59+
60+
println!("Information extracted: {:?}", prompt_input);
61+
62+
dotenv().ok();
63+
64+
let implemented_fn = generate_body_function_from_head(prompt_input).unwrap();
65+
66+
println!("{}", implemented_fn);
5667

57-
input
68+
implemented_fn.parse().unwrap()
5869
}

0 commit comments

Comments
 (0)